org.springframework.data.mongodb.core.query.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(766)

本文整理了Java中org.springframework.data.mongodb.core.query.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Query
类名称:Query

Query介绍

[英]MongoDB Query object representing criteria, projection, sorting and query hints.
[中]MongoDB查询对象,表示条件、投影、排序和查询提示。

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
  3. Assert.notNull(example, "Sample must not be null!");
  4. Assert.notNull(sort, "Sort must not be null!");
  5. Query q = new Query(new Criteria().alike(example)).with(sort);
  6. return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName());
  7. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. public boolean exists(String scriptName) {
  3. Assert.hasText(scriptName, "ScriptName must not be null or empty!");
  4. return mongoOperations.exists(query(where("_id").is(scriptName)), NamedMongoScript.class, SCRIPT_COLLECTION_NAME);
  5. }

代码示例来源:origin: yu199195/myth

  1. @Override
  2. public int remove(final String transId) {
  3. Query query = new Query();
  4. query.addCriteria(new Criteria("transId").is(transId));
  5. template.remove(query, collectionName);
  6. return CommonConstant.SUCCESS;
  7. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. protected Query complete(Criteria criteria, Sort sort) {
  3. Query query = (criteria == null ? new Query() : new Query(criteria)).with(sort);
  4. if (LOG.isDebugEnabled()) {
  5. LOG.debug("Created query " + query);
  6. }
  7. return query;
  8. }

代码示例来源:origin: yu199195/hmily

  1. @Override
  2. public List<HmilyTransaction> listAllByDelay(final Date date) {
  3. Query query = new Query();
  4. query.addCriteria(Criteria.where("lastTime").lt(date));
  5. final List<MongoAdapter> mongoBeans =
  6. template.find(query, MongoAdapter.class, collectionName);
  7. if (CollectionUtils.isNotEmpty(mongoBeans)) {
  8. return mongoBeans.stream().map(this::buildByCache).collect(Collectors.toList());
  9. }
  10. return Collections.emptyList();
  11. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. public Flux<T> findAll(Sort sort) {
  3. Assert.notNull(sort, "Sort must not be null!");
  4. return findAll(new Query().with(sort));
  5. }

代码示例来源:origin: com.bq.oss.lib/mongodb

  1. private boolean doUpdate(Object id, DBObject data, String... fieldsToDelete) {
  2. Assert.notNull(id);
  3. data.removeField("_id");
  4. Update update = new Update();
  5. setField("", data, update);
  6. for (String field : fieldsToDelete) {
  7. update.unset(field);
  8. }
  9. WriteResult result = mongoOperations.updateFirst(Query.query(Criteria.where("_id").is(id)), update,
  10. metadata.getCollectionName());
  11. return result.getN() != 0;
  12. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. public Flux<T> findAllById(Iterable<ID> ids) {
  3. Assert.notNull(ids, "The given Iterable of Id's must not be null!");
  4. return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
  5. .in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
  6. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Nullable
  2. @Override
  3. public <T> T findOne(Query query, Class<T> entityClass, String collectionName) {
  4. Assert.notNull(query, "Query must not be null!");
  5. Assert.notNull(entityClass, "EntityClass must not be null!");
  6. Assert.notNull(collectionName, "CollectionName must not be null!");
  7. if (ObjectUtils.isEmpty(query.getSortObject()) && !query.getCollation().isPresent()) {
  8. return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass);
  9. } else {
  10. query.limit(1);
  11. List<T> results = find(query, entityClass, collectionName);
  12. return results.isEmpty() ? null : results.get(0);
  13. }
  14. }

代码示例来源:origin: spring-projects/spring-data-mongodb

  1. @Override
  2. public Mono<ReactiveGridFsResource> getResource(String location) {
  3. Assert.notNull(location, "Filename must not be null!");
  4. return findOne(query(whereFilename().is(location))).flatMap(this::getResource)
  5. .defaultIfEmpty(ReactiveGridFsResource.absent(location));
  6. }

代码示例来源:origin: spring-projects/spring-integration

  1. /**
  2. * Get the {@code value} for the provided {@code key} performing {@code findOne} MongoDB operation.
  3. * @param key the metadata entry key
  4. * @return the metadata entry value or null if doesn't exist.
  5. * @see MongoTemplate#findOne(Query, Class, String)
  6. */
  7. @Override
  8. public String get(String key) {
  9. Assert.hasText(key, "'key' must not be empty.");
  10. Query query = new Query(Criteria.where(ID_FIELD).is(key));
  11. query.fields().exclude(ID_FIELD);
  12. @SuppressWarnings("unchecked")
  13. Map<String, String> result = this.template.findOne(query, Map.class, this.collectionName);
  14. return result == null ? null : result.get(VALUE);
  15. }

代码示例来源:origin: spring-projects/spring-integration

  1. /**
  2. * Remove the metadata entry for the provided {@code key} and return its {@code value}, if any,
  3. * using {@code findAndRemove} MongoDB operation.
  4. * @param key the metadata entry key
  5. * @return the metadata entry value or null if doesn't exist.
  6. * @see MongoTemplate#findAndRemove(Query, Class, String)
  7. */
  8. @Override
  9. public String remove(String key) {
  10. Assert.hasText(key, "'key' must not be empty.");
  11. Query query = new Query(Criteria.where(ID_FIELD).is(key));
  12. query.fields().exclude(ID_FIELD);
  13. @SuppressWarnings("unchecked")
  14. Map<String, String> result = this.template.findAndRemove(query, Map.class, this.collectionName);
  15. return result == null ? null : result.get(VALUE);
  16. }

代码示例来源:origin: spring-projects/spring-integration

  1. /**
  2. * If the specified key is not already associated with a value, associate it with the given value.
  3. * This is equivalent to
  4. * <pre> {@code
  5. * if (!map.containsKey(key))
  6. * return map.put(key, value);
  7. * else
  8. * return map.get(key);
  9. * }</pre>
  10. * except that the action is performed atomically.
  11. * <p>
  12. * @param key the metadata entry key
  13. * @param value the metadata entry value to store
  14. * @return null if successful, the old value otherwise.
  15. * @see java.util.concurrent.ConcurrentMap#putIfAbsent(Object, Object)
  16. */
  17. @Override
  18. public String putIfAbsent(String key, String value) {
  19. Assert.hasText(key, "'key' must not be empty.");
  20. Assert.hasText(value, "'value' must not be empty.");
  21. Query query = new Query(Criteria.where(ID_FIELD).is(key));
  22. query.fields().exclude(ID_FIELD);
  23. @SuppressWarnings("unchecked")
  24. Map<String, String> result = this.template.findAndModify(query, new Update().setOnInsert(VALUE, value),
  25. new FindAndModifyOptions().upsert(true), Map.class, this.collectionName);
  26. return result == null ? null : result.get(VALUE);
  27. }

代码示例来源:origin: yu199195/hmily

  1. final PageParameter pageParameter = query.getPageParameter();
  2. final int pageSize = pageParameter.getPageSize();
  3. Query baseQuery = new Query();
  4. if (StringUtils.isNoneBlank(query.getTransId())) {
  5. baseQuery.addCriteria(new Criteria("transId").is(query.getTransId()));
  6. baseQuery.addCriteria(new Criteria("retriedCount").lt(query.getRetry()));
  7. final long totalCount = mongoTemplate.count(baseQuery, mongoTableName);
  8. if (totalCount <= 0) {
  9. return voCommonPager;
  10. int start = (currentPage - 1) * pageSize;
  11. voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), (int) totalCount));
  12. baseQuery.skip(start).limit(pageSize);
  13. final List<MongoAdapter> mongoAdapters =
  14. mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);
  15. if (CollectionUtils.isNotEmpty(mongoAdapters)) {
  16. final List<HmilyCompensationVO> recoverVOS =

代码示例来源:origin: kaaproject/kaa

  1. @Override
  2. public MongoEndpointProfile findEndpointIdByKeyHash(byte[] endpointKeyHash) {
  3. LOG.debug("Get count of endpoint profiles by endpoint key hash [{}] ", endpointKeyHash);
  4. Query query = query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
  5. query.fields().include(ID);
  6. return findOne(query);
  7. }

代码示例来源:origin: kaaproject/kaa

  1. @Override
  2. public MongoEndpointProfile findByKeyHash(byte[] endpointKeyHash) {
  3. LOG.debug("Find endpoint profile by endpoint key hash [{}] ", endpointKeyHash);
  4. DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH)
  5. .is(endpointKeyHash))
  6. .getQueryObject();
  7. DBObject result = mongoTemplate.getDb()
  8. .getCollection(getCollectionName())
  9. .findOne(dbObject);
  10. return mongoTemplate.getConverter().read(getDocumentClass(), result);
  11. }

