本文整理了Java中org.springframework.data.mongodb.core.query.Query.getLimit
方法的一些代码示例,展示了Query.getLimit
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getLimit
方法的具体详情如下:
包路径:org.springframework.data.mongodb.core.query.Query
类名称:Query
方法名:getLimit
[英]Get the maximum number of documents to be return.
[中]
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Adds an actual query to the {@link NearQuery} to restrict the objects considered for the actual near operation.
*
* @param query must not be {@literal null}.
* @return
*/
public NearQuery query(Query query) {
Assert.notNull(query, "Cannot apply 'null' query on NearQuery.");
this.query = query;
this.skip = query.getSkip();
if (query.getLimit() != 0) {
this.num = (long) query.getLimit();
}
return this;
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Checks mandatory properties
*
* @see InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(template != null, "An implementation of MongoOperations is required.");
Assert.state(type != null, "A type to convert the input into is required.");
Assert.state(queryString != null || query != null, "A query is required.");
if (queryString != null) {
Assert.state(sort != null, "A sort is required.");
}
if (query != null && query.getLimit() != 0) {
log.warn("PageSize in Query object was ignored. Please set it by MongoItemReader.setPageSize().");
}
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public <S, T> T findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
String collectionName, Class<T> resultType) {
Assert.notNull(query, "Query must not be null!");
Assert.notNull(replacement, "Replacement must not be null!");
Assert.notNull(options, "Options must not be null! Use FindAndReplaceOptions#empty() instead.");
Assert.notNull(entityType, "EntityType must not be null!");
Assert.notNull(collectionName, "CollectionName must not be null!");
Assert.notNull(resultType, "ResultType must not be null! Use Object.class instead.");
Assert.isTrue(query.getLimit() <= 1, "Query must not define a limit other than 1 ore none!");
Assert.isTrue(query.getSkip() <= 0, "Query must not define skip.");
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), entity);
Document mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), entity);
Document mappedSort = queryMapper.getMappedSort(query.getSortObject(), entity);
Document mappedReplacement = operations.forEntity(replacement).toMappedDocument(this.mongoConverter).getDocument();
return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
query.getCollation().map(Collation::toMongoCollation).orElse(null), entityType, mappedReplacement, options,
resultType);
}
代码示例来源:origin: spring-projects/spring-data-mongodb
@Override
public <S, T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
String collectionName, Class<T> resultType) {
Assert.notNull(query, "Query must not be null!");
Assert.notNull(replacement, "Replacement must not be null!");
Assert.notNull(options, "Options must not be null! Use FindAndReplaceOptions#empty() instead.");
Assert.notNull(entityType, "Entity class must not be null!");
Assert.notNull(collectionName, "CollectionName must not be null!");
Assert.notNull(resultType, "ResultType must not be null! Use Object.class instead.");
Assert.isTrue(query.getLimit() <= 1, "Query must not define a limit other than 1 ore none!");
Assert.isTrue(query.getSkip() <= 0, "Query must not define skip.");
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), entity);
Document mappedFields = queryMapper.getMappedFields(query.getFieldsObject(), entity);
Document mappedSort = queryMapper.getMappedSort(query.getSortObject(), entity);
Document mappedReplacement = operations.forEntity(replacement).toMappedDocument(this.mongoConverter).getDocument();
return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
query.getCollation().map(Collation::toMongoCollation).orElse(null), entityType, mappedReplacement, options,
resultType);
}
代码示例来源:origin: spring-projects/spring-batch
Assert.state(this.query.getLimit() != 0, "PageSize in Query object was ignored.");
代码示例来源: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: spring-projects/spring-batch
@Test
public void testBasicQueryFirstPage() {
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testBasicQuerySecondPage() {
reader.page = 2;
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(100, query.getSkip());
assertEquals("{ }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
assertTrue(query.getFieldsObject().isEmpty());
}
代码示例来源:origin: spring-projects/spring-data-mongodb
if (query.getSkip() <= 0 && query.getLimit() <= 0 && ObjectUtils.isEmpty(query.getSortObject())
&& !StringUtils.hasText(query.getHint()) && !meta.hasValues()) {
return findPublisherToUse;
if (query.getLimit() > 0) {
findPublisherToUse = findPublisherToUse.limit(query.getLimit());
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryWithHint() {
reader.setHint("{ $natural : 1}");
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
assertEquals("{ $natural : 1}", query.getHint());
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("serial")
@Test
public void testQueryWithParameters() {
reader.setParameterValues(new ArrayList<Object>(){{
add("foo");
}});
reader.setQuery("{ name : ?0 }");
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testBasic() throws Exception {
MongoItemReader<String> reader = getBasicBuilder().build();
when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertNull("reader should not return result", reader.read());
Query query = this.queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
}
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("serial")
@Test
public void testQueryWithCollection() {
reader.setParameterValues(new ArrayList<Object>(){{
add("foo");
}});
reader.setQuery("{ name : ?0 }");
reader.setCollection("collection");
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
ArgumentCaptor<String> collectionContainer = ArgumentCaptor.forClass(String.class);
when(template.find(queryContainer.capture(), eq(String.class), collectionContainer.capture())).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
assertEquals("collection", collectionContainer.getValue());
}
代码示例来源:origin: spring-projects/spring-data-mongodb
if (query.getLimit() > 0 || query.getSkip() > 0) {
代码示例来源:origin: spring-projects/spring-data-mongodb
if (query.getLimit() > 0 || query.getSkip() > 0) {
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryObject() throws Exception {
reader = new MongoItemReader<>();
reader.setTemplate(template);
Query query = new Query()
.with(Sort.by(new Order(Sort.Direction.ASC, "_id")));
reader.setQuery(query);
reader.setTargetType(String.class);
reader.afterPropertiesSet();
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query actualQuery = queryContainer.getValue();
assertFalse(reader.doPageRead().hasNext());
assertEquals(10, actualQuery.getLimit());
assertEquals(0, actualQuery.getSkip());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryObjectWithCollection() throws Exception {
reader = new MongoItemReader<>();
reader.setTemplate(template);
Query query = new Query()
.with(Sort.by(new Order(Sort.Direction.ASC, "_id")));
reader.setQuery(query);
reader.setTargetType(String.class);
reader.setCollection("collection");
reader.afterPropertiesSet();
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
ArgumentCaptor<String> stringContainer = ArgumentCaptor.forClass(String.class);
when(template.find(queryContainer.capture(), eq(String.class), stringContainer.capture())).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query actualQuery = queryContainer.getValue();
assertFalse(reader.doPageRead().hasNext());
assertEquals(10, actualQuery.getLimit());
assertEquals(0, actualQuery.getSkip());
assertEquals("collection", stringContainer.getValue());
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryObjectWithIgnoredPageSize() throws Exception {
reader = new MongoItemReader<>();
reader.setTemplate(template);
Query query = new Query()
.with(Sort.by(new Order(Sort.Direction.ASC, "_id")))
.with(PageRequest.of(0, 50));
reader.setQuery(query);
reader.setTargetType(String.class);
reader.afterPropertiesSet();
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query actualQuery = queryContainer.getValue();
assertFalse(reader.doPageRead().hasNext());
assertEquals(10, actualQuery.getLimit());
assertEquals(0, actualQuery.getSkip());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryObjectWithPageSize() throws Exception {
reader = new MongoItemReader<>();
reader.setTemplate(template);
Query query = new Query()
.with(Sort.by(new Order(Sort.Direction.ASC, "_id")))
.with(PageRequest.of(30, 50));
reader.setQuery(query);
reader.setTargetType(String.class);
reader.setPageSize(100);
reader.afterPropertiesSet();
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query actualQuery = queryContainer.getValue();
assertFalse(reader.doPageRead().hasNext());
assertEquals(100, actualQuery.getLimit());
assertEquals(0, actualQuery.getSkip());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testQueryWithFields() {
reader.setFields("{name : 1, age : 1, _id: 0}");
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
assertFalse(reader.doPageRead().hasNext());
Query query = queryContainer.getValue();
assertEquals(50, query.getLimit());
assertEquals(0, query.getSkip());
assertEquals("{ }", query.getQueryObject().toJson());
assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson());
assertEquals(1, query.getFieldsObject().get("name"));
assertEquals(1, query.getFieldsObject().get("age"));
assertEquals(0, query.getFieldsObject().get("_id"));
}
内容来源于网络,如有侵权,请联系作者删除!