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

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

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

Query.getSkip介绍

[英]Get the number of documents to skip.
[中]获取要跳过的文档数。

代码示例

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

  1. /**
  2. * Adds an actual query to the {@link NearQuery} to restrict the objects considered for the actual near operation.
  3. *
  4. * @param query must not be {@literal null}.
  5. * @return
  6. */
  7. public NearQuery query(Query query) {
  8. Assert.notNull(query, "Cannot apply 'null' query on NearQuery.");
  9. this.query = query;
  10. this.skip = query.getSkip();
  11. if (query.getLimit() != 0) {
  12. this.num = (long) query.getLimit();
  13. }
  14. return this;
  15. }

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

  1. @Override
  2. public <S, T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
  3. String collectionName, Class<T> resultType) {
  4. Assert.notNull(query, "Query must not be null!");
  5. Assert.notNull(replacement, "Replacement must not be null!");
  6. Assert.notNull(options, "Options must not be null! Use FindAndReplaceOptions#empty() instead.");
  7. Assert.notNull(entityType, "Entity class must not be null!");
  8. Assert.notNull(collectionName, "CollectionName must not be null!");
  9. Assert.notNull(resultType, "ResultType must not be null! Use Object.class instead.");
  10. Assert.isTrue(query.getLimit() <= 1, "Query must not define a limit other than 1 ore none!");
  11. Assert.isTrue(query.getSkip() <= 0, "Query must not define skip.");
  12. MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
  13. Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), entity);
  14. Document mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), entity);
  15. Document mappedSort = queryMapper.getMappedSort(query.getSortObject(), entity);
  16. Document mappedReplacement = operations.forEntity(replacement).toMappedDocument(this.mongoConverter).getDocument();
  17. return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
  18. query.getCollation().map(Collation::toMongoCollation).orElse(null), entityType, mappedReplacement, options,
  19. resultType);
  20. }

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

  1. @Override
  2. public <S, T> T findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
  3. String collectionName, Class<T> resultType) {
  4. Assert.notNull(query, "Query must not be null!");
  5. Assert.notNull(replacement, "Replacement must not be null!");
  6. Assert.notNull(options, "Options must not be null! Use FindAndReplaceOptions#empty() instead.");
  7. Assert.notNull(entityType, "EntityType must not be null!");
  8. Assert.notNull(collectionName, "CollectionName must not be null!");
  9. Assert.notNull(resultType, "ResultType must not be null! Use Object.class instead.");
  10. Assert.isTrue(query.getLimit() <= 1, "Query must not define a limit other than 1 ore none!");
  11. Assert.isTrue(query.getSkip() <= 0, "Query must not define skip.");
  12. MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
  13. Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), entity);
  14. Document mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), entity);
  15. Document mappedSort = queryMapper.getMappedSort(query.getSortObject(), entity);
  16. Document mappedReplacement = operations.forEntity(replacement).toMappedDocument(this.mongoConverter).getDocument();
  17. return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
  18. query.getCollation().map(Collation::toMongoCollation).orElse(null), entityType, mappedReplacement, options,
  19. resultType);
  20. }

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

  1. @Test
  2. public void testBasicQueryFirstPage() {
  3. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  4. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  5. assertFalse(reader.doPageRead().hasNext());
  6. Query query = queryContainer.getValue();
  7. assertEquals(50, query.getLimit());
  8. assertEquals(0, query.getSkip());
  9. assertEquals("{ }", query.getQueryObject().toJson());
  10. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  11. }

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

  1. @Test
  2. public void testBasicQuerySecondPage() {
  3. reader.page = 2;
  4. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  5. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  6. assertFalse(reader.doPageRead().hasNext());
  7. Query query = queryContainer.getValue();
  8. assertEquals(50, query.getLimit());
  9. assertEquals(100, query.getSkip());
  10. assertEquals("{ }", query.getQueryObject().toJson());
  11. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  12. assertTrue(query.getFieldsObject().isEmpty());
  13. }

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

  1. if (query.getSkip() <= 0 && query.getLimit() <= 0 && ObjectUtils.isEmpty(query.getSortObject())
  2. && !StringUtils.hasText(query.getHint()) && !meta.hasValues()) {
  3. return findPublisherToUse;
  4. if (query.getSkip() > 0) {
  5. findPublisherToUse = findPublisherToUse.skip((int) query.getSkip());

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

  1. @Test
  2. public void testQueryWithHint() {
  3. reader.setHint("{ $natural : 1}");
  4. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  5. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  6. assertFalse(reader.doPageRead().hasNext());
  7. Query query = queryContainer.getValue();
  8. assertEquals(50, query.getLimit());
  9. assertEquals(0, query.getSkip());
  10. assertEquals("{ }", query.getQueryObject().toJson());
  11. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  12. assertEquals("{ $natural : 1}", query.getHint());
  13. }

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

  1. @SuppressWarnings("serial")
  2. @Test
  3. public void testQueryWithParameters() {
  4. reader.setParameterValues(new ArrayList<Object>(){{
  5. add("foo");
  6. }});
  7. reader.setQuery("{ name : ?0 }");
  8. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  9. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  10. assertFalse(reader.doPageRead().hasNext());
  11. Query query = queryContainer.getValue();
  12. assertEquals(50, query.getLimit());
  13. assertEquals(0, query.getSkip());
  14. assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson());
  15. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  16. }

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

  1. @Test
  2. public void testBasic() throws Exception {
  3. MongoItemReader<String> reader = getBasicBuilder().build();
  4. when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  5. assertNull("reader should not return result", reader.read());
  6. Query query = this.queryContainer.getValue();
  7. assertEquals(50, query.getLimit());
  8. assertEquals(0, query.getSkip());
  9. assertEquals("{ }", query.getQueryObject().toJson());
  10. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  11. }

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

  1. if (query.getSkip() <= 0 && query.getLimit() <= 0 && ObjectUtils.isEmpty(query.getSortObject())
  2. && !StringUtils.hasText(query.getHint()) && !meta.hasValues() && !query.getCollation().isPresent()) {
  3. return cursor;
  4. if (query.getSkip() > 0) {
  5. cursorToUse = cursorToUse.skip((int) query.getSkip());

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

  1. @SuppressWarnings("serial")
  2. @Test
  3. public void testQueryWithCollection() {
  4. reader.setParameterValues(new ArrayList<Object>(){{
  5. add("foo");
  6. }});
  7. reader.setQuery("{ name : ?0 }");
  8. reader.setCollection("collection");
  9. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  10. ArgumentCaptor<String> collectionContainer = ArgumentCaptor.forClass(String.class);
  11. when(template.find(queryContainer.capture(), eq(String.class), collectionContainer.capture())).thenReturn(new ArrayList<>());
  12. assertFalse(reader.doPageRead().hasNext());
  13. Query query = queryContainer.getValue();
  14. assertEquals(50, query.getLimit());
  15. assertEquals(0, query.getSkip());
  16. assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson());
  17. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  18. assertEquals("collection", collectionContainer.getValue());
  19. }

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

  1. if (query.getLimit() > 0 || query.getSkip() > 0) {

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

  1. if (query.getLimit() > 0 || query.getSkip() > 0) {

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

  1. @Test
  2. public void testQueryObject() throws Exception {
  3. reader = new MongoItemReader<>();
  4. reader.setTemplate(template);
  5. Query query = new Query()
  6. .with(Sort.by(new Order(Sort.Direction.ASC, "_id")));
  7. reader.setQuery(query);
  8. reader.setTargetType(String.class);
  9. reader.afterPropertiesSet();
  10. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  11. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  12. assertFalse(reader.doPageRead().hasNext());
  13. Query actualQuery = queryContainer.getValue();
  14. assertFalse(reader.doPageRead().hasNext());
  15. assertEquals(10, actualQuery.getLimit());
  16. assertEquals(0, actualQuery.getSkip());
  17. }

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

  1. @Test
  2. public void testQueryObjectWithCollection() throws Exception {
  3. reader = new MongoItemReader<>();
  4. reader.setTemplate(template);
  5. Query query = new Query()
  6. .with(Sort.by(new Order(Sort.Direction.ASC, "_id")));
  7. reader.setQuery(query);
  8. reader.setTargetType(String.class);
  9. reader.setCollection("collection");
  10. reader.afterPropertiesSet();
  11. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  12. ArgumentCaptor<String> stringContainer = ArgumentCaptor.forClass(String.class);
  13. when(template.find(queryContainer.capture(), eq(String.class), stringContainer.capture())).thenReturn(new ArrayList<>());
  14. assertFalse(reader.doPageRead().hasNext());
  15. Query actualQuery = queryContainer.getValue();
  16. assertFalse(reader.doPageRead().hasNext());
  17. assertEquals(10, actualQuery.getLimit());
  18. assertEquals(0, actualQuery.getSkip());
  19. assertEquals("collection", stringContainer.getValue());
  20. }
  21. }

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

  1. @Test
  2. public void testQueryObjectWithIgnoredPageSize() throws Exception {
  3. reader = new MongoItemReader<>();
  4. reader.setTemplate(template);
  5. Query query = new Query()
  6. .with(Sort.by(new Order(Sort.Direction.ASC, "_id")))
  7. .with(PageRequest.of(0, 50));
  8. reader.setQuery(query);
  9. reader.setTargetType(String.class);
  10. reader.afterPropertiesSet();
  11. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  12. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  13. assertFalse(reader.doPageRead().hasNext());
  14. Query actualQuery = queryContainer.getValue();
  15. assertFalse(reader.doPageRead().hasNext());
  16. assertEquals(10, actualQuery.getLimit());
  17. assertEquals(0, actualQuery.getSkip());
  18. }

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

  1. @Test
  2. public void testQueryObjectWithPageSize() throws Exception {
  3. reader = new MongoItemReader<>();
  4. reader.setTemplate(template);
  5. Query query = new Query()
  6. .with(Sort.by(new Order(Sort.Direction.ASC, "_id")))
  7. .with(PageRequest.of(30, 50));
  8. reader.setQuery(query);
  9. reader.setTargetType(String.class);
  10. reader.setPageSize(100);
  11. reader.afterPropertiesSet();
  12. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  13. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  14. assertFalse(reader.doPageRead().hasNext());
  15. Query actualQuery = queryContainer.getValue();
  16. assertFalse(reader.doPageRead().hasNext());
  17. assertEquals(100, actualQuery.getLimit());
  18. assertEquals(0, actualQuery.getSkip());
  19. }

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

  1. @Test
  2. public void testQueryWithFields() {
  3. reader.setFields("{name : 1, age : 1, _id: 0}");
  4. ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
  5. when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
  6. assertFalse(reader.doPageRead().hasNext());
  7. Query query = queryContainer.getValue();
  8. assertEquals(50, query.getLimit());
  9. assertEquals(0, query.getSkip());
  10. assertEquals("{ }", query.getQueryObject().toJson());
  11. assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
  12. assertEquals(1, query.getFieldsObject().get("name"));
  13. assertEquals(1, query.getFieldsObject().get("age"));
  14. assertEquals(0, query.getFieldsObject().get("_id"));
  15. }

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

  1. /**
  2. * Adds an actual query to the {@link NearQuery} to restrict the objects considered for the actual near operation.
  3. *
  4. * @param query must not be {@literal null}.
  5. * @return
  6. */
  7. public NearQuery query(Query query) {
  8. Assert.notNull(query, "Cannot apply 'null' query on NearQuery.");
  9. this.query = query;
  10. this.skip = query.getSkip();
  11. if (query.getLimit() != 0) {
  12. this.num = (long) query.getLimit();
  13. }
  14. return this;
  15. }

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

  1. @Override
  2. public <S, T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
  3. String collectionName, Class<T> resultType) {
  4. Assert.notNull(query, "Query must not be null!");
  5. Assert.notNull(replacement, "Replacement must not be null!");
  6. Assert.notNull(options, "Options must not be null! Use FindAndReplaceOptions#empty() instead.");
  7. Assert.notNull(entityType, "Entity class must not be null!");
  8. Assert.notNull(collectionName, "CollectionName must not be null!");
  9. Assert.notNull(resultType, "ResultType must not be null! Use Object.class instead.");
  10. Assert.isTrue(query.getLimit() <= 1, "Query must not define a limit other than 1 ore none!");
  11. Assert.isTrue(query.getSkip() <= 0, "Query must not define skip.");
  12. MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
  13. Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), entity);
  14. Document mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), entity);
  15. Document mappedSort = queryMapper.getMappedSort(query.getSortObject(), entity);
  16. Document mappedReplacement = operations.forEntity(replacement).toMappedDocument(this.mongoConverter).getDocument();
  17. return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
  18. query.getCollation().map(Collation::toMongoCollation).orElse(null), entityType, mappedReplacement, options,
  19. resultType);
  20. }

相关文章