Search in sources :

Example 1 with IdMap

use of de.fhg.igd.mongomvcc.helper.IdMap in project mongomvcc by igd-geo.

the class Index method insert.

/**
 * Inserts a new object into the index and marks it as dirty
 * @param collection the name of the collection the object has been added to
 * @param uid the new object's UID
 * @param oid the OID
 */
public void insert(String collection, long uid, long oid) {
    IdMap objs = getObjects(collection);
    IdSet oids = getOIDs(collection);
    long prev = objs.put(uid, oid);
    if (prev != 0) {
        // an existing object is replaced by a new instance. Remove the
        // old OID, since the old object is now invalid (within this index)
        oids.remove(prev);
        if (oid == -1) {
            getDeletedOids(collection).add(prev);
        }
    }
    if (oid != -1) {
        oids.add(oid);
    }
    getDirtyObjects(collection).put(uid, oid);
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdSet(de.fhg.igd.mongomvcc.helper.IdSet)

Example 2 with IdMap

use of de.fhg.igd.mongomvcc.helper.IdMap in project mongomvcc by igd-geo.

the class Tree method resolveCollectionObjects.

private static IdMap resolveCollectionObjects(DBObject o) {
    Set<String> keys = o.keySet();
    IdMap r = new IdHashMap(keys.size());
    for (String k : keys) {
        r.put(Long.parseLong(k), (Long) o.get(k));
    }
    return r;
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap)

Example 3 with IdMap

use of de.fhg.igd.mongomvcc.helper.IdMap in project mongomvcc by igd-geo.

the class Tree method addCommit.

/**
 * Adds a commit to the tree
 * @param commit the commit to add
 */
public void addCommit(Commit commit) {
    DBObject o = new BasicDBObject();
    o.put(MongoDBConstants.ID, commit.getCID());
    o.put(MongoDBConstants.TIMESTAMP, commit.getTimestamp());
    o.put(PARENT_CID, commit.getParentCID());
    o.put(ROOT_CID, commit.getRootCID());
    DBObject objs = new BasicDBObject();
    for (Map.Entry<String, IdMap> e : commit.getObjects().entrySet()) {
        DBObject co = new BasicDBObject();
        IdMapIterator it = e.getValue().iterator();
        while (it.hasNext()) {
            it.advance();
            co.put(String.valueOf(it.key()), it.value());
        }
        objs.put(e.getKey(), co);
    }
    o.put(OBJECTS, objs);
    _commits.insert(o);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdMapIterator(de.fhg.igd.mongomvcc.helper.IdMapIterator) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap) HashMap(java.util.HashMap) IdMap(de.fhg.igd.mongomvcc.helper.IdMap) Map(java.util.Map)

Example 4 with IdMap

use of de.fhg.igd.mongomvcc.helper.IdMap in project mongomvcc by igd-geo.

the class Index method getObjects.

/**
 * For a given collection, this method lazily retrieves
 * the map that maps UIDs to OIDs
 * @param collection the collection's name
 * @return the map
 */
private IdMap getObjects(String collection) {
    IdMap objs = _objects.get(collection);
    if (objs == null) {
        objs = new IdHashMap();
        _objects.put(collection, objs);
    }
    return objs;
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap)

Example 5 with IdMap

use of de.fhg.igd.mongomvcc.helper.IdMap in project mongomvcc by igd-geo.

the class Index method getDirtyObjects.

/**
 * For a given collection, this method lazily retrieves
 * the map that maps UIDs of dirty objects to OIDs.
 * @param collection the collection's name
 * @return the map
 */
private IdMap getDirtyObjects(String collection) {
    IdMap objs = _dirtyObjects.get(collection);
    if (objs == null) {
        objs = new IdHashMap();
        _dirtyObjects.put(collection, objs);
    }
    return objs;
}
Also used : IdMap(de.fhg.igd.mongomvcc.helper.IdMap) IdHashMap(de.fhg.igd.mongomvcc.helper.IdHashMap)

Aggregations

IdMap (de.fhg.igd.mongomvcc.helper.IdMap)10 IdHashMap (de.fhg.igd.mongomvcc.helper.IdHashMap)6 BasicDBObject (com.mongodb.BasicDBObject)5 DBObject (com.mongodb.DBObject)4 IdMapIterator (de.fhg.igd.mongomvcc.helper.IdMapIterator)4 IdSet (de.fhg.igd.mongomvcc.helper.IdSet)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 DBCollection (com.mongodb.DBCollection)2 Commit (de.fhg.igd.mongomvcc.impl.internal.Commit)2 DB (com.mongodb.DB)1 DBCursor (com.mongodb.DBCursor)1 VException (de.fhg.igd.mongomvcc.VException)1 IdHashSet (de.fhg.igd.mongomvcc.helper.IdHashSet)1 IdSetIterator (de.fhg.igd.mongomvcc.helper.IdSetIterator)1 Index (de.fhg.igd.mongomvcc.impl.internal.Index)1 ArrayDeque (java.util.ArrayDeque)1