List of usage examples for com.mongodb BasicDBObject append
@Override public BasicDBObject append(final String key, final Object val)
From source file:com.github.bluetiger9.nosql.benchmarking.clients.document.mongodb.MongoDBClient.java
License:Open Source License
@Override public void insert(String key, Map<String, String> attributes) throws ClientException { final BasicDBObject doc = new BasicDBObject(); doc.append("_id", key); for (Map.Entry<String, String> entry : attributes.entrySet()) { doc.append(entry.getKey(), entry.getValue()); }/*from w w w . j a va2s . c o m*/ dbCollection.insert(doc); }
From source file:com.github.bluetiger9.nosql.benchmarking.clients.document.mongodb.MongoDBClient.java
License:Open Source License
@Override public void update(String key, Map<String, String> attributes) throws ClientException { final BasicDBObject doc = new BasicDBObject(); for (Map.Entry<String, String> entry : attributes.entrySet()) { doc.append(entry.getKey(), entry.getValue()); }/*from ww w. ja v a 2 s. co m*/ dbCollection.update(new BasicDBObject("_id", key), new BasicDBObject("$set", doc)); }
From source file:com.github.dbourdette.otto.web.util.IntervalUtils.java
License:Apache License
public static BasicDBObject query(DateTime from, DateTime to) { BasicDBObject criteria = new BasicDBObject(); if (from == null && to == null) { return criteria; }//from www .j ava 2s. com if (from != null) { criteria.append("$gte", from.toDate()); } if (to != null) { criteria.append("$lt", to.toDate()); } return new BasicDBObject("date", criteria); }
From source file:com.groupon.jenkins.dynamic.build.repository.DynamicBuildRepository.java
License:Open Source License
public <T extends DbBackedBuild> Iterable<T> getBuildGreaterThan(DbBackedProject project, String n, String branch) {/*from www . j a v a2 s. c o m*/ BasicDBObject query = getQuery(project); if (branch != null) { query.append("branch", branch); } return getBuildsGreaterThan(project, n, query); }
From source file:com.groupon.jenkins.dynamic.build.repository.DynamicBuildRepository.java
License:Open Source License
public <T extends DbBackedBuild> Iterable<T> getLast(DbBackedProject project, int i, String branch) { BasicDBObject query = getQuery(project); if (branch != null) { query.append("branch", branch); }//from w w w . java 2 s . c o m return find(query, new BasicDBObject("number", -1), i, DynamicBuildRepository.<T>getTransformer(project)); }
From source file:com.groupon.jenkins.dynamic.build.repository.DynamicBuildRepository.java
License:Open Source License
public void deleteBuild(DbBackedBuild build) { BasicDBObject query = getQuery((DbBackedProject) build.getProject()); query.append("number", build.getNumber()); delete(query);/*from ww w . j a va 2s.c om*/ }
From source file:com.groupon.jenkins.dynamic.build.repository.DynamicBuildRepository.java
License:Open Source License
public DbBackedBuild getPreviousFinishedBuildOfSameBranch(DbBackedBuild build, String branch) { BasicDBObject query = getQuery((DbBackedProject) build.getProject()); query.append("branch", branch); query.append("state", "COMPLETED"); query.putAll(QueryBuilder.start("number").lessThan(build.getNumber()).get()); return findOne(query, null, new BasicDBObject("number", -1), getTransformer((DbBackedProject) build.getProject())); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestAndORComplexStmt.java
License:Open Source License
/** * @param args/*from w w w.j a v a 2 s.co m*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); DBCollection myColl = db.getCollection("rental"); BasicDBObject mainQuery = new BasicDBObject(); // tmp and BasicDBObject tmpAndQuery = new BasicDBObject(); tmpAndQuery.append("inventory_id", 100); tmpAndQuery.append("rental_id", new BasicDBObject("$ne", 1)); mainQuery.put("$and", tmpAndQuery); // tmp or ArrayList<BasicDBObject> myList = new ArrayList<BasicDBObject>(); myList.add(new BasicDBObject("customer_id", 3)); mainQuery.put("$or", myList); System.out.println(mainQuery.toString()); DBCursor myCursor = myColl.find(mainQuery); System.out.println("[result cursor size is " + myCursor.count()); while (myCursor.hasNext()) { System.out.println(myCursor.next()); } mongo.close(); }
From source file:com.health.smart.ejb.MongoEJB.java
@Schedule(minute = "*/15", hour = "*", persistent = false) public void checkMeasurement() throws Exception { BasicDBObject gt60 = new BasicDBObject("$gte", 160); BasicDBObject alertExists = new BasicDBObject("$exists", false); BasicDBObject doc = new BasicDBObject("bph", gt60).append("alerted", alertExists); List<DBObject> result = MongoC.findObject("measurement", doc); for (DBObject obj : result) { int pid = (Integer) obj.get("patientId"); double value = (Double) obj.get("bph"); int success = ejb.sendMsg(pid, String.format("Systolic level too high (%s)!\r\n Please make appointment ASAP!", NumberFormat.getInstance().format(value))); if (success > 0) { obj.put("alerted", true); BasicDBObject filter = new BasicDBObject(); filter.append("_id", obj.get("_id")); MongoC.update("measurement", filter, obj); }/*w w w. j a va 2 s . co m*/ } }
From source file:com.heisenberg.mongo.MongoWorkflowInstanceStore.java
License:Apache License
@Override public void flush(WorkflowInstanceImpl workflowInstance) { if (log.isDebugEnabled()) log.debug("Flushing..."); WorkflowInstanceUpdates updates = workflowInstance.getUpdates(); DBObject query = BasicDBObjectBuilder.start().add(fields._id, new ObjectId(workflowInstance.id)) .add(fields.lock, writeLock(workflowInstance.lock)).get(); BasicDBObject sets = new BasicDBObject(); BasicDBObject unsets = new BasicDBObject(); BasicDBObject update = new BasicDBObject(); if (updates.isEndChanged) { if (log.isDebugEnabled()) log.debug(" Workflow instance ended"); sets.append(fields.end, workflowInstance.end); sets.append(fields.duration, workflowInstance.duration); }// w ww . ja v a2 s .c o m // MongoDB can't combine updates of array elements together with // adding elements to that array. That's why we overwrite the whole // activity instance array when an update happened in there. // We do archive the ended (and joined) activity instances into a separate collection // that doesn't have to be loaded. if (updates.isActivityInstancesChanged) { if (log.isDebugEnabled()) log.debug(" Activity instances changed"); List<BasicDBObject> activityInstances = new ArrayList<>(); List<BasicDBObject> archivedActivityInstances = new ArrayList<>(); collectActivities(workflowInstance, activityInstances, archivedActivityInstances); sets.append(fields.activityInstances, activityInstances); if (!archivedActivityInstances.isEmpty()) { update.append("$push", new BasicDBObject(fields.archivedActivityInstances, archivedActivityInstances)); } } else { if (log.isDebugEnabled()) log.debug(" No activity instances changed"); } if (updates.isVariableInstancesChanged) { if (log.isDebugEnabled()) log.debug(" Variable instances changed"); writeVariables(sets, workflowInstance); } else { if (log.isDebugEnabled()) log.debug(" No variable instances changed"); } if (updates.isWorkChanged) { if (log.isDebugEnabled()) log.debug(" Work changed"); List<ObjectId> work = writeWork(workflowInstance.work); if (work != null) { sets.put(fields.work, work); } else { unsets.put(fields.work, 1); } } else { if (log.isDebugEnabled()) log.debug(" No work changed"); } if (updates.isAsyncWorkChanged) { if (log.isDebugEnabled()) log.debug(" Aync work changed"); List<ObjectId> workAsync = writeWork(workflowInstance.workAsync); if (workAsync != null) { sets.put(fields.workAsync, workAsync); } else { unsets.put(fields.workAsync, 1); } } else { if (log.isDebugEnabled()) log.debug(" No async work changed"); } if (!sets.isEmpty()) { update.append("$set", sets); } else { if (log.isDebugEnabled()) log.debug(" No sets"); } if (!unsets.isEmpty()) { update.append("$unset", unsets); } else { if (log.isDebugEnabled()) log.debug(" No unsets"); } if (!update.isEmpty()) { update(query, update, false, false, writeConcernFlushUpdates); } else { if (log.isDebugEnabled()) log.debug(" Nothing to flush"); } // reset the update tracking as all changes have been saved workflowInstance.trackUpdates(false); }