Package de.fhg.igd.mongomvcc.impl.internal

Examples of de.fhg.igd.mongomvcc.impl.internal.Index


   * @return the index. The index provides access to all objects from
   * the currently checked out branch/commit and stores information on
   * dirty objects.
   */
  public Index getIndex() {
    Index r = _index.get();
    if (r == null) {
      r = new Index(getHeadCommit(), _tree);
      _index.set(r);
    }
    return r;
  }
View Full Code Here


    return _rootCid;
  }
 
  @Override
  public long commit() {
    Index idx = getIndex();
    //clone dirty objects because we clear them below
    Map<String, IdMap> dos = new HashMap<String, IdMap>(idx.getDirtyObjects());
    Commit head = getHeadCommit();
    Commit c = new Commit(_db.getCounter().getNextId(), head.getCID(), _rootCid, dos);
    _tree.addCommit(c);
    updateHead(c);
   
    //mark deleted objects as deleted in the database
    DB db = _db.getDB();
    String lifetimeAttr = MongoDBConstants.LIFETIME + "." + getRootCid();
    for (Map.Entry<String, IdSet> e : idx.getDeletedOids().entrySet()) {
      DBCollection dbc = db.getCollection(e.getKey());
      IdSetIterator li = e.getValue().iterator();
      while (li.hasNext()) {
        long oid = li.next();
        //save the CID of the commit where the object has been deleted
        dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set",
            new BasicDBObject(lifetimeAttr, head.getCID())));
      }
    }
   
    //mark dirty objects as inserted
    String instimeAttr = MongoDBConstants.LIFETIME + ".i" + getRootCid();
    for (Map.Entry<String, IdMap> e : dos.entrySet()) {
      DBCollection dbc = db.getCollection(e.getKey());
      IdMap m = e.getValue();
      IdMapIterator li = m.iterator();
      while (li.hasNext()) {
        li.advance();
        long oid = li.value();
        if (oid == -1) {
          //the document has been inserted and then deleted again
          //do not save time of insertion
          continue;
        }
        //save the CID of the commit where the object has been inserted
        dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set",
            new BasicDBObject(instimeAttr, head.getCID())));
      }
    }
   
    //reset index
    idx.clearDirtyObjects();
   
    //if we fail below, the commit has already been performed and the
    //index is clear. failing below simply means the named branch's
    //head could not be updated. If the caller wants to keep the commit
    //he/she just has to create a new named branch based on this
View Full Code Here

TOP

Related Classes of de.fhg.igd.mongomvcc.impl.internal.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.