List of usage examples for org.springframework.data.mongodb.core.query Criteria where
public static Criteria where(String key)
From source file:com.comcast.video.dawg.service.park.MongoParkService.java
/** * {@inheritDoc}/*www . j a v a 2s . co m*/ */ @Override public DawgModel getModelById(String modelName) { Query query = new Query(Criteria.where("name").is(modelName)); List<DawgModel> models = template.find(query, DawgModel.class, DawgModel.class.getSimpleName()); return models.isEmpty() ? null : models.get(0); }
From source file:net.cit.tetrad.utility.QueryUtils.java
public static Query setAlarmCode(int alarmCode) { Query query = new Query(); if (alarmCode != 0) query.addCriteria(Criteria.where("alarmCode").is(alarmCode)); return query; }
From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java
public void deleteExtendedProfile(String userId, String profileId) throws DataException { Criteria criteria = new Criteria(); criteria = Criteria.where("content.userId").is(userId).and("content.profileId").is(profileId); criteria.and("type").is(ExtendedProfile.class.getCanonicalName()); criteria.and("deleted").is(false); List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class); if (!profiles.isEmpty()) { deleteObject(profiles.get(0));/*from www .java2s .c o m*/ } }
From source file:edu.upf.nets.mercury.dao.GeoIpDatabase.java
public boolean load() { //Go to mongo to find the last maxmind file. Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1);/* w w w. j ava 2 s.c o m*/ Query query = new Query(); query.with(new Sort(Sort.Direction.DESC, "timestamp")); query.addCriteria(Criteria.where("timestamp").gt(cal.getTime())); GeoIpData geoIpData = mongoTemplate.findOne(query, GeoIpData.class); // If there is no data, return false. if (null == geoIpData) return false; // Save data to temporary file and load the new service. try { this.process(geoIpData.getData()); return true; } catch (IOException e) { return false; } }
From source file:example.springdata.mongodb.people.ReactiveMongoTemplateIntegrationTest.java
/** * Note that the all object conversions are performed before the results are printed to the console. *//*from w w w . j a va 2s . co m*/ @Test public void convertReactorTypesToRxJava2() throws Exception { Flux<Person> flux = template.find(Query.query(Criteria.where("lastname").is("White")), Person.class); long count = RxReactiveStreams.toObservable(flux).count().toSingle().toBlocking().value(); assertThat(count).isEqualTo(2); }
From source file:org.openinfinity.tagcloud.domain.repository.TargetRepositoryMongoDBImpl.java
@Override public Collection<Target> loadByTag(Tag tag) { Query query = new Query(Criteria.where("tags").elemMatch(Criteria.where("text").is(tag.getText()))); return mongoTemplate.find(query, Target.class); }
From source file:org.ingini.mongodb.spring.example.read.TestFindOne.java
@Test public void shouldFindOneArrayElement() { //GIVEN/*from w w w. ja v a 2 s.co m*/ CollectionManager.cleanAndFill(mongoTemplate.getDb(), "characters.json", HumanCharacter.COLLECTION_NAME); //WHEN Hero hero = mongoTemplate.findOne(new BasicQuery( Query.query(Criteria.where("_id").is(new ObjectId("52516b563004ba6b745e864f"))).getQueryObject(), Query.query(Criteria.where("children") .elemMatch(Criteria.where("first_name").is("Sansa").and("last_name").is("Stark"))) .getFieldsObject()), Hero.class); //THEN assertThat(hero).isNotNull(); assertThat(hero.getFirstName()).isEqualTo("Eddard"); }
From source file:org.maodian.flyingcat.im.repository.AccountRepositoryImpl.java
@Override public SimpleUser getSpecificContact(String uid, String targetUid) { String kContId = Account.CONTACTS + "." + SimpleUser.USERNAME; Query query = Query.query(Criteria.where(Account.USERNAME).is(uid).and(kContId).is(targetUid)); query.fields().include(Account.CONTACTS + ".$").exclude("_id"); Account account = getMongoTemplate().findOne(query, Account.class); return account == null ? null : account.getContactList().get(0); }
From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java
@SuppressWarnings("unchecked") @Override/* w ww . j av a2s .c o m*/ public List<T> findOnlyOwnedEntities(Set<String> ids, String owner) { if (owner == null) { return new ArrayList<>(); } Query query = ShareableRepositoryUtils.createOwnedEntityQuery(owner); if (Preconditions.NOT_EMPTY_COLLECTION.test(ids)) { query.addCriteria(Criteria.where(Shareable.ID).in(ids)); } Class<T> entityType = getEntityInformation().getJavaType(); return getMongoOperations().find(query, entityType); }
From source file:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.ValuesRepositoryImpl.java
@Override public void insertOrUpdate(SensorDataset value) throws DaoException { Update update = new Update(); Query existingQuery = new Query(new Criteria("timestamp").is(value.getTimestamp())); if (mongoOperation.exists(existingQuery, SensorDataset.class, collectionName)) { TreeMap<Integer, MinuteValues> minuteValues = value.getValues(); for (Integer minuteTs : minuteValues.keySet()) { Query existingMinute = new Query( new Criteria().andOperator(Criteria.where("timestamp").is(value.getTimestamp()), Criteria.where("values." + minuteTs))); MinuteValues minute;// ww w. j a va 2s.c om if (mongoOperation.exists(existingMinute, MinuteValues.class, collectionName)) { minute = mongoOperation.findOne(existingMinute, MinuteValues.class, collectionName); minute.merge(minuteValues.get(minuteTs)); } else { minute = minuteValues.get(minuteTs); } update.set("values." + minuteTs, minute); } mongoOperation.updateFirst(existingQuery, update, collectionName); } else { mongoOperation.save(value, collectionName); } }