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

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

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

Query.limit介绍

[英]Limit the number of returned documents to limit.
[中]限制返回的文档数量。

代码示例

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

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

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

@Override
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public Object execute(Query query) {
    int pageSize = pageable.getPageSize();
    // Apply Pageable but tweak limit to peek into next page
    Query modifiedQuery = query.with(pageable).limit(pageSize + 1);
    List result = find.matching(modifiedQuery).all();
    boolean hasNext = result.size() > pageSize;
    return new SliceImpl<Object>(hasNext ? result.subList(0, pageSize) : result, pageable, hasNext);
  }
}

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

@Override
public <S extends T> Mono<S> findOne(Example<S> example) {
  Assert.notNull(example, "Sample must not be null!");
  Query q = new Query(new Criteria().alike(example));
  q.limit(2);
  return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
      .map(vals -> {
        if (vals.size() > 1) {
          throw new IncorrectResultSizeDataAccessException(1);
        }
        return vals.iterator().next();
      }).next();
}

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

public <T> Mono<T> findOne(Query query, Class<T> entityClass, String collectionName) {
  if (ObjectUtils.isEmpty(query.getSortObject())) {
    return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
        query.getCollation().orElse(null));
  }
  query.limit(1);
  return find(query, entityClass, collectionName).next();
}

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

@Override
  public Object execute(Query query) {
    int overallLimit = query.getLimit();
    TerminatingFind<?> matching = operation.matching(query);
    // Apply raw pagination
    query.with(pageable);
    // Adjust limit if page would exceed the overall limit
    if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
      query.limit((int) (overallLimit - pageable.getOffset()));
    }
    return PageableExecutionUtils.getPage(matching.all(), pageable, () -> {
      long count = matching.count();
      return overallLimit != 0 ? Math.min(count, overallLimit) : count;
    });
  }
}

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

@Override
public EndpointProfilesPageDto findByEndpointGroupId(PageLinkDto pageLink) {
 LOG.debug("Find endpoint profiles by endpoint group id [{}] ",
   pageLink.getEndpointGroupId());
 EndpointProfilesPageDto endpointProfilesPageDto = new EndpointProfilesPageDto();
 int lim = Integer.valueOf(pageLink.getLimit());
 int offs = Integer.valueOf(pageLink.getOffset());
 List<MongoEndpointProfile> mongoEndpointProfileList = find(
   query(new Criteria()
     .orOperator(where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID)
         .is(pageLink.getEndpointGroupId()),
       where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID)
         .is(pageLink.getEndpointGroupId())))
     .skip(offs)
     .limit(lim + 1));
 if (mongoEndpointProfileList.size() == (lim + 1)) {
  String offset = Integer.toString(lim + offs);
  pageLink.setOffset(offset);
  mongoEndpointProfileList.remove(lim);
 } else {
  pageLink.setNext(DaoConstants.LAST_PAGE_MESSAGE);
 }
 endpointProfilesPageDto.setPageLinkDto(pageLink);
 endpointProfilesPageDto.setEndpointProfiles(convertDtoList(mongoEndpointProfileList));
 return endpointProfilesPageDto;
}

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

int start = (currentPage - 1) * pageSize;
voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), (int) totalCount));
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
    mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);

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

int start = (currentPage - 1) * pageSize;
voCommonPager.setPage(PageHelper.buildPage(query.getPageParameter(), (int) totalCount));
baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
    mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);

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

query.limit(tree.getMaxResults());

代码示例来源: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: yu199195/Raincat

baseQuery.skip(start).limit(pageSize);
final List<MongoAdapter> mongoAdapters =
    mongoTemplate.find(baseQuery, MongoAdapter.class, mongoTableName);

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

where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID)
        .is(pageLink.getEndpointGroupId())));
query.skip(offs).limit(lim + 1);
query.fields()
  .include(DaoConstants.PROFILE)

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

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

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

@Override
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public Object execute(Query query) {
    int pageSize = pageable.getPageSize();
    // Apply Pageable but tweak limit to peek into next page
    Query modifiedQuery = query.with(pageable).limit(pageSize + 1);
    List result = find.matching(modifiedQuery).all();
    boolean hasNext = result.size() > pageSize;
    return new SliceImpl<Object>(hasNext ? result.subList(0, pageSize) : result, pageable, hasNext);
  }
}

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

@Override
public <S extends T> Mono<S> findOne(Example<S> example) {
  Assert.notNull(example, "Sample must not be null!");
  Query q = new Query(new Criteria().alike(example));
  q.limit(2);
  return mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
      .map(vals -> {
        if (vals.size() > 1) {
          throw new IncorrectResultSizeDataAccessException(1);
        }
        return vals.iterator().next();
      }).next();
}

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

public <T> Mono<T> findOne(Query query, Class<T> entityClass, String collectionName) {
  if (ObjectUtils.isEmpty(query.getSortObject())) {
    return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
        query.getCollation().orElse(null));
  }
  query.limit(1);
  return find(query, entityClass, collectionName).next();
}

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

@Override
  public Object execute(Query query) {
    int overallLimit = query.getLimit();
    TerminatingFind<?> matching = operation.matching(query);
    // Apply raw pagination
    query.with(pageable);
    // Adjust limit if page would exceed the overall limit
    if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
      query.limit((int) (overallLimit - pageable.getOffset()));
    }
    return PageableExecutionUtils.getPage(matching.all(), pageable, () -> {
      long count = matching.count();
      return overallLimit != 0 ? Math.min(count, overallLimit) : count;
    });
  }
}

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

query.limit(tree.getMaxResults());

代码示例来源: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: io.gravitee.repository/gravitee-repository-mongodb

@Override
public int findMaxPortalPageOrder() {
  Query query = new Query();
  query.limit(1);
  query.with(new Sort(Sort.Direction.DESC, "order"));
  query.addCriteria(where("api").exists(false));
  PageMongo page = mongoTemplate.findOne(query, PageMongo.class);
  return (page != null) ? page.getOrder() : 0;
}

相关文章