DATAJPA-77 - Count queries for manually defined queries don't get pagination applied anymore.
This commit is contained in:
@@ -101,7 +101,7 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
|
||||
@Override
|
||||
protected Query createCountQuery(Object[] values) {
|
||||
|
||||
return createBinder(values).bindAndPrepare(
|
||||
return createBinder(values).bind(
|
||||
applyHints(getEntityManager().createQuery(countQuery)));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.QueryHints;
|
||||
import org.springframework.data.jpa.repository.sample.UserRepository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
@@ -55,6 +58,8 @@ public class SimpleJpaQueryUnitTests {
|
||||
Query query;
|
||||
@Mock
|
||||
RepositoryMetadata metadata;
|
||||
@Mock
|
||||
ParameterBinder binder;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -96,4 +101,26 @@ public class SimpleJpaQueryUnitTests {
|
||||
|
||||
assertThat(jpaQuery.createCountQuery(new Object[] {}), is(query));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DATAJPA-77
|
||||
*/
|
||||
@Test
|
||||
public void doesNotApplyPaginationToCountQuery() throws Exception {
|
||||
|
||||
when(em.createQuery(Mockito.anyString())).thenReturn(query);
|
||||
|
||||
Method method =
|
||||
UserRepository.class.getMethod("findAllPaged", Pageable.class);
|
||||
JpaQueryMethod queryMethod =
|
||||
new JpaQueryMethod(method, metadata, extractor);
|
||||
|
||||
AbstractJpaQuery jpaQuery =
|
||||
new SimpleJpaQuery(queryMethod, em, "select u from User u");
|
||||
jpaQuery.createCountQuery(new Object[] { new PageRequest(1, 10) });
|
||||
|
||||
verify(query, times(0)).setFirstResult(anyInt());
|
||||
verify(query, times(0)).setMaxResults(anyInt());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user