List of usage examples for org.springframework.data.mongodb.core.query Query Query
public Query(CriteriaDefinition criteriaDefinition)
From source file:eu.trentorise.game.managers.DBPlayerManager.java
private StatePersistence persist(String gameId, String playerId, List<GenericObjectPersistence> concepts, CustomData customData, Map<String, Object> metadata) { if (StringUtils.isBlank(gameId) || StringUtils.isBlank(playerId)) { throw new IllegalArgumentException("field gameId and playerId of PlayerState MUST be set"); }/*from ww w . j a va 2 s.c o m*/ Criteria criteria = new Criteria(); criteria = criteria.and("gameId").is(gameId).and("playerId").is(playerId); Query query = new Query(criteria); Update update = new Update(); if (concepts != null) { update.set("concepts", concepts); } if (customData != null) { update.set("customData", customData); } if (metadata != null) { update.set("metadata", metadata); } FindAndModifyOptions options = new FindAndModifyOptions(); options.upsert(true); options.returnNew(true); return mongoTemplate.findAndModify(query, update, options, StatePersistence.class); }
From source file:demo.SpringTest.java
@Test public void testStackOverflowBecauseOfCyclicRelationBetweenDocumentsDbRefRelated() { EagerFrom three = new EagerFrom("three"); EagerTo four = new EagerTo("four"); template.save(three);/* ww w . ja v a 2s.c o m*/ template.save(four); three.refToFour = four; four.refToThree = three; template.save(three); template.save(four); EagerFrom foundThree = template.findOne(Query.query(Criteria.where("id").is(three.id)), EagerFrom.class); Assert.assertThat(foundThree.refToFour, Matchers.notNullValue()); Assert.assertThat(foundThree.refToFour, IsInstanceOf.instanceOf(EagerTo.class)); Assert.assertThat(foundThree.refToFour.id, Matchers.is("four")); Assert.assertThat(foundThree.refToFour.refToThree, IsInstanceOf.instanceOf(EagerFrom.class)); Assert.assertThat(foundThree.refToFour.refToThree.id, Matchers.is("three")); EagerTo foundFour = template.findOne(Query.query(Criteria.where("id").is(four.id)), EagerTo.class); Assert.assertThat(foundFour.refToThree, Matchers.notNullValue()); Assert.assertThat(foundFour.refToThree, IsInstanceOf.instanceOf(EagerFrom.class)); Assert.assertThat(foundFour.refToThree.id, Matchers.is("three")); Assert.assertThat(foundFour.refToThree.refToFour, IsInstanceOf.instanceOf(EagerTo.class)); Assert.assertThat(foundFour.refToThree.refToFour.id, Matchers.is("four")); }
From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java
/** * deletes a {@link UserAccount}/*from w w w. ja v a2 s.com*/ * * @param id * id of the user storage account to delete */ public void delete(String id) { db.remove(Query.query(new Criteria("id").is(id)), UserAccount.class); }
From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java
@Override public int updateEducation(Education education, String consultantId) { Query query = new Query( where(ID).is(consultantId).and(EDUCATIONS + "." + Fields.UNDERSCORE_ID).is(education.getId())); Update update = new Update().set(EDUCATIONS + ".$", education); return updateConsultant(query, update).getN(); }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
@Override public ResponseDo register(User user, JSONObject json) throws ApiException { LOG.debug("Save register data begin, first check user is exist or not with phone:{}", user.getPhone()); User phoneUser = userDao.findOne(Query.query(Criteria.where("phone").is(user.getPhone()))); if (phoneUser != null) { LOG.warn("Phone number already register by other user, phone:{}", user.getPhone()); throw new ApiException("?"); }/*from ww w. ja v a 2s . c om*/ // user.setRegisterTime(DateUtil.getTime()); user.setRole(Constants.UserCatalog.COMMON); user.setPhotoAuthStatus(Constants.AuthStatus.UNAUTHORIZED); user.setLicenseAuthStatus(Constants.AuthStatus.UNAUTHORIZED); userDao.save(user); // uploadAvatarToRemoteServer(user); // LOG.debug("Register emchat user by call remote service"); Map<String, String> chatUser = new HashMap<>(2, 1); chatUser.put("username", chatCommonService.getUsernameByUserid(user.getUserId())); chatUser.put("password", user.getPassword()); JSONObject result = chatThirdService.registerChatUser(chatCommonService.getChatToken(), chatUser); if (result.isEmpty()) { //?? userDao.deleteById(user.getUserId()); LOG.warn("Create emchat user failure"); throw new ApiException("?"); } String emchatName = chatCommonService.getUsernameByUserid(user.getUserId()); userDao.update(Query.query(Criteria.where("userId").is(user.getUserId())), Update.update("emchatName", emchatName)); UserToken userToken = new UserToken(); userToken.setUserId(user.getUserId()); userToken.setToken(CodeGenerator.generatorId()); int tokenOverDays = PropertiesUtil.getProperty("carplay.token.over.date", 7); userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE, tokenOverDays)); userTokenDao.save(userToken); cacheManager.setUserToken(userToken); pushNearbyActivity(user.getUserId(), emchatName, user.getLandmark()); Map<String, Object> map = user.buildFullUserMap(); user.appendCompute(map, photoDao.getUserAlbumCount(user.getUserId())); user.appendToken(map, userToken.getToken()); return ResponseDo.buildSuccessResponse(map); }
From source file:com.appleframework.monitor.service.AlertService.java
public void removeAlerts(String projectName) { mongoTemplate.remove(Query.query(Criteria.where("projectName").is(projectName)), collectionName); }
From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java
@Override public int removeEducation(String consultantId, String educationId) { Query query = new Query( where(ID).is(consultantId).and(EDUCATIONS + "." + Fields.UNDERSCORE_ID).is(educationId)); Update update = new Update().pull(EDUCATIONS, findEducation(consultantId, educationId)); return updateConsultant(query, update).getN(); }
From source file:com.comcast.video.dawg.service.house.MongoHouseService.java
@Override public Map<String, Object>[] getStbsById(String... id) { Criteria c = new Criteria(MetaStb.ID).in(Arrays.asList(id)); List<PersistableDevice> list = template.find(new Query(c), PersistableDevice.class, COLLECTION_NAME); return toArray(list); }
From source file:net.cit.tetrad.resource.SubResource.java
/** * ? /* www .ja va2 s . com*/ * @param dto * @return * @throws Exception */ @RequestMapping("/subShardInfoView.do") public ModelAndView subShardInfoView(CommonDto dto) throws Exception { log.debug("start - subShardInfoView()"); ModelAndView mav = commMav(); List<Object> deviceLst = monadService .getList(new Query(where(DEVICE_TYPE).is(StringUtils.getEncStr(PROCESS_MONGOS))), Device.class); Device device = new Device(); if (dto.getDeviceCode() == 0 && deviceLst.size() != 0) { device = (Device) deviceLst.get(0); dto.setDeviceCode(device.getIdx()); dto.setAutoRefresh("off"); } mav.addObject("deviceLst", deviceLst); mav.addObject("comm", dto); mav.setViewName("subShardInfoPage"); log.debug("end - subShardInfoView()"); return mav; }
From source file:br.com.ezequieljuliano.argos.persistence.LoggerDAO.java
private List<Logger> findByTermsAndCriteria(List<UserTerm> terms, Criteria criteria, long limit) { List<Logger> loggers = new ArrayList<Logger>(); if (!terms.isEmpty()) { String searchString = ""; for (UserTerm userTerm : terms) { if (userTerm.getTerm() == Term.fullText) { searchString = searchString + userTerm.getValue() + " "; } else { switch (userTerm.getFilterMatchMode()) { case contains: if (userTerm.getLogicalOperator() == LogicalOperator.orOperator) { criteria.orOperator( Criteria.where(userTerm.getTerm().getField()).regex(userTerm.getValue(), "i")); } else { criteria.and(userTerm.getTerm().getField()).regex(userTerm.getValue(), "i"); }/*from w w w . j a va 2 s . c o m*/ break; case startsWith: if (userTerm.getLogicalOperator() == LogicalOperator.orOperator) { criteria.orOperator(Criteria.where(userTerm.getTerm().getField()) .regex('^' + userTerm.getValue(), "i")); } else { criteria.and(userTerm.getTerm().getField()).regex('^' + userTerm.getValue(), "i"); } break; case equal: if (userTerm.getLogicalOperator() == LogicalOperator.orOperator) { if (userTerm.getTerm().isObjId()) { criteria.orOperator(Criteria.where(userTerm.getTerm().getField()) .is(new ObjectId(userTerm.getValue()))); } else { criteria.orOperator( Criteria.where(userTerm.getTerm().getField()).is(userTerm.getValue())); } } else { if (userTerm.getTerm().isObjId()) { criteria.and(userTerm.getTerm().getField()).is(new ObjectId(userTerm.getValue())); } else { criteria.and(userTerm.getTerm().getField()).is(userTerm.getValue()); } } break; case endsWith: if (userTerm.getLogicalOperator() == LogicalOperator.orOperator) { criteria.orOperator(Criteria.where(userTerm.getTerm().getField()) .regex(userTerm.getValue() + '$', "i")); } else { criteria.and(userTerm.getTerm().getField()).regex(userTerm.getValue() + '$', "i"); } break; } } } if (Strings.isEmpty(searchString)) { loggers = getMongoOperations().find(Query.query(criteria).limit((int) limit), Logger.class); } else { loggers = findByFullText(Logger.COLLECTION_NAME, searchString, criteria, limit); } } return loggers; }