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

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

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

  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. @SuppressWarnings({ "unchecked", "rawtypes" })
  3. public Object execute(Query query) {
  4. int pageSize = pageable.getPageSize();
  5. // Apply Pageable but tweak limit to peek into next page
  6. Query modifiedQuery = query.with(pageable).limit(pageSize + 1);
  7. List result = find.matching(modifiedQuery).all();
  8. boolean hasNext = result.size() > pageSize;
  9. return new SliceImpl<Object>(hasNext ? result.subList(0, pageSize) : result, pageable, hasNext);
  10. }
  11. }

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

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

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

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

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

  1. @Override
  2. public Object execute(Query query) {
  3. int overallLimit = query.getLimit();
  4. TerminatingFind<?> matching = operation.matching(query);
  5. // Apply raw pagination
  6. query.with(pageable);
  7. // Adjust limit if page would exceed the overall limit
  8. if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
  9. query.limit((int) (overallLimit - pageable.getOffset()));
  10. }
  11. return PageableExecutionUtils.getPage(matching.all(), pageable, () -> {
  12. long count = matching.count();
  13. return overallLimit != 0 ? Math.min(count, overallLimit) : count;
  14. });
  15. }
  16. }

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

  1. @Override
  2. public EndpointProfilesPageDto findByEndpointGroupId(PageLinkDto pageLink) {
  3. LOG.debug("Find endpoint profiles by endpoint group id [{}] ",
  4. pageLink.getEndpointGroupId());
  5. EndpointProfilesPageDto endpointProfilesPageDto = new EndpointProfilesPageDto();
  6. int lim = Integer.valueOf(pageLink.getLimit());
  7. int offs = Integer.valueOf(pageLink.getOffset());
  8. List<MongoEndpointProfile> mongoEndpointProfileList = find(
  9. query(new Criteria()
  10. .orOperator(where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID)
  11. .is(pageLink.getEndpointGroupId()),
  12. where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID)
  13. .is(pageLink.getEndpointGroupId())))
  14. .skip(offs)
  15. .limit(lim + 1));
  16. if (mongoEndpointProfileList.size() == (lim + 1)) {
  17. String offset = Integer.toString(lim + offs);
  18. pageLink.setOffset(offset);
  19. mongoEndpointProfileList.remove(lim);
  20. } else {
  21. pageLink.setNext(DaoConstants.LAST_PAGE_MESSAGE);
  22. }
  23. endpointProfilesPageDto.setPageLinkDto(pageLink);
  24. endpointProfilesPageDto.setEndpointProfiles(convertDtoList(mongoEndpointProfileList));
  25. return endpointProfilesPageDto;
  26. }

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

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

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

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

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

  1. query.limit(tree.getMaxResults());

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

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

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

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

代码示例来源:origin: org.springframework.data/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: org.springframework.data/spring-data-mongodb

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

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

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

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

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

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

  1. @Override
  2. public Object execute(Query query) {
  3. int overallLimit = query.getLimit();
  4. TerminatingFind<?> matching = operation.matching(query);
  5. // Apply raw pagination
  6. query.with(pageable);
  7. // Adjust limit if page would exceed the overall limit
  8. if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
  9. query.limit((int) (overallLimit - pageable.getOffset()));
  10. }
  11. return PageableExecutionUtils.getPage(matching.all(), pageable, () -> {
  12. long count = matching.count();
  13. return overallLimit != 0 ? Math.min(count, overallLimit) : count;
  14. });
  15. }
  16. }

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

  1. query.limit(tree.getMaxResults());

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

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

相关文章