Java Code Examples for org.springframework.data.mongodb.core.query.Query#addCriteria()
The following examples show how to use
org.springframework.data.mongodb.core.query.Query#addCriteria() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlackListServiceImpl.java From FEBS-Cloud with Apache License 2.0 | 7 votes |
private Query getQuery(BlackList blackList) { Query query = new Query(); Criteria criteria = new Criteria(); if (StringUtils.isNotBlank(blackList.getIp())) { criteria.and("ip").is(blackList.getIp()); } if (StringUtils.isNotBlank(blackList.getRequestUri())) { criteria.and("requestUri").is(blackList.getRequestUri()); } if (StringUtils.isNotBlank(blackList.getRequestMethod())) { criteria.and("requestMethod").is(blackList.getRequestMethod()); } if (StringUtils.isNotBlank(blackList.getStatus())) { criteria.and("status").is(blackList.getStatus()); } query.addCriteria(criteria); return query; }
Example 2
Source File: RouteLogServiceImpl.java From FEBS-Cloud with Apache License 2.0 | 7 votes |
private Query getQuery(RouteLog routeLog) { Query query = new Query(); Criteria criteria = new Criteria(); if (StringUtils.isNotBlank(routeLog.getIp())) { criteria.and("ip").is(routeLog.getIp()); } if (StringUtils.isNotBlank(routeLog.getTargetServer())) { criteria.and("targetServer").is(routeLog.getTargetServer()); } if (StringUtils.isNotBlank(routeLog.getRequestMethod())) { criteria.and("requestMethod").is(routeLog.getRequestMethod().toUpperCase()); } if (StringUtils.isNotBlank(routeLog.getCreateTimeFrom()) && StringUtils.isNotBlank(routeLog.getCreateTimeTo())) { criteria.andOperator( Criteria.where("createTime").gt(routeLog.getCreateTimeFrom()), Criteria.where("createTime").lt(routeLog.getCreateTimeTo()) ); } query.addCriteria(criteria); return query; }
Example 3
Source File: BaseItemServiceImpl.java From Lottor with MIT License | 6 votes |
@Override public int updateItem(BaseItem baseItem) { Query query = new Query(); query.addCriteria(new Criteria("type").is(baseItem.getType()).and("itemId").is(baseItem.getItemId())); BaseItem item = mongoTemplate.findOne(query, BaseItem.class, CollectionNameEnum.BaseItem.name()); if (Objects.isNull(item)) { baseItem.setHealthyState(false); baseItem.setRetryCount(1); baseItem.setLastModified(System.currentTimeMillis()); mongoTemplate.save(baseItem, collectionName); return baseItem.getRetryCount(); } int count = item.getRetryCount(); Update update = Update.update("retryCount", count + 1); update.set("lastModified", System.currentTimeMillis()); if (count < 1) { update.set("healthyState", false); } mongoTemplate.updateFirst(query, update, BaseItem.class, collectionName); return count + 1; }
Example 4
Source File: EventMongoDBDaoImpl.java From chronus with Apache License 2.0 | 6 votes |
@Override public List<EventEntity> getLastEvent(String cluster, String address, String version) { Query query = new Query(); query.addCriteria(Criteria.where("cluster").is(cluster)); query.addCriteria(Criteria.where("address").is(address)); query.addCriteria(Criteria.where("version").is(version)); query.with(new Sort(Sort.Direction.DESC, "dateCreated")); query.limit(3); return super.selectList(query); }
Example 5
Source File: MongoRecoverTransactionServiceImpl.java From Raincat with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Boolean updateRetry(final String id, final Integer retry, final String applicationName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(applicationName) || Objects.isNull(retry)) { return Boolean.FALSE; } final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName); Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); Update update = new Update(); update.set("lastTime", DateUtils.getCurrentDateTime()); update.set("retriedCount", retry); final WriteResult writeResult = mongoTemplate.updateFirst(query, update, MongoAdapter.class, mongoTableName); if (writeResult.getN() <= 0) { throw new TransactionRuntimeException("更新数据异常!"); } return Boolean.TRUE; }
Example 6
Source File: ArticleRepositoryImpl.java From jakduk-api with MIT License | 6 votes |
/** * 글 보기에서 앞 글, 뒷 글의 정보를 가져온다. */ @Override public ArticleSimple findByIdAndCategoryWithOperator(ObjectId id, String category, Constants.CRITERIA_OPERATOR operator) { Query query = new Query(); if (StringUtils.isNotBlank(category)) query.addCriteria(Criteria.where("category").is(category)); switch (operator) { case GT: query.addCriteria(Criteria.where("_id").gt(id)); query.with(new Sort(Sort.Direction.ASC, "_id")); break; case LT: query.addCriteria(Criteria.where("_id").lt(id)); query.with(new Sort(Sort.Direction.DESC, "_id")); break; } return mongoTemplate.findOne(query, ArticleSimple.class); }
Example 7
Source File: TaskRuntimeMongoDBDaoImpl.java From chronus with Apache License 2.0 | 6 votes |
@Override public void updateTaskRuntimeHeartBeatTime(TaskRuntimeEntity taskRuntimeEntity) { Query query = new Query(); query.addCriteria(Criteria.where("cluster").is(taskRuntimeEntity.getCluster())); query.addCriteria(Criteria.where("taskName").is(taskRuntimeEntity.getTaskName())); query.addCriteria(Criteria.where("seqNo").is(taskRuntimeEntity.getSeqNo())); Update update = new Update(); update.set("address", taskRuntimeEntity.getAddress()); update.set("hostName", taskRuntimeEntity.getHostName()); update.set("heartBeatTime", taskRuntimeEntity.getHeartBeatTime()); update.set("registerTime", taskRuntimeEntity.getRegisterTime()); update.set("nextRunStartTime", taskRuntimeEntity.getNextRunStartTime()); update.set("nextRunEndTime", taskRuntimeEntity.getNextRunEndTime()); update.set("lastFetchDataTime", taskRuntimeEntity.getLastFetchDataTime()); update.set("state", taskRuntimeEntity.getState()); update.set("taskItems", taskRuntimeEntity.getTaskItems()); update.set("message", taskRuntimeEntity.getMessage()); super.updateFirst(query, update); }
Example 8
Source File: MongoDataPointRepositoryImpl.java From omh-dsu-ri with Apache License 2.0 | 5 votes |
void addCreationTimestampCriteria(Query query, Range<OffsetDateTime> timestampRange) { if (timestampRange.hasLowerBound() || timestampRange.hasUpperBound()) { Criteria timestampCriteria = where("header.creation_date_time"); if (timestampRange.hasLowerBound()) { if (timestampRange.lowerBoundType() == CLOSED) { timestampCriteria = timestampCriteria.gte(timestampRange.lowerEndpoint()); } else { timestampCriteria = timestampCriteria.gt(timestampRange.lowerEndpoint()); } } if (timestampRange.hasUpperBound()) { if (timestampRange.upperBoundType() == CLOSED) { timestampCriteria = timestampCriteria.lte(timestampRange.upperEndpoint()); } else { timestampCriteria = timestampCriteria.lt(timestampRange.upperEndpoint()); } } query.addCriteria(timestampCriteria); } }
Example 9
Source File: PersonService.java From acelera-dev-brasil-2019-01 with Apache License 2.0 | 5 votes |
public List<Person> buscar(Filtro filtro) { Query query = new Query(); // if (filtro.isTemFoto()) { // query.addCriteria(Criteria.where("foto").ne(null)); // } else { // query.addCriteria(Criteria.where("foto").is(null)); // } query.addCriteria(Criteria.where("nome").is(filtro.getNome())); query.addCriteria(Criteria.where("altura").lte(filtro.getAltura())); return template.find(query, Person.class); }
Example 10
Source File: Denormalizer.java From secure-data-service with Apache License 2.0 | 5 votes |
private DBObject buildPullObject(List<Entity> entities) { Query pullQuery = new Query(); List <Criteria> orList = new ArrayList<Criteria>(); for (Entity entity : entities) { String internalId = null; if (denormalizedIdKey.equals("_id")) { internalId = entity.getEntityId(); } else { internalId = (String) entity.getBody().get(denormalizedIdKey); } //delete studentSectionAssociation DND where (sectionId(_id) = "x1" and beginDate(denormalizedKey) = "y1") OR (sectionId(_id) = "x2" and beginDate(denormalizedKey) = "y2") ... //delete studentSchoolAssociation DND where (schoolld(_id) = "x1" and entryDate(denormalizedKey) = "y1") OR (schoolld(_id) = "x2" and entryDate(denormalizedKey) = "y2") ... //DND -> denormalizedDoc List<Criteria> andList = new ArrayList<Criteria>(); andList.add(Criteria.where("_id").is(internalId)); for(String denormalizedKey:denormalizedEntityKeys) { String denormalizedValue = (String) entity.getBody().get(denormalizedKey); andList.add( Criteria.where(denormalizedKey).is(denormalizedValue)); } Criteria and = new Criteria().andOperator(andList.toArray(new Criteria[0])); orList.add(and); } Criteria or = new Criteria().orOperator(orList.toArray(new Criteria[0])); pullQuery.addCriteria(or); Update update = new Update(); update.pull(denormalizedToField, pullQuery.getQueryObject()); return update.getUpdateObject(); }
Example 11
Source File: MongoTransactionOperateRepository.java From Lottor with MIT License | 5 votes |
/** * 根据id获取对象 * * @param id 主键id * @return TransactionRecover */ @Override public TransactionRecover findById(String id) { Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName); return buildByCache(cache); }
Example 12
Source File: MongoCoordinatorRepository.java From hmily with Apache License 2.0 | 5 votes |
@Override public List<HmilyTransaction> listAllByDelay(final Date date) { Query query = new Query(); query.addCriteria(Criteria.where("lastTime").lt(date)); final List<MongoAdapter> mongoBeans = template.find(query, MongoAdapter.class, collectionName); if (CollectionUtils.isNotEmpty(mongoBeans)) { return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList()); } return Collections.emptyList(); }
Example 13
Source File: SystemGroupMongoDBDaoImpl.java From chronus with Apache License 2.0 | 5 votes |
@Override public SystemGroupEntity selectByGroupName(String groupName, String sysCode) { Query query = new Query(); query.addCriteria(Criteria.where("groupName").is(groupName)); query.addCriteria(Criteria.where("sysCode").is(sysCode)); SystemGroupEntity systemGroupEntity = super.selectOne(query); return systemGroupEntity; }
Example 14
Source File: SubDocAccessor.java From secure-data-service with Apache License 2.0 | 5 votes |
private DBObject getParentQuery(Map<String, Object> body) { Query parentQuery = new Query(); for (Entry<String, String> entry : lookup.entrySet()) { parentQuery.addCriteria(new Criteria(entry.getValue()).is(body.get(entry.getKey()))); } return parentQuery.getQueryObject(); }
Example 15
Source File: TxManagerServiceImpl.java From Lottor with MIT License | 5 votes |
/** * 根据事务组id 获取所有的子项目 * * @param txGroupId 事务组id * @return List<TxTransactionItem> */ @Override public List<TxTransactionItem> listByTxGroupId(String txGroupId) { Query query = new Query(); query.addCriteria(new Criteria("txGroupId").is(txGroupId)); List<TxTransactionItem> items = mongoTemplate.find(query, TxTransactionItem.class, CollectionNameEnum.TxTransactionItem.name()); return new ArrayList<>(items); }
Example 16
Source File: RouteUserServiceImpl.java From FEBS-Cloud with Apache License 2.0 | 5 votes |
private Query getQuery(RouteUser routeUser) { Query query = new Query(); Criteria criteria = new Criteria(); if (StringUtils.isNotBlank(routeUser.getUsername())) { criteria.and("username").is(routeUser.getUsername()); } query.addCriteria(criteria); return query; }
Example 17
Source File: JobExecLogMongoDBDaoImpl.java From chronus with Apache License 2.0 | 4 votes |
@Override public PageResult<JobExecLogEntity> findAllByPage(JobExecLogEntity jobExecLogEntity) { Map<String, String> param = new HashMap<>(3); if (StringUtils.isNotBlank(jobExecLogEntity.getCluster())) { param.put("cluster", jobExecLogEntity.getCluster()); } if (StringUtils.isNotBlank(jobExecLogEntity.getSysCode())) { param.put("sysCode", jobExecLogEntity.getSysCode()); } if (StringUtils.isNotBlank(jobExecLogEntity.getTaskName())) { param.put("taskName", jobExecLogEntity.getTaskName()); } int page = jobExecLogEntity.getPageNum() - 1; PageQueryParams pageQueryParams = new PageQueryParams(page, jobExecLogEntity.getPageSize()); Query query = getWhereParamsByRequest(param); if (jobExecLogEntity.getStartDate() != null) { //使用调度的开始时间判断 Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.setTime(jobExecLogEntity.getStartDate()); Date startDate = calendar.getTime(); if (jobExecLogEntity.getEndDate() != null) { calendar.setTime(jobExecLogEntity.getEndDate()); Date endDate = calendar.getTime(); query.addCriteria(Criteria.where("startDate").gte(startDate).andOperator(Criteria.where("startDate").lte(endDate))); } else { query.addCriteria(Criteria.where("startDate").gte(startDate)); } } Long count = this.countByQuery(query); query.with(new Sort(Sort.Direction.DESC, "startDate")); final PageResult<JobExecLogEntity> pageResult = new PageResult<>(); pageResult.setTotal(count); pageResult.setPageSize(jobExecLogEntity.getPageSize()); pageResult.setPageNum(page); pageResult.setList(this.selectByQuery(query, pageQueryParams)); return pageResult; }
Example 18
Source File: ClusterMongoDBDaoImpl.java From chronus with Apache License 2.0 | 4 votes |
@Override public void delete(String cluster) { Query query = new Query(); query.addCriteria(Criteria.where("cluster").is(cluster)); super.delete(query); }
Example 19
Source File: TaskMongoDBDaoImpl.java From chronus with Apache License 2.0 | 4 votes |
@Override public TaskEntity selectById(String id) { Query query = new Query(); query.addCriteria(Criteria.where("_id").is(id)); return super.selectOne(query); }
Example 20
Source File: SimpleMongoRepository.java From secure-data-service with Apache License 2.0 | 3 votes |
public void delete(String principle, String collectionName, String uuid) throws ModelException { // log.info("Deleting Entity With Id: " + uuid); // Convert UUID to Mongo ID Object mongoId = (new MongoIdConverter()).toDatabaseId(uuid); Query query = new Query(); Criteria criteria = Criteria.where("_id").is(mongoId); query.addCriteria(criteria); this.getMongoTemplate().remove(query, collectionName); }