Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Apply sort of unpaged Pageable to QuerydslMongoPredicateExecutor query.

Original pull request: #4773
Closes #4771
  • Loading branch information
mp911de committed Sep 12, 2024
1 parent 4df06c7 commit a508b7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,11 @@ public Query withHint(Document hint) {
*/
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
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;
Expand Down Expand Up @@ -199,11 +200,10 @@ private SpringDataMongodbQuery<T> createQuery() {
*/
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public void findPage() {
.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() {

Expand Down

0 comments on commit a508b7d

Please sign in to comment.