@Override public long totalCountForStreams(List<String> streamIds, AlertState state) { if (streamIds == null || streamIds.isEmpty()) { return 0; } DBQuery.Query query = getFindAnyStreamQuery(streamIds); if (state != null && state != AlertState.ANY) { query = DBQuery.and(query, getFindByStateQuery(state)); } return this.coll.count(this.coll.serializeQuery(query)); }
/** * calls * {@link DBCollection#findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)} * with fields=null, sort=null, remove=true, returnNew=false, upsert=false * * @param query * The query * @return the removed object */ public T findAndRemove(DBQuery.Query query) { return findAndModify(serializeQuery(query), null, null, true, new BasicDBObject(), false, false); // Alibi DBObject due // ambiguous method call }
/** * Returns the number of documents in the collection that match the * specified query * * @param query * query to select documents to count * @param fields * fields to return * @param limit * limit the count to this value * @param skip * number of entries to skip * @return number of documents that match query and fields * @throws MongoException * If an error occurred */ public long getCount(DBQuery.Query query, DBObject fields, long limit, long skip) throws MongoException { return dbCollection .getCount(serializeQuery(query), fields, limit, skip); }
/** * Queries for an object in this collection. * * @param query * object for which to search * @return an iterator over the results * @throws MongoException * If an error occurred */ public org.mongojack.DBCursor<T> find(DBQuery.Query query) throws MongoException { return new org.mongojack.DBCursor<T>(this, dbCollection.find(serializeQuery(query))); }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param query * the query * @return The write result * @throws MongoException * If an error occurred */ public WriteResult<T, K> remove(DBQuery.Query query) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(serializeQuery(query))); }
/** * Removes objects from the database collection. * * @param query * the query * @param concern * WriteConcern for this operation * @return The result * @throws MongoException * If an error occurred */ public WriteResult<T, K> remove(DBQuery.Query query, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove( serializeQuery(query), concern)); }
/** * Queries for an object in this collection. * <p> * <p> * An empty DBObject will match every document in the collection. Regardless of fields specified, the _id fields are * always returned. * </p> * To keys object should have non null values for every key that you want to * return * * @param query * object for which to search * @param keys * fields to return * @return a cursor to iterate over results */ public org.mongojack.DBCursor<T> find(DBQuery.Query query, DBObject keys) { return new org.mongojack.DBCursor<T>(this, dbCollection.find( serializeQuery(query), keys)); }
@Override public long totalCountForStreams(List<String> streamIds, AlertState state) { if (streamIds == null || streamIds.isEmpty()) { return 0; } DBQuery.Query query = getFindAnyStreamQuery(streamIds); if (state != null && state != AlertState.ANY) { query = DBQuery.and(query, getFindByStateQuery(state)); } return this.coll.count(this.coll.serializeQuery(query)); }
@Override protected DBCursor<T> putGroup(String op, DBQuery.Query... expressions) { checkExecuted(); List<DBObject> conditions; Object existing = cursor.getQuery().get(op); if (existing == null) { conditions = new ArrayList<DBObject>(); cursor.getQuery().put(op, conditions); } else if (existing instanceof List) { conditions = (List<DBObject>) existing; } else { throw new IllegalStateException("Expecting collection for " + op); } for (DBQuery.Query query : expressions) { conditions.add(jacksonDBCollection.serializeQuery(query)); } return this; } }
/** * Finds the first document in the query and updates it. * * @param query * query to match * @param fields * fields to be returned * @param sort * sort to apply before picking first document * @param remove * if true, document found will be removed * @param update * update to apply * @param returnNew * if true, the updated document is returned, otherwise the old * document is returned (or it would be lost forever) * @param upsert * do upsert (insert if document not present) * @return the object */ public T findAndModify(DBQuery.Query query, DBObject fields, DBObject sort, boolean remove, DBUpdate.Builder update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify( serializeQuery(query), fields, sort, remove, update.serialiseAndGet(objectMapper, type), returnNew, upsert)); }
/** * Finds the first document in the query and updates it. * * @param query * query to match * @param fields * fields to be returned * @param sort * sort to apply before picking first document * @param remove * if true, document found will be removed * @param update * update to apply * @param returnNew * if true, the updated document is returned, otherwise the old * document is returned (or it would be lost forever) * @param upsert * do upsert (insert if document not present) * @return the object */ public T findAndModify(DBQuery.Query query, DBObject fields, DBObject sort, boolean remove, T update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify( serializeQuery(query), fields, sort, remove, convertToBasicDbObject(update), returnNew, upsert)); }
/** * Performs an update operation. * * @param query * search query for old object to update * @param update * update with which to update <tt>query</tt> * @param upsert * if the database should create the element if it does not exist * @param multi * if the update should be applied to all objects matching (db * version 1.1.3 and above). An object will not be inserted if it * does not exist in the collection and upsert=true and * multi=true. See <a * href="http://www.mongodb.org/display/DOCS/Atomic+Operations" * >http://www.mongodb.org/display/DOCS/Atomic+Operations</a> * @param concern * the write concern * @return The write result * @throws MongoException * If an error occurred */ public WriteResult<T, K> update(DBQuery.Query query, DBUpdate.Builder update, boolean upsert, boolean multi, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.update( serializeQuery(query), update.serialiseAndGet(objectMapper, type), upsert, multi, concern)); }
/** * Performs an update operation. * * @param query * search query for old object to update * @param object * object with which to update <tt>query</tt> * @param upsert * if the database should create the element if it does not exist * @param multi * if the update should be applied to all objects matching (db * version 1.1.3 and above). An object will not be inserted if it * does not exist in the collection and upsert=true and * multi=true. See <a * href="http://www.mongodb.org/display/DOCS/Atomic+Operations" * >http://www.mongodb.org/display/DOCS/Atomic+Operations</a> * @param concern * the write concern * @return The write result * @throws MongoException * If an error occurred */ public WriteResult<T, K> update(DBQuery.Query query, T object, boolean upsert, boolean multi, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.update( serializeQuery(query), convertToBasicDbObject(object), upsert, multi, concern)); }
com.mongodb.MapReduceCommand build(JacksonDBCollection<?, ?> collection) { DBObject query = null; if (this.query != null) { query = collection.serializeQuery(this.query); } com.mongodb.MapReduceCommand command = new com.mongodb.MapReduceCommand( collection.getDbCollection(), map, reduce, this.collection, outputType.getDriverType(), query); if (finalize != null) { command.setFinalize(finalize); } if (readPreference != null) { command.setReadPreference(readPreference); } if (outputDB != null) { command.setOutputDB(outputDB); } if (sort != null) { command.setSort(sort); } command.setLimit(limit); if (scope != null) { command.setScope(scope); } command.setVerbose(verbose); return command; }