Skip to content

Commit

Permalink
Apply sort of unpaged Pageable to query.
Browse files Browse the repository at this point in the history
Original pull request: #4773
Closes #4771
  • Loading branch information
christophstrobl authored and mp911de committed Sep 12, 2024
1 parent 156197c commit a960ae1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ public Query withHint(Document hint) {
public Query with(Pageable pageable) {

if (pageable.isUnpaged()) {
if(pageable.getSort().isSorted()) {
return with(pageable.getSort());
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.data.domain.Limit;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
Expand Down Expand Up @@ -366,6 +367,15 @@ void queryOfShouldWorkOnProxiedObjects() {
compareQueries(target, source);
}

@Test // GH-4771
void appliesSortOfUnpagedPageable() {

Query query = new Query();
query.with(Pageable.unpaged(Sort.by("sortMe")));

assertThat(query.isSorted()).isTrue();
}

private void compareQueries(Query actual, Query expected) {

assertThat(actual.getCollation()).isEqualTo(expected.getCollation());
Expand Down

0 comments on commit a960ae1

Please sign in to comment.