org.springframework.data.mongodb.core.query.Query.fields()方法的使用及代码示例

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

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

Query.fields介绍

暂无

代码示例

代码示例来源: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. private Long findVersionByKey(byte[] endpointKeyHash) {
  2. LOG.debug("Find endpoint profile version by key hash [{}] ", endpointKeyHash);
  3. Long version = null;
  4. Query query = query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
  5. query.fields().include(OPT_LOCK);
  6. DBObject result = mongoTemplate.getDb()
  7. .getCollection(getCollectionName())
  8. .findOne(query.getQueryObject());
  9. if (result != null) {
  10. version = (Long) result.get(OPT_LOCK);
  11. }
  12. return version;
  13. }

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

  1. Field fields = query.fields();

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

  1. @Override
  2. protected Query createQuery(ConvertingParameterAccessor accessor) {
  3. MongoQueryCreator creator = new MongoQueryCreator(tree, accessor, context, isGeoNearQuery);
  4. Query query = creator.createQuery();
  5. if (tree.isLimiting()) {
  6. query.limit(tree.getMaxResults());
  7. }
  8. TextCriteria textCriteria = accessor.getFullText();
  9. if (textCriteria != null) {
  10. query.addCriteria(textCriteria);
  11. }
  12. String fieldSpec = getQueryMethod().getFieldSpecification();
  13. if (!StringUtils.hasText(fieldSpec)) {
  14. ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
  15. if (returnedType.isProjecting()) {
  16. returnedType.getInputProperties().forEach(query.fields()::include);
  17. }
  18. return query;
  19. }
  20. try {
  21. BasicQuery result = new BasicQuery(query.getQueryObject(), Document.parse(fieldSpec));
  22. result.setSortObject(query.getSortObject());
  23. return result;
  24. } catch (JSONParseException o_O) {
  25. throw new IllegalStateException(String.format("Invalid query or field specification in %s!", getQueryMethod()),
  26. o_O);
  27. }
  28. }

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

  1. .is(pageLink.getEndpointGroupId())));
  2. query.skip(offs).limit(lim + 1);
  3. query.fields()
  4. .include(DaoConstants.PROFILE)
  5. .include(EP_SERVER_PROFILE_PROPERTY)

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

  1. @Override
  2. public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) {
  3. LOG.debug("Find endpoint profile body by endpoint key hash [{}] ", endpointKeyHash);
  4. EndpointProfileBodyDto endpointProfileBodyDto = null;
  5. Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
  6. query.fields()
  7. .include(DaoConstants.PROFILE)
  8. .include(EP_SERVER_PROFILE_PROPERTY)
  9. .include(EP_APPLICATION_ID)
  10. .include(EP_PROFILE_VERSION)
  11. .include(EP_SERVER_PROFILE_VERSION_PROPERTY)
  12. .include(EP_USE_RAW_SCHEMA);
  13. EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto();
  14. if (pf != null) {
  15. endpointProfileBodyDto = new EndpointProfileBodyDto(
  16. endpointKeyHash,
  17. pf.getClientProfileBody(),
  18. pf.getServerProfileBody(),
  19. pf.getClientProfileVersion(),
  20. pf.getServerProfileVersion(),
  21. pf.getApplicationId());
  22. }
  23. LOG.debug("[{}] Found client-side endpoint profile body {} with client-side endpoint "
  24. + "profile version {} and server-side endpoint profile body {} "
  25. + "with server-side endpoint profile version {} and application id {}",
  26. endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(),
  27. pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId());
  28. return endpointProfileBodyDto;
  29. }

代码示例来源: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: spring-projects/spring-integration

  1. private int getNextId() {
  2. Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
  3. query.fields().include(SEQUENCE);
  4. return (Integer) this.template.findAndModify(query,
  5. new Update().inc(SEQUENCE, 1),
  6. FindAndModifyOptions.options().returnNew(true).upsert(true),
  7. Map.class,
  8. this.collectionName).get(SEQUENCE); // NOSONAR - never returns null
  9. }

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

  1. /**
  2. * Perform MongoDB {@code INC} operation for the document, which contains the {@link MessageDocument}
  3. * {@code sequence}, and return the new incremented value for the new {@link MessageDocument}.
  4. * The {@link #SEQUENCE_NAME} document is created on demand.
  5. * @return the next sequence value.
  6. */
  7. protected int getNextId() {
  8. Query query = Query.query(Criteria.where("_id").is(SEQUENCE_NAME));
  9. query.fields().include(MessageDocumentFields.SEQUENCE);
  10. return (Integer) this.mongoTemplate.findAndModify(query,
  11. new Update().inc(MessageDocumentFields.SEQUENCE, 1),
  12. FindAndModifyOptions.options().returnNew(true).upsert(true),
  13. Map.class, this.collectionName)
  14. .get(MessageDocumentFields.SEQUENCE); // NOSONAR - never returns null
  15. }

