List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start(final String key, final Object val)
From source file:org.apache.sling.mongodb.impl.MongoDBResourceProvider.java
License:Apache License
/** * TODO - we have to check for deleted and added resources * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource) *//*from www .ja v a 2 s .co m*/ public Iterator<Resource> listChildren(final Resource parent) { final String[] info = this.extractResourceInfo(parent.getPath()); if (info != null) { if (info.length == 0) { // all collections final Set<String> names = new HashSet<String>(context.getDatabase().getCollectionNames()); names.removeAll(this.context.getFilterCollectionNames()); final Iterator<String> i = names.iterator(); return new Iterator<Resource>() { public boolean hasNext() { return i.hasNext(); } public Resource next() { final String name = i.next(); return new MongoDBCollectionResource(parent.getResourceResolver(), parent.getPath() + '/' + name); } public void remove() { throw new UnsupportedOperationException("remove"); } }; } final DBCollection col = this.getCollection(info[0]); if (col != null) { final String pattern; if (info.length == 1) { pattern = "^([^/])*$"; } else { pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$"; } final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get(); final DBCursor cur = col.find(query).sort(BasicDBObjectBuilder.start(getPROP_PATH(), 1).get()); return new Iterator<Resource>() { public boolean hasNext() { return cur.hasNext(); } public Resource next() { final DBObject obj = cur.next(); final String objPath = obj.get(getPROP_PATH()).toString(); final int lastSlash = objPath.lastIndexOf('/'); final String name; if (lastSlash == -1) { name = objPath; } else { name = objPath.substring(lastSlash + 1); } return new MongoDBResource(parent.getResourceResolver(), parent.getPath() + '/' + name, info[0], obj, MongoDBResourceProvider.this); } public void remove() { throw new UnsupportedOperationException("remove"); } }; } } return null; }
From source file:org.baldeapi.v1.persistence.GenericDAO.java
License:Apache License
public DBObject updateFields(DBObject query, DBObject object, boolean multi) { object = BasicDBObjectBuilder.start("$set", object).get(); collection.update(query, object, false, multi); return object; }
From source file:org.ff4j.store.FeatureStoreMongoDB.java
License:Apache License
/** * Update status of feature./*from www .j a v a 2s .c o m*/ * * @param uid * feature id * @param enable * enabler */ private void updateStatus(String uid, boolean enable) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } DBObject target = BUILDER.getFeatUid(uid); Object enabledd = BUILDER.getEnable(enable); collection.update(target, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get()); }
From source file:org.ff4j.store.FeatureStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ @Override/* w w w . j a v a2 s. co m*/ public void enableGroup(String groupName) { if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException("Groupname cannot be null nor empty"); } if (!existGroup(groupName)) { throw new GroupNotFoundException(groupName); } for (DBObject dbObject : collection.find(BUILDER.getGroupName(groupName))) { Object enabledd = BUILDER.getEnable(true); collection.update(dbObject, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get()); } }
From source file:org.ff4j.store.FeatureStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ @Override/*from ww w .j a va 2 s . c o m*/ public void disableGroup(String groupName) { if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException("Groupname cannot be null nor empty"); } if (!existGroup(groupName)) { throw new GroupNotFoundException(groupName); } for (DBObject dbObject : collection.find(BUILDER.getGroupName(groupName))) { Object enabledd = BUILDER.getEnable(false); collection.update(dbObject, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get()); } }
From source file:org.ff4j.store.FeatureStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ @Override/* w w w .j a v a2s. c o m*/ public void addToGroup(String uid, String groupName) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException("Groupname cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } DBObject target = BUILDER.getFeatUid(uid); DBObject nGroupName = BUILDER.getGroupName(groupName); collection.update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get()); }
From source file:org.ff4j.store.FeatureStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ @Override//from w w w . j a va 2s .c o m public void removeFromGroup(String uid, String groupName) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException("Groupname cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } if (!existGroup(groupName)) { throw new GroupNotFoundException(groupName); } DBObject target = BUILDER.getFeatUid(uid); DBObject nGroupName = BUILDER.getGroupName(""); collection.update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get()); }
From source file:org.ff4j.store.PropertyStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ public void updateProperty(String name, String newValue) { assertPropertyName(name);/*from ww w.ja va2s . c o m*/ readProperty(name).fromString(newValue); DBObject query = BUILDER.getName(name); Object update = BUILDER.getValue(newValue); collection.update(query, BasicDBObjectBuilder.start(MONGO_SET, update).get()); }
From source file:org.geogit.storage.mongo.MongoGraph.java
License:Open Source License
public Vertex addVertex(Object key) { DBObject record;//from w w w . ja va 2s . c o m WriteResult result; if (key instanceof String) { record = BasicDBObjectBuilder.start("_id", (String) key).get(); } else { record = new BasicDBObject(); } result = collection.save(record); if (result.getLastError().ok()) return new MVertex(record); else throw new RuntimeException("Storing vertex to mongo failed: " + result.getError()); }
From source file:org.mongodb.demos.tailable.RealTimeAppServer.java
License:Apache License
public static void main(String[] args) throws Exception { RealTimeAppServer realTimeAppServer = new RealTimeAppServer(); DBCollection coll = realTimeAppServer.createAndGetCappedCollection("messages"); DBCursor cur = coll.find().sort(BasicDBObjectBuilder.start("$natural", 1).get()) .addOption(Bytes.QUERYOPTION_TAILABLE).addOption(Bytes.QUERYOPTION_AWAITDATA); System.out.println("== open cursor =="); Runnable task = () -> {/*from ww w .ja v a 2s. co m*/ System.out.println("\tWaiting for events"); while (cur.hasNext()) { DBObject obj = cur.next(); System.out.println(obj); } }; new Thread(task).start(); }