Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DATAJPA-243 - QueryDslJpaRepository applies sort given through Pageab…

…le 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.
  • Loading branch information...
commit e59b8b31944c47652234213d61fb59003c1a71fc 1 parent c90d1c1
@olivergierke olivergierke authored
View
2  src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java
@@ -104,7 +104,7 @@ public JPQLQuery applyPagination(Pageable pageable, JPQLQuery query) {
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
- return query;
+ return applySorting(pageable.getSort(), query);
}
/**
View
23 ...test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java
@@ -26,12 +26,16 @@
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 void executesStringBasedPredicatesCorrectly() throws Exception {
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));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.