Search in sources :

Example 16 with BasicDBObject

use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.

the class Tree method getChildren.

@Override
public long[] getChildren(long cid) {
    if (cid != 0 && !existsCommit(cid)) {
        throw new VException("Unknown commit: " + cid);
    }
    DBCursor c = _commits.find(new BasicDBObject(PARENT_CID, cid), new BasicDBObject(MongoDBConstants.ID, 1));
    long[] r = new long[c.count()];
    int i = 0;
    for (DBObject o : c) {
        r[i++] = (Long) o.get(MongoDBConstants.ID);
    }
    return r;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) VException(de.fhg.igd.mongomvcc.VException) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 17 with BasicDBObject

use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.

the class DefaultConvertStrategy method convert.

@Override
public Object convert(long oid) throws IOException {
    GridFSDBFile file = _gridFS.findOne(new BasicDBObject(MongoDBVLargeCollection.OID, oid));
    if (file == null) {
        return null;
    }
    int type = (Integer) file.get(BINARY_TYPE);
    Object r;
    if (type == BYTEARRAY) {
        r = toByteArray(file);
    } else if (type == INPUTSTREAM) {
        r = file.getInputStream();
    } else if (type == BYTEBUFFER) {
        r = ByteBuffer.wrap(toByteArray(file));
    } else if (type == FLOATARRAY) {
        r = toFloatArray(file);
    } else if (type == FLOATBUFFER) {
        r = FloatBuffer.wrap(toFloatArray(file));
    } else {
        //no information. simply forward the input stream
        r = file.getInputStream();
    }
    return r;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) BasicDBObject(com.mongodb.BasicDBObject)

Example 18 with BasicDBObject

use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.

the class MongoDBVDatabaseBenchmark method plainOldInsertDelete.

/**
	 * Inserts a lot of documents using plain old MongoDB and then deletes them
	 */
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDelete() {
    plainOldInsert();
    DBCollection coll = _db.getCollection("persons");
    for (long i = 0; i < DOCUMENTS; ++i) {
        coll.remove(new BasicDBObject("_id", 1 + i));
    }
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 19 with BasicDBObject

use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.

the class MongoDBVMaintenance method doFindDanglingCommits.

private long[] doFindDanglingCommits(long expiry, TimeUnit unit) {
    long maxTime = getMaxTime(expiry, unit);
    //load all commits which are older than the expiry time. mark them as dangling
    DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
    DBCursor commits = collCommits.find(new BasicDBObject(MongoDBConstants.TIMESTAMP, //also include commits without a timestamp
    new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), new BasicDBObject(MongoDBConstants.ID, 1));
    IdSet danglingCommits = new IdHashSet();
    for (DBObject o : commits) {
        long cid = (Long) o.get(MongoDBConstants.ID);
        danglingCommits.add(cid);
    }
    //walk through all branches and eliminate commits which are not dangling
    DBCollection collBranches = _db.getDB().getCollection(MongoDBConstants.COLLECTION_BRANCHES);
    DBCursor branches = collBranches.find(new BasicDBObject(), new BasicDBObject(MongoDBConstants.CID, 1));
    VHistory history = _db.getHistory();
    IdSet alreadyCheckedCommits = new IdHashSet();
    for (DBObject o : branches) {
        long cid = (Long) o.get(MongoDBConstants.CID);
        while (cid != 0) {
            if (alreadyCheckedCommits.contains(cid)) {
                break;
            }
            alreadyCheckedCommits.add(cid);
            danglingCommits.remove(cid);
            cid = history.getParent(cid);
        }
    }
    //all remaining commits must be dangling
    return danglingCommits.toArray();
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) VHistory(de.fhg.igd.mongomvcc.VHistory) IdSet(de.fhg.igd.mongomvcc.helper.IdSet) IdHashSet(de.fhg.igd.mongomvcc.helper.IdHashSet) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 20 with BasicDBObject

use of com.mongodb.BasicDBObject in project mongomvcc by igd-geo.

the class MongoDBVMaintenance method pruneUnreferencedDocuments.

@Override
public long pruneUnreferencedDocuments(String collection, long expiry, TimeUnit unit) {
    long[] oids = findUnreferencedDocuments(collection, expiry, unit);
    DBCollection coll = _db.getDB().getCollection(collection);
    //delete documents in chunks, so we avoid sending an array that is
    //larger than the maximum document size
    final int sliceCount = 1000;
    for (int i = 0; i < oids.length; i += sliceCount) {
        int maxSliceCount = Math.min(sliceCount, oids.length - i);
        long[] slice = new long[maxSliceCount];
        System.arraycopy(oids, i, slice, 0, maxSliceCount);
        coll.remove(new BasicDBObject(MongoDBConstants.ID, new BasicDBObject("$in", slice)));
    }
    return oids.length;
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)497 DBObject (com.mongodb.DBObject)289 Test (org.junit.Test)166 DBCollection (com.mongodb.DBCollection)72 ArrayList (java.util.ArrayList)48 ObjectId (org.bson.types.ObjectId)40 DBCursor (com.mongodb.DBCursor)38 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)38 ApiOperation (io.swagger.annotations.ApiOperation)37 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)36 HashMap (java.util.HashMap)32 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)30 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)29 BasicDBList (com.mongodb.BasicDBList)28 List (java.util.List)24 Map (java.util.Map)23 BSONObject (org.bson.BSONObject)23 MongoException (com.mongodb.MongoException)22 Date (java.util.Date)18 IOException (java.io.IOException)15