DATAJPA-635 - Added implementation of QueryDslPredicateExecutor.findAll(OrderSpecifier<?>... orders).
This commit is contained in:
@@ -107,10 +107,16 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
* @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.Predicate, com.mysema.query.types.OrderSpecifier<?>[])
|
||||
*/
|
||||
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
|
||||
return executeSorted(createQuery(predicate), orders);
|
||||
}
|
||||
|
||||
JPQLQuery query = createQuery(predicate);
|
||||
query = querydsl.applySorting(new QSort(orders), query);
|
||||
return query.list(path);
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.OrderSpecifier[])
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll(OrderSpecifier<?>... orders) {
|
||||
return executeSorted(createQuery(new Predicate[0]), orders);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -174,4 +180,15 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given {@link JPQLQuery} after applying the given {@link OrderSpecifier}s.
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param orders must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private List<T> executeSorted(JPQLQuery query, OrderSpecifier<?>... orders) {
|
||||
return querydsl.applySorting(new QSort(orders), query).list(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -290,15 +288,14 @@ public class QueryDslJpaRepositoryTests {
|
||||
oliver.setManager(dave);
|
||||
dave.getRoles().add(adminRole);
|
||||
|
||||
Page<User> page = repository.findAll(QUser.user.id.gt(0), new PageRequest(0, 10, //
|
||||
new Sort(Sort.Direction.ASC, "manager.roles.name")));
|
||||
Page<User> page = repository.findAll(new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "manager.roles.name")));
|
||||
|
||||
assertThat(page.getContent(), hasSize(3));
|
||||
assertThat(page.getContent().get(0), is(dave));
|
||||
}
|
||||
|
||||
/**
|
||||
* @DATAJPA-500
|
||||
* @see DATAJPA-500, DATAJPA-635
|
||||
*/
|
||||
@Test
|
||||
public void sortByNestedEmbeddedAttribite() {
|
||||
@@ -307,24 +304,24 @@ public class QueryDslJpaRepositoryTests {
|
||||
dave.setAddress(new Address("U", "A", "Y", "41"));
|
||||
oliver.setAddress(new Address("G", "D", "X", "42"));
|
||||
|
||||
List<User> users = repository.findAll(QUser.user.id.goe(0), QUser.user.address.streetName.asc());
|
||||
List<User> users = repository.findAll(QUser.user.address.streetName.asc());
|
||||
|
||||
assertThat(users, hasSize(3));
|
||||
assertThat(users, hasItems(dave, oliver, carter));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @DATAJPA-566
|
||||
* @see DATAJPA-566, DATAJPA-635
|
||||
*/
|
||||
@Test
|
||||
public void shouldSupportSortByOperatorWithDateExpressions() {
|
||||
|
||||
|
||||
carter.setDateOfBirth(new LocalDate(2000, 2, 1).toDate());
|
||||
dave.setDateOfBirth(new LocalDate(2000, 1, 1).toDate());
|
||||
oliver.setDateOfBirth(new LocalDate(2003, 5, 1).toDate());
|
||||
|
||||
List<User> users = repository.findAll(QUser.user.id.goe(0), QUser.user.dateOfBirth.yearMonth().asc());
|
||||
|
||||
|
||||
List<User> users = repository.findAll(QUser.user.dateOfBirth.yearMonth().asc());
|
||||
|
||||
assertThat(users, hasSize(3));
|
||||
assertThat(users, hasItems(dave, carter, oliver));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user