List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:com.effektif.mongo.MongoWorkflowInstanceStore.java
License:Apache License
public DBObject createLockQuery() { return BasicDBObjectBuilder.start().push(LOCK).add("$exists", false).pop().get(); }
From source file:com.effektif.mongo.MongoWorkflowInstanceStore.java
License:Apache License
public DBObject createLockUpdate() { return BasicDBObjectBuilder.start().push("$set").push(LOCK).add(Lock.TIME, Time.now().toDate()) .add(Lock.OWNER, workflowEngine.getId()).pop().pop().get(); }
From source file:com.ejbmongoembeddedtomcat.converter.CustomerConverter.java
public static DBObject toDBObject(Customer cus) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("name", cus.getName()) .append("address", cus.getAddress()).append("kota", cus.getKota()); if (cus.getId() != null) { builder = builder.append("_id", new ObjectId(cus.getId())); }/*from ww w. ja v a 2 s. c o m*/ return builder.get(); }
From source file:com.ejbmongoembeddedtomcat.service.MongoService.java
public void updateCustomer(Customer cus) { DBObject query = BasicDBObjectBuilder.start().append("_id", new ObjectId(cus.getId())).get(); this.col.update(query, CustomerConverter.toDBObject(cus)); }
From source file:com.ejbmongoembeddedtomcat.service.MongoService.java
public void deleteCustomer(Customer cus) { DBObject query = BasicDBObjectBuilder.start().append("_id", new ObjectId(cus.getId())).get(); this.col.remove(query); }
From source file:com.ejbmongoembeddedtomcat.service.MongoService.java
public Customer readCustomer(Customer cus) { DBObject query = BasicDBObjectBuilder.start().append("_id", new ObjectId(cus.getId())).get(); DBObject data = this.col.findOne(query); return CustomerConverter.toCustomer(data); }
From source file:com.englishtown.vertx.GridFSModule.java
License:Open Source License
public void saveFile(Message<JsonObject> message, JsonObject jsonObject) { ObjectId id = getObjectId(message, jsonObject, "id"); if (id == null) { return;//from w w w .j a v a 2 s. c om } Integer length = getRequiredInt("length", message, jsonObject, 1); if (length == null) { return; } Integer chunkSize = getRequiredInt("chunkSize", message, jsonObject, 1); if (chunkSize == null) { return; } long uploadDate = jsonObject.getLong("uploadDate", 0); if (uploadDate <= 0) { uploadDate = System.currentTimeMillis(); } String filename = jsonObject.getString("filename"); String contentType = jsonObject.getString("contentType"); JsonObject metadata = jsonObject.getObject("metadata"); try { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().add("_id", id).add("length", length) .add("chunkSize", chunkSize).add("uploadDate", new Date(uploadDate)); if (filename != null) builder.add("filename", filename); if (contentType != null) builder.add("contentType", contentType); if (metadata != null) builder.add("metadata", JSON.parse(metadata.encode())); DBObject dbObject = builder.get(); String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET); DBCollection collection = db.getCollection(bucket + ".files"); // Ensure standard indexes as long as collection is small if (collection.count() < 1000) { collection.ensureIndex(BasicDBObjectBuilder.start().add("filename", 1).add("uploadDate", 1).get()); } collection.save(dbObject); sendOK(message); } catch (Exception e) { sendError(message, "Error saving file", e); } }
From source file:com.englishtown.vertx.GridFSModule.java
License:Open Source License
public void saveChunk(Message<Buffer> message, JsonObject jsonObject, byte[] data) { if (data == null || data.length == 0) { sendError(message, "chunk data is missing"); return;/*w w w .ja v a 2s . com*/ } ObjectId id = getObjectId(message, jsonObject, "files_id"); if (id == null) { return; } Integer n = getRequiredInt("n", message, jsonObject, 0); if (n == null) { return; } try { DBObject dbObject = BasicDBObjectBuilder.start().add("files_id", id).add("n", n).add("data", data) .get(); String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET); DBCollection collection = db.getCollection(bucket + ".chunks"); // Ensure standard indexes as long as collection is small if (collection.count() < 1000) { collection.ensureIndex(BasicDBObjectBuilder.start().add("files_id", 1).add("n", 1).get(), BasicDBObjectBuilder.start().add("unique", 1).get()); } collection.save(dbObject); sendOK(message); } catch (RuntimeException e) { sendError(message, "Error saving chunk", e); } }
From source file:com.exorath.service.connector.service.MongoDatabaseProvider.java
License:Apache License
@Override public ServerInfo getServerInfo(Filter filter, Long minLastUpdate) { //Fingers crossed BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); if (filter.getGameId() != null) builder.append("gameId", filter.getGameId()); if (filter.getMapId() != null) builder.append("mapId", filter.getMapId()); if (filter.getFlavorId() != null) builder.append("flavorId", filter.getFlavorId()); builder.append("expiry", new BasicDBObject("$gte", System.currentTimeMillis())); MapReduceCommand mapReduceCommand = new MapReduceCommand(datastore.getDB().getCollection(collectionName), "function(){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "ret.pc = this.pc; ret.sc = 1;" + "if(this.joinable && this.pc < this.mpc){ ret.opc = this.mpc - this.pc; ret.osc = 1;}" + "emit('server', ret);}", "function(key, values){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "values.forEach( function(value) {" + " ret.pc+= value.pc; ret.sc++;" + " ret.osc+= value.osc; ret.opc+= value.opc" + " });" + "return ret;" + "}", null, MapReduceCommand.OutputType.INLINE, builder.get()); MapReduceOutput results = datastore.getDB().getCollection(collectionName).mapReduce(mapReduceCommand); if (results.getOutputCount() == 0) return new ServerInfo(0, 0, 0, 0, System.currentTimeMillis()); if (results.getOutputCount() > 1) throw new IllegalStateException("mapReduce returned multiple results."); for (DBObject res : results.results()) { DBObject val = (DBObject) res.get("value"); return new ServerInfo(((Double) val.get("pc")).intValue(), ((Double) val.get("sc")).intValue(), ((Double) val.get("osc")).intValue(), ((Double) val.get("opc")).intValue(), System.currentTimeMillis()); }//from www.j a va 2s . com //// MapreduceResults<ServerInfo> results = datastore.mapReduce(MapreduceType.INLINE, getFilterQuery(filter), ServerInfo.class, mapReduceCommand); //// if(results.getCounts().getOutputCount() == 0) { //// System.out.println("output 0 :*"); // return null; // } // System.out.println("ms: " + results.getElapsedMillis()); // results.forEach(info -> System.out.println(info.getOpenSlotCount())); return null; }
From source file:com.gigaspaces.persistency.datasource.MongoQueryFactory.java
License:Open Source License
private static BasicDBObjectBuilder replaceParameters(Object[] parameters, SpaceDocumentMapper<DBObject> mapper, BasicDBObjectBuilder builder, Integer index) { BasicDBObjectBuilder newBuilder = BasicDBObjectBuilder.start(); DBObject document = builder.get();/*from ww w . j a v a 2s . c o m*/ Iterator<String> iterator = document.keySet().iterator(); while (iterator.hasNext()) { String field = iterator.next(); Object ph = document.get(field); if (index >= parameters.length) return builder; if (ph instanceof String) { if (PARAM_PLACEHOLDER.equals(ph)) { Object p = mapper.toObject(parameters[index++]); if (p instanceof DBObject && Constants.CUSTOM_BINARY.equals(((DBObject) p).get(Constants.TYPE))) { newBuilder.add(field + "." + Constants.HASH, ((DBObject) p).get(Constants.HASH)); } else { newBuilder.add(field, p); } } } else if (ph instanceof Pattern) { Pattern p = (Pattern) ph; if (LIKE.equalsIgnoreCase(p.pattern())) { newBuilder.add(field, convertLikeExpression((String) parameters[index++])); } else if (RLIKE.equalsIgnoreCase(p.pattern())) { newBuilder.add(field, Pattern.compile((String) parameters[index++], Pattern.CASE_INSENSITIVE)); } } else { DBObject element = (DBObject) ph; Object p = mapper.toObject(parameters[index]); if (p instanceof DBObject) { String t = (String) ((DBObject) p).get(Constants.TYPE); String op = element.keySet().iterator().next(); if (Constants.CUSTOM_BINARY.equals(t) && !op.equals("$ne")) return newBuilder; } BasicDBObjectBuilder doc = replaceParameters(parameters, mapper, BasicDBObjectBuilder.start(element.toMap()), index); newBuilder.add(field, doc.get()); } } return newBuilder; }