-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sorting ability for unpaged request in QuerydslPredicateExecutor [DATACMNS-1405] #3761
Comments
Oskars Pakers commented This would be very beneficial to apply default sorting when pagination is not used (but can be passed). A simple class can be added. class UnpagedSorted implements Pageable {
private final Sort sort;
UnpagedSorted(Sort sort) {
this.sort = sort;
}
public boolean isPaged() {
return false;
}
public Pageable previousOrFirst() {
return this;
}
public Pageable next() {
return this;
}
public boolean hasPrevious() {
return false;
}
public Sort getSort() {
return sort;
}
public int getPageSize() {
throw new UnsupportedOperationException();
}
public int getPageNumber() {
throw new UnsupportedOperationException();
}
public long getOffset() {
throw new UnsupportedOperationException();
}
public Pageable first() {
return this;
}
}
Then service method can use the same repository method, for example. if (limit == null) {
return songRepository.findByArtist(artist, new UnpagedSorted(Sort.by("title").ascending()));
}
return songRepository.findByArtist(artist, PageRequest.of(0, limit)); What do you think? |
I was also very surprised to find that this does not work: repository.findAll(predicate, Pageable.unpaged(Sort.by("timestamp"))) The results are instead in the default, unsorted order. |
In JPA, this is still present and we've fixed #3476 for Specifications and Query by Example. I'm going to move this ticket into JPA. |
We now apply sorting using Querydsl for Pageable that is sorted but not paged. Closes #3761
We now apply sorting using Querydsl for Pageable that is sorted but not paged. Closes #3761
Vladyslav Tkachuk opened DATACMNS-1405 and commented
I'm sorry for a bit confusing title, but I'll try to explain it here.
So, org.springframework.data.querydsl.QuerydslPredicateExecutor has a method to return paged data Page findAll(Predicate predicate, Pageable pageable).
If you want to get all existing entities as one page, Pageable.unpaged() as a second paramater.
However, this way you cannot get this single page sorted anyhow, whereas QPageRequest and PageRequest which extend AbstractPageRequest which implements Pageable have sorting ability.
Based on this, if you want to have a single page with all entities, you won't get it sorted.
To my mind this functionality is missing.
I would be interested to hear your opinions and ideas.
No further details from DATACMNS-1405
The text was updated successfully, but these errors were encountered: