Polishing.
Apply sort of unpaged Pageable to QuerydslMongoPredicateExecutor query. Original pull request: #4773 Closes #4771
This commit is contained in:
@@ -285,16 +285,11 @@ public class Query implements ReadConcernAware, ReadPreferenceAware {
|
||||
*/
|
||||
public Query with(Pageable pageable) {
|
||||
|
||||
if (pageable.isUnpaged()) {
|
||||
if(pageable.getSort().isSorted()) {
|
||||
return with(pageable.getSort());
|
||||
}
|
||||
return this;
|
||||
if (pageable.isPaged()) {
|
||||
this.limit = pageable.toLimit();
|
||||
this.skip = pageable.getOffset();
|
||||
}
|
||||
|
||||
this.limit = pageable.toLimit();
|
||||
this.skip = pageable.getOffset();
|
||||
|
||||
return with(pageable.getSort());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,13 @@ import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Window;
|
||||
import org.springframework.data.domain.ScrollPosition;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Window;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
@@ -199,11 +200,10 @@ public class QuerydslMongoPredicateExecutor<T> extends QuerydslPredicateExecutor
|
||||
*/
|
||||
private SpringDataMongodbQuery<T> applyPagination(SpringDataMongodbQuery<T> query, Pageable pageable) {
|
||||
|
||||
if (pageable.isUnpaged()) {
|
||||
return query;
|
||||
if (pageable.isPaged()) {
|
||||
query = query.offset(pageable.getOffset()).limit(pageable.getPageSize());
|
||||
}
|
||||
|
||||
query = query.offset(pageable.getOffset()).limit(pageable.getPageSize());
|
||||
return applySorting(query, pageable.getSort());
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,13 @@ public class QuerydslMongoPredicateExecutorIntegrationTests {
|
||||
.getContent()).containsExactly(dave);
|
||||
}
|
||||
|
||||
@Test // GH-4771
|
||||
public void findUnpagedPage() {
|
||||
|
||||
assertThat(repository.findAll(person.lastname.isNotNull(), Pageable.unpaged(Sort.by("firstname"))))
|
||||
.containsExactly(carter, dave, oliver);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-362, DATAMONGO-1848
|
||||
public void springDataMongodbQueryShouldAllowJoinOnDBref() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user