代码示例来源:origin: org.springframework.data/spring-data-mongodb

  1. @Override
  2. protected Query createQuery(ConvertingParameterAccessor accessor) {
  3. MongoQueryCreator creator = new MongoQueryCreator(tree, accessor, context, isGeoNearQuery);
  4. Query query = creator.createQuery();
  5. if (tree.isLimiting()) {
  6. query.limit(tree.getMaxResults());
  7. }
  8. TextCriteria textCriteria = accessor.getFullText();
  9. if (textCriteria != null) {
  10. query.addCriteria(textCriteria);
  11. }
  12. String fieldSpec = getQueryMethod().getFieldSpecification();
  13. if (!StringUtils.hasText(fieldSpec)) {
  14. ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
  15. if (returnedType.isProjecting()) {
  16. returnedType.getInputProperties().forEach(query.fields()::include);
  17. }
  18. return query;
  19. }
  20. try {
  21. BasicQuery result = new BasicQuery(query.getQueryObject(), Document.parse(fieldSpec));
  22. result.setSortObject(query.getSortObject());
  23. return result;
  24. } catch (JSONParseException o_O) {
  25. throw new IllegalStateException(String.format("Invalid query or field specification in %s!", getQueryMethod()),
  26. o_O);
  27. }
  28. }

代码示例来源:origin: org.springframework.data/spring-data-mongodb

  1. Field fields = query.fields();

代码示例来源:origin: fi.vm.sade.haku/hakemus-api

  1. public List<ApplicationSystem> findAll(String... includeFields) {
  2. log.debug("Find all ApplicationSystems (include fields: {})", Arrays.toString(includeFields));
  3. Query q = new Query();
  4. q.fields().include("name"); // Mandatory field
  5. for (String includeField : includeFields) {
  6. q.fields().include(includeField);
  7. }
  8. List<ApplicationSystem> applicationSystems = mongoOperations.find(q, ApplicationSystem.class);
  9. log.debug("Found {} applicationSystems", applicationSystems.size());
  10. return applicationSystems;
  11. }

代码示例来源:origin: com.epam.reportportal/commons-dao

  1. @Override
  2. public Set<String> findIdsWithNameByLaunchesRef(String name, Set<String> launchRef) {
  3. Query query = query(where(LAUNCH_REFERENCE).in(launchRef)).addCriteria(where(NAME).is(name));
  4. query.fields().include("_id");
  5. return mongoTemplate.find(query, TestItem.class).stream().map(TestItem::getId).collect(toSet());
  6. }

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

  1. public static String findStringFieldById(MongoOperations mongo, String field, String id, String collection) {
  2. Criteria criteria = Criteria.where(FIELD_ID).is(id);
  3. Query query = Query.query(criteria);
  4. query.fields().include(field);
  5. DBObject json = mongo.findOne(query, DBObject.class, collection);
  6. return json == null ? null : json.get(field).toString();
  7. }

代码示例来源:origin: com.bosch.bis.apiregistry/apidocrepo-apidocrepoclient-interface

  1. private static Query createApiDocQuery(String clientId, String apiId) {
  2. Query query = new Query()
  3. .addCriteria(Criteria.where(ApiDocNames.CLIENT_ID).is(clientId))
  4. .addCriteria(Criteria.where(ApiDocNames.API_ID).is(apiId));
  5. query.fields().exclude(ApiDocNames.SWAGGER);
  6. query.fields().exclude(ApiDocNames.BASE_API_DRAFT);
  7. return query;
  8. }
  9. }

代码示例来源:origin: fi.vm.sade.haku/hakemus-api

  1. public List<ApplicationSystem> findAllPublished(String[] includeFields) {
  2. Query q = new Query();
  3. q.addCriteria(new Criteria("state").is("JULKAISTU"));
  4. for (String includeField : includeFields) {
  5. q.fields().include(includeField);
  6. }
  7. return mongoOperations.find(q, ApplicationSystem.class);
  8. }
  9. }

代码示例来源:origin: com.epam.reportportal/commons-dao

  1. @Override
  2. public Page<Launch> findModifiedBefore(String project, Date before,Pageable p) {
  3. Query query = Query.query(Criteria.where(Modifiable.LAST_MODIFIED).lte((before)))
  4. .addCriteria(Criteria.where(PROJECT_ID_REFERENCE).is(project));
  5. query.with(p);
  6. query.fields().include(ID_REFERENCE);
  7. return pageByQuery(query, p, Launch.class);
  8. }

代码示例来源:origin: com.epam.reportportal/commons-dao

  1. @Override
  2. public Stream<Launch> streamModifiedInRange(String project, Date from, Date to) {
  3. Query query = Query.query(Criteria.where(Modifiable.LAST_MODIFIED).gte(from).lte((to)))
  4. .addCriteria(Criteria.where(PROJECT_ID_REFERENCE).is(project));
  5. query.fields().include(ID_REFERENCE);
  6. return Streams.stream(mongoTemplate.stream(query, Launch.class));
  7. }

相关文章