List of usage examples for org.springframework.data.mongodb.core.query Query addCriteria
public Query addCriteria(CriteriaDefinition criteriaDefinition)
From source file:org.oncoblocks.centromere.mongodb.GenericMongoRepository.java
/** * {@link RepositoryOperations#distinct(String, Iterable)} *//*from ww w .j a v a2 s .c om*/ public List<Object> distinct(String field, Iterable<QueryCriteria> queryCriterias) { Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias); Query query = new Query(); if (criteria != null) { query.addCriteria(criteria); } return mongoOperations.getCollection(mongoOperations.getCollectionName(model)).distinct(field, query.getQueryObject()); }
From source file:things.mongo.MongoConnector.java
@Override public Observable<? extends Thing<?>> findThingsForTypeMatchingKey(String type, String key) { final Timer.Context context = find_exact_type_matching_key_timer.time(); try {// www . java 2s . co m Query q = new Query(); String regexKey = MatcherUtils.convertGlobToRegex(key); q.addCriteria(Criteria.where("thingType").is(type).and("key").regex(regexKey)); List<Thing> things = mongoTemplate.find(q, Thing.class); return Observable.from(things).map(t -> (Thing<?>) t); } finally { context.stop(); } }
From source file:org.oncoblocks.centromere.mongodb.GenericMongoRepository.java
/** * {@link RepositoryOperations#findAll}//from w w w .j a v a2 s .c o m */ public Page<T> find(Iterable<QueryCriteria> queryCriterias, Pageable pageable) { Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias); Query query = new Query(); if (criteria != null) { query.addCriteria(criteria); } List<T> entities = mongoOperations.find(query.with(pageable), model); long count = count(queryCriterias); return new PageImpl<T>(entities, pageable, count); }
From source file:com.traffitruck.service.MongoDAO.java
public ResetPassword getResetPassword(String uuid, String username) { Query q = new Query(); q.addCriteria(Criteria.where("uuid").is(uuid)).addCriteria(Criteria.where("username").is(username)); ResetPassword rp = mongoTemplate.findOne(q, ResetPassword.class); return rp;/*from w w w . jav a 2 s . c o m*/ }
From source file:com.traffitruck.service.MongoDAO.java
public Load getLoad(String loadId) { Query q = new Query(); q.addCriteria(Criteria.where("_id").is(loadId)); q.fields().exclude("loadPhoto"); List<Load> loadslist = mongoTemplate.find(q, Load.class); if (loadslist.isEmpty()) return null; return loadslist.get(0); }
From source file:com.traffitruck.service.MongoDAO.java
public void updateLoad(Load load) { Query q = new Query(); q.addCriteria(Criteria.where("_id").is(load.getId())); Update update = new Update(); update.set("source", load.getSource()); update.set("sourceLocation", load.getSourceLocation()); update.set("destinationLocation", load.getDestinationLocation()); update.set("destination", load.getDestination()); update.set("driveDate", load.getDriveDate()); update.set("suggestedQuote", load.getSuggestedQuote()); update.set("weight", load.getWeight()); update.set("volume", load.getVolume()); update.set("comments", load.getComments()); update.set("comments", load.getComments()); update.set("quantity", load.getQuantity()); update.set("loadingType", load.getLoadingType()); update.set("downloadingType", load.getDownloadingType()); update.set("name", load.getName()); update.set("waitingTime", load.getWaitingTime()); if (load.getHasPhoto()) { update.set("loadPhoto", load.getLoadPhoto()); update.set("hasPhoto", load.getHasPhoto()); }/*from www . j ava 2 s .co m*/ mongoTemplate.updateFirst(q, update, Load.class); }
From source file:com.seajas.search.profiler.service.repository.RepositoryService.java
/** * Create a query given any or all of the provided parameters. * * @param allStates//from w w w . j a v a 2s .c o m * @param collection * @param sourceId * @param taxonomyMatch * @param startDate * @param endDate * @param url * @return Query */ private Query createQuery(final Boolean allStates, final String collection, final Integer sourceId, final String taxonomyMatch, final Date startDate, final Date endDate, final String url, final Map<String, String> parameters) { Query query = new Query(); if (!allStates) query.addCriteria( new Criteria().orOperator(where("currentState").is(CompositeState.CompletedDocument.name()), where("currentState").is(CompositeState.InitialDocument.name()))); if (collection != null) query.addCriteria(where("source.collection").is(collection)); if (sourceId != null) query.addCriteria(where("source.id").is(sourceId)); if (taxonomyMatch != null) query.addCriteria(where("originalContent.hostname").is(taxonomyMatch)); if (startDate != null || endDate != null) { Criteria dateCriteria = where("originalContent.dateSubmitted"); if (startDate != null) dateCriteria = dateCriteria.gte(startDate); if (endDate != null) dateCriteria = dateCriteria.lt(endDate); query.addCriteria(dateCriteria); } if (parameters != null && parameters.size() > 0) for (Map.Entry<String, String> parameter : parameters.entrySet()) { if (parameter.getKey().contains(".") || parameter.getKey().contains("$")) throw new IllegalStateException("Can't add criteria for parameter '" + parameter.getKey() + "' because it contains invalid characters"); query.addCriteria( where("source.resultParameters." + StringEscapeUtils.escapeJavaScript(parameter.getKey())) .is(parameter.getValue())); } if (url != null) query.addCriteria(where("originalContent.uri").is(url)); return query; }
From source file:things.mongo.MongoConnector.java
public Observable<? extends Thing<?>> getChildrenMatchingTypeAndKey(Thing<?> thing, String typeMatcher, String keyMatcher) {/*from w w w.j ava 2 s . c o m*/ Query q = new Query(); String regexType = MatcherUtils.convertGlobToRegex(typeMatcher); String regexKey = MatcherUtils.convertGlobToRegex(keyMatcher); q.addCriteria(Criteria.where("parents").is(thing.getId()).and("thingType").regex(regexType).and("key") .regex(regexKey)); List<Thing> things = mongoTemplate.find(q, Thing.class); return Observable.from(things).map(t -> (Thing<?>) t); }
From source file:things.mongo.MongoConnector.java
@Override public Observable<? extends Thing<?>> findThingsMatchingTypeAndKey(final String type, final String key) { final Timer.Context context = find_matching_timer.time(); try {/*w ww . jav a 2 s .co m*/ Query q = new Query(); String regexType = MatcherUtils.convertGlobToRegex(type); String regexKey = MatcherUtils.convertGlobToRegex(key); q.addCriteria(Criteria.where("thingType").regex(regexType).and("key").regex(regexKey)); List<Thing> things = mongoTemplate.find(q, Thing.class); return Observable.from(things).map(t -> (Thing<?>) t); } finally { context.stop(); } }
From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java
@Override public Long findLaunchesQuantity(String projectId, String mode, Date from) { Query query = query(where(PROJECT_ID_REFERENCE).is(projectId)) .addCriteria(where(STATUS).ne(IN_PROGRESS.name())).addCriteria(where(MODE).is(mode)); if (null != from) { query = query.addCriteria(where(START_TIME).gt(from)); }//from w w w .ja v a 2 s . com return mongoTemplate.count(query, Launch.class); }