List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:org.gennai.gungnir.topology.processor.MongoFetchProcessor.java
License:Apache License
private static Document getQuery(Map<String, Object> query, GungnirTuple tuple) { Document queryCopy = new Document(); for (Map.Entry<String, Object> entry : query.entrySet()) { if (entry.getValue() instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) entry.getValue(); queryCopy.append(entry.getKey(), getQuery(map, tuple)); } else if (entry.getValue() instanceof List) { @SuppressWarnings("unchecked") List<Object> list = (List<Object>) entry.getValue(); BasicDBList dbList = new BasicDBList(); for (Object element : list) { if (element instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) element; dbList.add(getQuery(map, tuple)); } else if (element instanceof PlaceHolders) { dbList.add(getQueryValue((PlaceHolders) element, tuple)); } else { dbList.add(element); }/*from w ww .j a v a2 s .co m*/ queryCopy.append(entry.getKey(), list); } } else if (entry.getValue() instanceof PlaceHolders) { queryCopy.append(entry.getKey(), getQueryValue((PlaceHolders) entry.getValue(), tuple)); } else { queryCopy.append(entry.getKey(), entry.getValue()); } } return queryCopy; }
From source file:org.geotools.data.mongodb.FilterToMongo.java
License:LGPL
@Override public Object visit(Or filter, Object extraData) { BasicDBObject output = asDBObject(extraData); List<Filter> children = filter.getChildren(); BasicDBList orList = new BasicDBList(); if (children != null) { for (Filter child : children) { BasicDBObject item = (BasicDBObject) child.accept(this, null); orList.add(item);//from w w w .ja v a 2 s .c o m } output.put("$or", orList); } return output; }
From source file:org.geotools.data.mongodb.FilterToMongoQuery.java
License:LGPL
public Object visit(Or filter, Object extraData) { BasicDBObject output = asDBObject(extraData); List<Filter> children = filter.getChildren(); BasicDBList orList = new BasicDBList(); if (children != null) { for (Iterator<Filter> i = children.iterator(); i.hasNext();) { Filter child = i.next(); BasicDBObject item = (BasicDBObject) child.accept(this, null); orList.add(item);// www . j a va2 s .c om } output.put("$or", orList); } return output; }
From source file:org.glassfish.cdinosqldemo.Order.java
License:Open Source License
@SuppressWarnings("rawtypes") public List getOrderLines() { BasicDBList orderLines = (BasicDBList) get("orderLines"); if (orderLines == null) { orderLines = new BasicDBList(); put("orderLines", orderLines); }//from www. jav a2s.co m return orderLines; }
From source file:org.graylog2.events.ClusterEventPeriodical.java
License:Open Source License
private DBCursor<ClusterEvent> eventCursor(NodeId nodeId) { // Resorting to ugly MongoDB Java Client because of https://github.com/devbliss/mongojack/issues/88 final DBObject producerClause = new BasicDBObject("producer", new BasicDBObject("$ne", nodeId.toString())); final BasicDBList consumersList = new BasicDBList(); consumersList.add(nodeId.toString()); final DBObject consumersClause = new BasicDBObject("consumers", new BasicDBObject("$nin", consumersList)); final BasicDBList and = new BasicDBList(); and.add(producerClause);//from w w w .jav a 2s. c o m and.add(consumersClause); final DBObject query = new BasicDBObject("$and", and); return dbCollection.find(query).sort(DBSort.asc("timestamp")); }
From source file:org.graylog2.indexer.ranges.LegacyMongoIndexRangeService.java
License:Open Source License
@Override public SortedSet<IndexRange> findAll() { final BasicDBList subQueries = new BasicDBList(); subQueries.add(new BasicDBObject(FIELD_INDEX, new BasicDBObject("$exists", true))); subQueries.add(new BasicDBObject(FIELD_START, new BasicDBObject("$exists", true))); final DBObject query = new BasicDBObject("$and", subQueries); final List<DBObject> result = query(query, COLLECTION_NAME); final ImmutableSortedSet.Builder<IndexRange> indexRanges = ImmutableSortedSet .orderedBy(IndexRange.COMPARATOR); for (DBObject dbo : result) { try {//from w w w .j a v a2s . c o m indexRanges.add(buildIndexRange(dbo)); } catch (Exception e) { LOG.debug("Couldn't add index range to result set: " + dbo, e); } } return indexRanges.build(); }
From source file:org.iternine.jeppetto.dao.mongodb.enhance.UpdateList.java
License:Apache License
@Override public void clear() { clear = true;//from w w w .j a va 2 s .c om operation = null; updates = new BasicDBList(); // When clear() is called, List-types become the only supported form. }
From source file:org.iternine.jeppetto.dao.mongodb.enhance.UpdateSet.java
License:Apache License
@Override public DBObject getUpdateClause() { if (clear) {// w w w .j a v a 2 s . c om // If new items were added, they'll be placed on the updateList. Either way We use $set to ensure old // values are removed from the underlying store. BasicDBList updateList = new BasicDBList(); updateList.addAll(updates); return new BasicDBObject($set.name(), new BasicDBObject(getNameFromPrefix(), updateList)); } else { if (updates.isEmpty()) { return new BasicDBObject(); // If there are no updates, return an empty DBObject } else { BasicDBList updateList = new BasicDBList(); updateList.addAll(updates); if (operation.equals($addToSet)) { return new BasicDBObject($addToSet.name(), new BasicDBObject(getNameFromPrefix(), new BasicDBObject(EACH, updateList))); } else { return new BasicDBObject(operation.name(), new BasicDBObject(getNameFromPrefix(), updateList)); } } } }
From source file:org.jberet.repository.MongoRepository.java
License:Open Source License
@Override public List<Long> getRunningExecutions(final String jobName) { //find all job instance ids belonging to the jobName DBObject keys = new BasicDBObject(TableColumns.JOBINSTANCEID, 1); DBCursor cursor = db.getCollection(TableColumns.JOB_INSTANCE) .find(new BasicDBObject(TableColumns.JOBNAME, jobName), keys); if (cursor.size() == 0) { throw BatchMessages.MESSAGES.noSuchJobException(jobName); }//from www .ja v a 2 s .c om //add matching job instance ids to the "jobinstanceid in" list BasicDBList basicDBList = new BasicDBList(); while (cursor.hasNext()) { final DBObject next = cursor.next(); basicDBList.add(next.get(TableColumns.JOBINSTANCEID)); } final DBObject inJobInstanceIdsClause = new BasicDBObject("$in", basicDBList); final DBObject query = new BasicDBObject(TableColumns.JOBINSTANCEID, inJobInstanceIdsClause); //create "batchstatus in" list basicDBList = new BasicDBList(); basicDBList.add(BatchStatus.STARTED.name()); basicDBList.add(BatchStatus.STARTING.name()); final DBObject inBatchStatusClause = new BasicDBObject("$in", basicDBList); //combine batchstatus in clause into jobinstanceid in clause query.put(TableColumns.BATCHSTATUS, inBatchStatusClause); keys = new BasicDBObject(TableColumns.JOBEXECUTIONID, 1); cursor = db.getCollection(TableColumns.JOB_EXECUTION).find(query, keys); final List<Long> result = new ArrayList<Long>(); while (cursor.hasNext()) { final DBObject next = cursor.next(); result.add((Long) next.get(TableColumns.JOBEXECUTIONID)); } return result; }
From source file:org.jberet.repository.MongoRepository.java
License:Open Source License
@Override public StepExecutionImpl findOriginalStepExecutionForRestart(final String stepName, final JobExecutionImpl jobExecutionToRestart, final ClassLoader classLoader) { final StepExecutionImpl result = super.findOriginalStepExecutionForRestart(stepName, jobExecutionToRestart, classLoader);/* ww w . j ava 2 s .c o m*/ if (result != null) { return result; } final DBObject keys = new BasicDBObject(TableColumns.JOBEXECUTIONID, 1); keys.put(TableColumns._id, 0); final DBCursor cursor = db.getCollection(TableColumns.JOB_EXECUTION).find(new BasicDBObject( TableColumns.JOBINSTANCEID, jobExecutionToRestart.getJobInstance().getInstanceId()), keys); final BasicDBList basicDBList = new BasicDBList(); while (cursor.hasNext()) { final DBObject next = cursor.next(); basicDBList.add(next.get(TableColumns.JOBEXECUTIONID)); } final DBObject inClause = new BasicDBObject("$in", basicDBList); final DBObject query = new BasicDBObject(TableColumns.JOBEXECUTIONID, inClause); query.put(TableColumns.STEPNAME, stepName); final DBCursor cursor1 = db.getCollection(TableColumns.STEP_EXECUTION).find(query) .sort(new BasicDBObject(TableColumns.STEPEXECUTIONID, -1)); return createStepExecutionFromDBObject(cursor1.one(), classLoader); }