List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:org.axonframework.eventstore.mongo.DocumentPerCommitStorageStrategy.java
License:Apache License
@Override public DBCursor findLastSnapshot(DBCollection collection, String aggregateType, String aggregateIdentifier) { DBObject mongoEntry = BasicDBObjectBuilder.start() .add(CommitEntry.AGGREGATE_IDENTIFIER_PROPERTY, aggregateIdentifier) .add(CommitEntry.AGGREGATE_TYPE_PROPERTY, aggregateType).get(); return collection.find(mongoEntry).sort(new BasicDBObject(CommitEntry.SEQUENCE_NUMBER_PROPERTY, ORDER_DESC)) .limit(1);/*from w ww . j ava2 s . co m*/ }
From source file:org.axonframework.eventstore.mongo.DocumentPerEventStorageStrategy.java
License:Apache License
@Override public DBCursor findEvents(DBCollection collection, MongoCriteria criteria) { DBObject filter = criteria == null ? null : criteria.asMongoObject(); DBObject sort = BasicDBObjectBuilder.start().add(EventEntry.TIME_STAMP_PROPERTY, ORDER_ASC) .add(EventEntry.SEQUENCE_NUMBER_PROPERTY, ORDER_ASC).get(); return collection.find(filter).sort(sort); }
From source file:org.axonframework.eventstore.mongo.DocumentPerEventStorageStrategy.java
License:Apache License
@Override public DBCursor findLastSnapshot(DBCollection collection, String aggregateType, String aggregateIdentifier) { DBObject mongoEntry = BasicDBObjectBuilder.start() .add(EventEntry.AGGREGATE_IDENTIFIER_PROPERTY, aggregateIdentifier) .add(EventEntry.AGGREGATE_TYPE_PROPERTY, aggregateType).get(); return collection.find(mongoEntry).sort(new BasicDBObject(EventEntry.SEQUENCE_NUMBER_PROPERTY, ORDER_DESC)) .limit(1);//from ww w . j a v a2 s . co m }
From source file:org.axonframework.eventstore.mongo.EventEntry.java
License:Apache License
/** * Returns the current EventEntry as a mongo DBObject. * * @return DBObject representing the EventEntry *//*from w ww .j a v a2 s .c o m*/ public DBObject asDBObject() { return BasicDBObjectBuilder.start().add(AGGREGATE_IDENTIFIER_PROPERTY, aggregateIdentifier) .add(SEQUENCE_NUMBER_PROPERTY, sequenceNumber).add(SERIALIZED_PAYLOAD_PROPERTY, serializedPayload) .add(TIME_STAMP_PROPERTY, timeStamp).add(AGGREGATE_TYPE_PROPERTY, aggregateType) .add(PAYLOAD_TYPE_PROPERTY, payloadType).add(PAYLOAD_REVISION_PROPERTY, payloadRevision) .add(META_DATA_PROPERTY, serializedMetaData).get(); }
From source file:org.axonframework.eventstore.mongo.EventEntry.java
License:Apache License
/** * Returns the mongo DBObject used to query mongo for events for specified aggregate identifier and type. * * @param type The type of the aggregate to create the mongo DBObject for * @param aggregateIdentifier Identifier of the aggregate to obtain the mongo DBObject for * @param firstSequenceNumber number representing the first event to obtain * @return Created DBObject based on the provided parameters to be used for a query *//* w ww. j a va2 s. c o m*/ public static DBObject forAggregate(String type, String aggregateIdentifier, long firstSequenceNumber) { return BasicDBObjectBuilder.start().add(EventEntry.AGGREGATE_IDENTIFIER_PROPERTY, aggregateIdentifier) .add(EventEntry.SEQUENCE_NUMBER_PROPERTY, new BasicDBObject("$gte", firstSequenceNumber)) .add(EventEntry.AGGREGATE_TYPE_PROPERTY, type).get(); }
From source file:org.botdefender.collector.MongoMessageWriter.java
License:Open Source License
private DBCollection connectHitsCollection() throws Exception { DB db = new MongoClient().getDB(config.getWriterDatabaseName()); if (db.collectionExists(config.getWriterCollectionName())) { // Connect to the collection collection = db.getCollection(config.getWriterCollectionName()); } else {// w ww .j av a 2s . c o m // Create a capped collection so the database doesn't grow forever DBObject options = BasicDBObjectBuilder.start().add("capped", true) .add("size", config.getWriterMaxCollectionSizeBytes()).get(); collection = db.createCollection(config.getWriterCollectionName(), options); } return collection; }
From source file:org.chimi.s4s.metainfo.mongo.MongoMetaInfoDao.java
License:Apache License
@Override public FileMetadata selectByFileId(String fileId) { DBObject q = BasicDBObjectBuilder.start().add("FILE_ID", fileId).get(); DBObject doc = dbCollection.findOne(q); return convertMetaInfo(doc); }
From source file:org.eclipse.jetty.nosql.mongodb.MongoSessionDataStore.java
License:Open Source License
protected void ensureIndexes() throws MongoException { DBObject idKey = BasicDBObjectBuilder.start().add("id", 1).get(); _dbSessions.createIndex(idKey, BasicDBObjectBuilder.start().add("name", "id_1") .add("ns", _dbSessions.getFullName()).add("sparse", false).add("unique", true).get()); DBObject versionKey = BasicDBObjectBuilder.start().add("id", 1).add("version", 1).get(); _dbSessions.createIndex(versionKey, BasicDBObjectBuilder.start().add("name", "id_1_version_1") .add("ns", _dbSessions.getFullName()).add("sparse", false).add("unique", true).get()); //TODO perhaps index on expiry time? }
From source file:org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager.java
License:Open Source License
public MongoSessionIdManager(Server server, DBCollection sessions) { super(new Random()); _server = server;/*from w w w . ja va 2 s . com*/ _sessions = sessions; _sessions.ensureIndex(BasicDBObjectBuilder.start().add("id", 1).get(), BasicDBObjectBuilder.start().add("unique", true).add("sparse", false).get()); _sessions.ensureIndex(BasicDBObjectBuilder.start().add("id", 1).add("version", 1).get(), BasicDBObjectBuilder.start().add("unique", true).add("sparse", false).get()); // index our accessed and valid fields so that purges are faster, note that the "valid" field is first // so that we can take advantage of index prefixes // http://docs.mongodb.org/manual/core/index-compound/#compound-index-prefix _sessions.ensureIndex( BasicDBObjectBuilder.start().add(MongoSessionManager.__VALID, 1) .add(MongoSessionManager.__ACCESSED, 1).get(), BasicDBObjectBuilder.start().add("sparse", false).add("background", true).get()); }
From source file:org.einherjer.week2.samples.DocumentRepresentationSample.java
License:Apache License
public static void main(String[] args) { //1- using constructor and put BasicDBObject doc = new BasicDBObject(); doc.put("userName", "jyemin"); doc.put("birthDate", new Date(234832423)); doc.put("programmer", true); doc.put("age", 8); //use Arrays.asList is handy for constucting arrays with predefined values doc.put("languages", Arrays.asList("Java", "C++")); //2- using append doc.put("address", new BasicDBObject("street", "20 Main").append("town", "Westfield").append("zip", "56789")); System.out.println(doc);/* w w w .j av a2s . c o m*/ //3- using BasicDBObjectBuilder DBObject johnSmithDoc = BasicDBObjectBuilder.start().append("firstname", "John").append("lastname", "Smith") .get(); System.out.println(johnSmithDoc); }