Skip to content

DATAJPA-1635 - Removed superfluous logic from evaluation of count query. #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.3.0.BUILD-SNAPSHOT</version>
<version>2.3.0.DATAJPA-1635-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ protected Object doExecute(final AbstractJpaQuery repositoryQuery, JpaParameters

private long count(AbstractJpaQuery repositoryQuery, JpaParametersParameterAccessor accessor) {

List<?> totals = repositoryQuery.createCountQuery(accessor).getResultList();
return (totals.size() == 1 ? CONVERSION_SERVICE.convert(totals.get(0), Long.class) : totals.size());
return CONVERSION_SERVICE.convert(repositoryQuery.createCountQuery(accessor).getSingleResult(), Long.class);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.query.JpaQueryExecution.ModifyingExecution;
Expand Down Expand Up @@ -147,14 +146,14 @@ public void pagedExecutionRetrievesObjectsForPageableOutOfRange() throws Excepti
JpaParameters parameters = new JpaParameters(getClass().getMethod("sampleMethod", Pageable.class));
when(jpaQuery.createCountQuery(Mockito.any())).thenReturn(countQuery);
when(jpaQuery.createQuery(Mockito.any())).thenReturn(query);
when(countQuery.getResultList()).thenReturn(Arrays.asList(20L));
when(countQuery.getSingleResult()).thenReturn(20L);

PagedExecution execution = new PagedExecution();
execution.doExecute(jpaQuery,
new JpaParametersParameterAccessor(parameters, new Object[] { PageRequest.of(2, 10) }));

verify(query).getResultList();
verify(countQuery).getResultList();
verify(countQuery).getSingleResult();
}

@Test // DATAJPA-477, DATAJPA-912
Expand Down Expand Up @@ -207,8 +206,8 @@ public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHit
JpaParameters parameters = new JpaParameters(getClass().getMethod("sampleMethod", Pageable.class));
when(jpaQuery.createQuery(Mockito.any())).thenReturn(query);
when(query.getResultList()).thenReturn(Collections.emptyList());
when(jpaQuery.createCountQuery(Mockito.any())).thenReturn(query);
when(countQuery.getResultList()).thenReturn(Arrays.asList(20L));
when(jpaQuery.createCountQuery(Mockito.any())).thenReturn(countQuery);
when(countQuery.getSingleResult()).thenReturn(20L);

PagedExecution execution = new PagedExecution();
execution.doExecute(jpaQuery,
Expand All @@ -224,8 +223,8 @@ public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHit
JpaParameters parameters = new JpaParameters(getClass().getMethod("sampleMethod", Pageable.class));
when(jpaQuery.createQuery(Mockito.any())).thenReturn(query);
when(query.getResultList()).thenReturn(Arrays.asList(new Object(), new Object(), new Object(), new Object()));
when(jpaQuery.createCountQuery(Mockito.any())).thenReturn(query);
when(countQuery.getResultList()).thenReturn(Arrays.asList(20L));
when(jpaQuery.createCountQuery(Mockito.any())).thenReturn(countQuery);
when(countQuery.getSingleResult()).thenReturn(20L);

PagedExecution execution = new PagedExecution();
execution.doExecute(jpaQuery,
Expand Down