Search in sources :

Example 6 with BasicDBObject

use of com.mongodb.BasicDBObject in project v7files by thiloplanz.

the class MongoContentStorage method storeContentChunk.

private ContentSHA storeContentChunk(byte[] bytes, final int offset, final int length) throws IOException {
    ContentSHA _sha = ContentSHA.calculate(bytes, offset, length);
    byte[] sha = _sha.getSHA();
    long existing = contentCollection.count(new BasicDBObject(_ID, sha));
    if (existing == 0) {
        byte[] gzipped = Compression.gzip(bytes, offset, length);
        if (gzipped != null && gzipped.length > chunkSize)
            gzipped = null;
        if (gzipped != null) {
            bytes = null;
            contentCollection.insert(new BasicDBObject(_ID, sha).append("zin", gzipped).append("store", "gz"), WriteConcern.SAFE);
            gzipped = null;
        } else {
            if (offset > 0 || bytes.length != length) {
                bytes = ArrayUtils.subarray(bytes, offset, offset + length);
            }
            contentCollection.insert(new BasicDBObject(_ID, sha).append("in", bytes), WriteConcern.SAFE);
        }
    }
    return _sha;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ContentSHA(v7db.files.spi.ContentSHA)

Example 7 with BasicDBObject

use of com.mongodb.BasicDBObject in project v7files by thiloplanz.

the class V7GridFS method delete.

void delete(V7File file) throws IOException {
    // TODO: should check the version present in the db
    Vermongo.remove(files, file.getId(), new BasicDBObject("deleted_at", new Date()));
    storage.insertContentsAndBackRefs(null, file.getId(), null, null);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Date(java.util.Date)

Example 8 with BasicDBObject

use of com.mongodb.BasicDBObject in project cas by apereo.

the class MongoDbTicketRegistry method initialize.

/**
     * Init registry.
     **/
@PostConstruct
public void initialize() {
    Assert.notNull(this.mongoTemplate);
    LOGGER.debug("Setting up MongoDb Ticket Registry instance [{}]", this.collectionName);
    if (this.dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }
    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
    LOGGER.debug("Creating indices on collection [{}] to auto-expire documents...", this.collectionName);
    final DBCollection collection = mongoTemplate.getCollection(this.collectionName);
    collection.createIndex(new BasicDBObject(TicketHolder.FIELD_NAME_EXPIRE_AT, 1), new BasicDBObject("expireAfterSeconds", 0));
    LOGGER.info("Configured MongoDb Ticket Registry instance [{}]", this.collectionName);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) PostConstruct(javax.annotation.PostConstruct)

Example 9 with BasicDBObject

use of com.mongodb.BasicDBObject in project meclipse by flaper87.

the class Filter method mergeJson.

private DBObject mergeJson(JSONObject json, DBObject dbObj) throws JSONException {
    @SuppressWarnings("unchecked") Iterator<String> jsonKeyIter = json.keys();
    while (jsonKeyIter.hasNext()) {
        String jsonKey = jsonKeyIter.next();
        Object jsonValue = json.get(jsonKey);
        if (jsonValue instanceof JSONObject)
            dbObj.put(jsonKey, mergeJson((JSONObject) jsonValue, new BasicDBObject()));
        dbObj.put(jsonKey, jsonValue);
    }
    return dbObj;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 10 with BasicDBObject

use of com.mongodb.BasicDBObject in project spring-data-document-examples by spring-projects.

the class ChartController method getTopRecommendedRestaurants.

public DBObject getTopRecommendedRestaurants(MongoTemplate mongoTemplate) {
    //This circumvents exception translation
    DBCollection collection = mongoTemplate.getCollection("mvc");
    Date startDate = createDate(1, 5, 2010);
    Date endDate = createDate(1, 12, 2010);
    DBObject cond = QueryBuilder.start("date").greaterThanEquals(startDate).lessThan(endDate).and("action").is("addFavoriteRestaurant").get();
    DBObject key = new BasicDBObject("parameters.p1", true);
    DBObject intitial = new BasicDBObject("count", 0);
    DBObject result = collection.group(key, cond, intitial, "function(doc, out){ out.count++; }");
    return result;
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Date(java.util.Date)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)566 DBObject (com.mongodb.DBObject)338 Test (org.junit.Test)175 DBCollection (com.mongodb.DBCollection)77 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)68 ApiOperation (io.swagger.annotations.ApiOperation)65 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)64 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)54 ArrayList (java.util.ArrayList)53 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)52 ObjectId (org.bson.types.ObjectId)43 DBCursor (com.mongodb.DBCursor)41 HashMap (java.util.HashMap)35 BasicDBList (com.mongodb.BasicDBList)32 List (java.util.List)30 Map (java.util.Map)26 BSONObject (org.bson.BSONObject)23 MongoException (com.mongodb.MongoException)22 Date (java.util.Date)22 CustomGroupingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation)18