DATAJPA-243 - QueryDslJpaRepository applies sort given through Pageable correctly.
During the refactoring of the Querydsl interaction a regression of not applying a Sort wrapped in a Pageable was introduced in QueryDsl utility class.
This commit is contained in:
@@ -104,7 +104,7 @@ public class Querydsl {
|
||||
query.offset(pageable.getOffset());
|
||||
query.limit(pageable.getPageSize());
|
||||
|
||||
return query;
|
||||
return applySorting(pageable.getSort(), query);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,12 +26,16 @@ import javax.persistence.PersistenceContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.jpa.domain.sample.QUser;
|
||||
import org.springframework.data.jpa.domain.sample.User;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.expr.BooleanExpression;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.mysema.query.types.path.PathBuilderFactory;
|
||||
@@ -89,4 +93,23 @@ public class QueryDslJpaRepositoryTests {
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result, hasItems(carter, dave));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-243
|
||||
*/
|
||||
@Test
|
||||
public void considersSortingProvidedThroughPageable() {
|
||||
|
||||
Predicate lastnameContainsE = user.lastname.contains("e");
|
||||
|
||||
Page<User> result = repository.findAll(lastnameContainsE, new PageRequest(0, 1, Direction.ASC, "lastname"));
|
||||
|
||||
assertThat(result.getContent(), hasSize(1));
|
||||
assertThat(result.getContent().get(0), is(carter));
|
||||
|
||||
result = repository.findAll(lastnameContainsE, new PageRequest(0, 1, Direction.DESC, "lastname"));
|
||||
|
||||
assertThat(result.getContent(), hasSize(1));
|
||||
assertThat(result.getContent().get(0), is(dave));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user