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

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

本文整理了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

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

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

private Long findVersionByKey(byte[] endpointKeyHash) {
 LOG.debug("Find endpoint profile version by key hash [{}] ", endpointKeyHash);
 Long version = null;
 Query query = query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
 query.fields().include(OPT_LOCK);
 DBObject result = mongoTemplate.getDb()
   .getCollection(getCollectionName())
   .findOne(query.getQueryObject());
 if (result != null) {
  version = (Long) result.get(OPT_LOCK);
 }
 return version;
}

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

Field fields = query.fields();

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

@Override
protected Query createQuery(ConvertingParameterAccessor accessor) {
  MongoQueryCreator creator = new MongoQueryCreator(tree, accessor, context, isGeoNearQuery);
  Query query = creator.createQuery();
  if (tree.isLimiting()) {
    query.limit(tree.getMaxResults());
  }
  TextCriteria textCriteria = accessor.getFullText();
  if (textCriteria != null) {
    query.addCriteria(textCriteria);
  }
  String fieldSpec = getQueryMethod().getFieldSpecification();
  if (!StringUtils.hasText(fieldSpec)) {
    ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
    if (returnedType.isProjecting()) {
      returnedType.getInputProperties().forEach(query.fields()::include);
    }
    return query;
  }
  try {
    BasicQuery result = new BasicQuery(query.getQueryObject(), Document.parse(fieldSpec));
    result.setSortObject(query.getSortObject());
    return result;
  } catch (JSONParseException o_O) {
    throw new IllegalStateException(String.format("Invalid query or field specification in %s!", getQueryMethod()),
        o_O);
  }
}

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

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

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

@Override
public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) {
 LOG.debug("Find endpoint profile body by endpoint key hash [{}] ", endpointKeyHash);
 EndpointProfileBodyDto endpointProfileBodyDto = null;
 Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
 query.fields()
   .include(DaoConstants.PROFILE)
   .include(EP_SERVER_PROFILE_PROPERTY)
   .include(EP_APPLICATION_ID)
   .include(EP_PROFILE_VERSION)
   .include(EP_SERVER_PROFILE_VERSION_PROPERTY)
   .include(EP_USE_RAW_SCHEMA);
 EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto();
 if (pf != null) {
  endpointProfileBodyDto = new EndpointProfileBodyDto(
    endpointKeyHash,
    pf.getClientProfileBody(),
    pf.getServerProfileBody(),
    pf.getClientProfileVersion(),
    pf.getServerProfileVersion(),
    pf.getApplicationId());
 }
 LOG.debug("[{}] Found client-side endpoint profile body {} with client-side endpoint "
     + "profile version {} and server-side endpoint profile body {} "
     + "with server-side endpoint profile version {} and application id {}",
   endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(),
   pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId());
 return endpointProfileBodyDto;
}

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

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

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

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

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

/**
 * If the specified key is not already associated with a value, associate it with the given value.
 * This is equivalent to
 * <pre> {@code
 * if (!map.containsKey(key))
 *   return map.put(key, value);
 * else
 *   return map.get(key);
 * }</pre>
 * except that the action is performed atomically.
 * <p>
 * @param key the metadata entry key
 * @param value the metadata entry value to store
 * @return null if successful, the old value otherwise.
 * @see java.util.concurrent.ConcurrentMap#putIfAbsent(Object, Object)
 */
@Override
public String putIfAbsent(String key, String value) {
  Assert.hasText(key, "'key' must not be empty.");
  Assert.hasText(value, "'value' must not be empty.");
  Query query = new Query(Criteria.where(ID_FIELD).is(key));
  query.fields().exclude(ID_FIELD);
  @SuppressWarnings("unchecked")
  Map<String, String> result = this.template.findAndModify(query, new Update().setOnInsert(VALUE, value),
      new FindAndModifyOptions().upsert(true), Map.class, this.collectionName);
  return result == null ? null : result.get(VALUE);
}

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

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

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

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

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

@Override
protected Query createQuery(ConvertingParameterAccessor accessor) {
  MongoQueryCreator creator = new MongoQueryCreator(tree, accessor, context, isGeoNearQuery);
  Query query = creator.createQuery();
  if (tree.isLimiting()) {
    query.limit(tree.getMaxResults());
  }
  TextCriteria textCriteria = accessor.getFullText();
  if (textCriteria != null) {
    query.addCriteria(textCriteria);
  }
  String fieldSpec = getQueryMethod().getFieldSpecification();
  if (!StringUtils.hasText(fieldSpec)) {
    ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
    if (returnedType.isProjecting()) {
      returnedType.getInputProperties().forEach(query.fields()::include);
    }
    return query;
  }
  try {
    BasicQuery result = new BasicQuery(query.getQueryObject(), Document.parse(fieldSpec));
    result.setSortObject(query.getSortObject());
    return result;
  } catch (JSONParseException o_O) {
    throw new IllegalStateException(String.format("Invalid query or field specification in %s!", getQueryMethod()),
        o_O);
  }
}

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

Field fields = query.fields();

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

public List<ApplicationSystem> findAll(String... includeFields) {
  log.debug("Find all ApplicationSystems (include fields: {})", Arrays.toString(includeFields));
  Query q = new Query();
  q.fields().include("name"); // Mandatory field
  for (String includeField : includeFields) {
    q.fields().include(includeField);
  }
  List<ApplicationSystem> applicationSystems = mongoOperations.find(q, ApplicationSystem.class);
  log.debug("Found {} applicationSystems", applicationSystems.size());
  return applicationSystems;
}

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

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

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

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

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

private static Query createApiDocQuery(String clientId, String apiId) {
    Query query = new Query()
        .addCriteria(Criteria.where(ApiDocNames.CLIENT_ID).is(clientId))
        .addCriteria(Criteria.where(ApiDocNames.API_ID).is(apiId));

    query.fields().exclude(ApiDocNames.SWAGGER);
    query.fields().exclude(ApiDocNames.BASE_API_DRAFT);
    return query;
  }
}

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

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

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

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

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

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

相关文章