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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations