Skip to content

Modify getQuery(Specification, Pageable) #3517

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,6 @@ public List<T> findAll(Sort sort) {

@Override
public Page<T> findAll(Pageable pageable) {

if (pageable.isUnpaged()) {
return new PageImpl<>(findAll());
}

return findAll((Specification<T>) null, pageable);
}

Expand Down Expand Up @@ -717,8 +712,7 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
*/
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {

Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
return getQuery(spec, getDomainClass(), sort);
return getQuery(spec, getDomainClass(), pageable.getSort());
}

/**
Expand All @@ -731,8 +725,7 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pagea
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
Pageable pageable) {

Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
return getQuery(spec, domainClass, sort);
return getQuery(spec, domainClass, pageable.getSort());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,18 @@ void existsByExampleNegative() {
assertThat(exists).isFalse();
}

@Test // GH-3476
void unPagedSortedQuery() {

flushTestUsers();

Sort sort = Sort.by(DESC, "firstname");
Page<User> firstPage = repository.findAll(PageRequest.of(0, 10, sort));
Page<User> secondPage = repository.findAll(Pageable.unpaged(sort));
assertThat(firstPage.getContent()).isEqualTo(secondPage.getContent());
}


@Test // DATAJPA-905
void executesPagedSpecificationSettingAnOrder() {

Expand Down
Loading