代码示例来源:origin: kaaproject/kaa

  1. @Override
  2. public void removeNotificationsByKeyHash(final byte[] keyHash) {
  3. LOG.debug("Remove unicast notifications by endpoint key hash [{}] ", keyHash);
  4. mongoTemplate.remove(query(where(EP_ENDPOINT_KEY_HASH).is(keyHash)), getCollectionName());
  5. }

代码示例来源:origin: yu199195/hmily

  1. @Override
  2. public HmilyTransaction findById(final String id) {
  3. Query query = new Query();
  4. query.addCriteria(new Criteria("transId").is(id));
  5. MongoAdapter cache = template.findOne(query, MongoAdapter.class, collectionName);
  6. return buildByCache(Objects.requireNonNull(cache));
  7. }

代码示例来源:origin: yu199195/hmily

  1. @Override
  2. public int updateStatus(final String id, final Integer status) {
  3. Query query = new Query();
  4. query.addCriteria(new Criteria("transId").is(id));
  5. Update update = new Update();
  6. update.set("status", status);
  7. final UpdateResult updateResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
  8. if (updateResult.getModifiedCount() <= 0) {
  9. throw new HmilyRuntimeException("update data exception!");
  10. }
  11. return ROWS;
  12. }

代码示例来源:origin: roncoo/spring-boot-demo

  1. public void deleteById(int id) {
  2. Criteria criteria = Criteria.where("id").in(id);
  3. Query query = new Query(criteria);
  4. mongoTemplate.remove(query, RoncooUser.class);
  5. }

相关文章