use of com.mongodb.QueryBuilder in project jackrabbit-oak by apache.
the class MongoDocumentStore method remove.
@Override
public <T extends Document> int remove(Collection<T> collection, Map<String, Map<Key, Condition>> toRemove) {
log("remove", toRemove);
int num = 0;
DBCollection dbCollection = getDBCollection(collection);
Stopwatch watch = startWatch();
try {
List<String> batchIds = Lists.newArrayList();
List<DBObject> batch = Lists.newArrayList();
Iterator<Entry<String, Map<Key, Condition>>> it = toRemove.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Map<Key, Condition>> entry = it.next();
QueryBuilder query = createQueryForUpdate(entry.getKey(), entry.getValue());
batchIds.add(entry.getKey());
batch.add(query.get());
if (!it.hasNext() || batch.size() == IN_CLAUSE_BATCH_SIZE) {
DBObject q = new BasicDBObject();
q.put(QueryOperators.OR, batch);
try {
num += dbCollection.remove(q).getN();
} catch (Exception e) {
throw DocumentStoreException.convert(e, "Remove failed for " + batch);
} finally {
if (collection == Collection.NODES) {
invalidateCache(batchIds);
}
}
batchIds.clear();
batch.clear();
}
}
} finally {
stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, num);
}
return num;
}
use of com.mongodb.QueryBuilder in project jackrabbit-oak by apache.
the class MongoBlobStore method countDeleteChunks.
@Override
public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
DBCollection collection = getBlobCollection();
QueryBuilder queryBuilder = new QueryBuilder();
if (chunkIds != null) {
queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).in(chunkIds.toArray(new String[0]));
if (maxLastModifiedTime > 0) {
queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD).lessThan(maxLastModifiedTime);
}
}
WriteResult result = collection.remove(queryBuilder.get());
return result.getN();
}
use of com.mongodb.QueryBuilder in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method handlesNativelyBuiltQueryCorrectly.
// DATAMONGO-373
@Test
public void handlesNativelyBuiltQueryCorrectly() {
DBObject query = new QueryBuilder().or(new BasicDBObject("foo", "bar")).get();
mapper.getMappedObject(new org.bson.Document(query.toMap()), Optional.empty());
}
use of com.mongodb.QueryBuilder in project records-management by Alfresco.
the class RecordService method getRecordCountInSpecifiedPaths.
/**
* Helper for counting the records with specified execution state, that has the parent path in specified list or from all existent records if listOfParentPaths is null or empty.
*
* @param state - record execution state to search for
* @param listOfParentPaths - list of parent paths to search in
* @return for counting the records with specified execution state, that has the parent path in specified list or from all existent records if listOfParentPaths is null or empty.
*/
public long getRecordCountInSpecifiedPaths(String state, List<String> listOfParentPaths) {
if (state == null) {
throw new IllegalArgumentException();
}
QueryBuilder queryObjBuilder = QueryBuilder.start();
queryObjBuilder.and(FIELD_STATE).is(state);
if (listOfParentPaths != null && listOfParentPaths.size() > 0) {
queryObjBuilder.and(FIELD_PARENT_PATH).in(listOfParentPaths);
}
DBObject queryObj = queryObjBuilder.get();
long count = collection.count(queryObj);
return count;
}
use of com.mongodb.QueryBuilder in project incubator-rya by apache.
the class GeoTemporalMongoDBStorageStrategy method getFilterQuery.
public DBObject getFilterQuery(final Collection<IndexingExpr> geoFilters, final Collection<IndexingExpr> temporalFilters) throws GeoTemporalIndexException {
final QueryBuilder builder = QueryBuilder.start();
if (!geoFilters.isEmpty()) {
final DBObject[] geo = getGeoObjs(geoFilters);
if (!temporalFilters.isEmpty()) {
final DBObject[] temporal = getTemporalObjs(temporalFilters);
builder.and(oneOrAnd(geo), oneOrAnd(temporal));
return builder.get();
} else {
return oneOrAnd(geo);
}
} else if (!temporalFilters.isEmpty()) {
final DBObject[] temporal = getTemporalObjs(temporalFilters);
return oneOrAnd(temporal);
} else {
return builder.get();
}
}
Aggregations