Fixed missing application of Pageable handed to query methods using query derivation from the method name.
This commit is contained in:
@@ -17,8 +17,10 @@ package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.query.SimpleParameterAccessor;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
|
||||
@@ -59,12 +61,23 @@ public class PartTreeJpaQuery extends AbstractJpaQuery {
|
||||
*/
|
||||
public Query createQuery(Object[] parameters) {
|
||||
|
||||
SimpleParameterAccessor accessor =
|
||||
new SimpleParameterAccessor(getParameters(), parameters);
|
||||
|
||||
JpaQueryCreator jpaQueryCreator =
|
||||
new JpaQueryCreator(tree, new SimpleParameterAccessor(
|
||||
getParameters(), parameters), domainClass,
|
||||
new JpaQueryCreator(tree, accessor, domainClass,
|
||||
getEntityManager());
|
||||
|
||||
return getEntityManager().createQuery(jpaQueryCreator.createQuery());
|
||||
TypedQuery<Object> query =
|
||||
getEntityManager().createQuery(jpaQueryCreator.createQuery());
|
||||
|
||||
if (getParameters().hasPageableParameter()) {
|
||||
Pageable pageable = accessor.getPageable();
|
||||
query.setFirstResult(pageable.getOffset());
|
||||
query.setMaxResults(pageable.getPageSize());
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ public class UserRepositoryFinderTests {
|
||||
secondUser = new User();
|
||||
secondUser.setEmailAddress("bar");
|
||||
secondUser.setLastname("foo");
|
||||
secondUser.setFirstname("foobar");
|
||||
|
||||
userRepository.save(secondUser);
|
||||
}
|
||||
@@ -117,8 +118,7 @@ public class UserRepositoryFinderTests {
|
||||
public void executesPagingMethodToPageCorrectly() throws Exception {
|
||||
|
||||
Page<User> page =
|
||||
userRepository
|
||||
.findByFirstname(new PageRequest(0, 20), "foobar");
|
||||
userRepository.findByFirstname(new PageRequest(0, 1), "foobar");
|
||||
assertEquals(1, page.getNumberOfElements());
|
||||
}
|
||||
|
||||
@@ -127,8 +127,7 @@ public class UserRepositoryFinderTests {
|
||||
public void executesPagingMethodToListCorrectly() throws Exception {
|
||||
|
||||
List<User> list =
|
||||
userRepository
|
||||
.findByFirstname("foobar", new PageRequest(0, 20));
|
||||
userRepository.findByFirstname("foobar", new PageRequest(0, 1));
|
||||
assertThat(list.size(), is(1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user