Skip to content

Commit 33d040a

Browse files
mhyeon-leeschauder
mhyeon-lee
authored andcommitted
DATAJDBC-531 - Skip COUNT query when current page is the last page.
Original pull request: #211.
1 parent 9128ea7 commit 33d040a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.context.ApplicationContext;
2525
import org.springframework.context.ApplicationEventPublisher;
2626
import org.springframework.data.domain.Page;
27-
import org.springframework.data.domain.PageImpl;
2827
import org.springframework.data.domain.Pageable;
2928
import org.springframework.data.domain.Sort;
3029
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
@@ -39,6 +38,7 @@
3938
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4039
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4140
import org.springframework.data.relational.core.mapping.event.*;
41+
import org.springframework.data.support.PageableExecutionUtils;
4242
import org.springframework.lang.Nullable;
4343
import org.springframework.util.Assert;
4444

@@ -50,6 +50,7 @@
5050
* @author Thomas Lang
5151
* @author Christoph Strobl
5252
* @author Milan Milanov
53+
* @author Myeonghyeon Lee
5354
*/
5455
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
5556

@@ -248,10 +249,9 @@ public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
248249
Assert.notNull(domainType, "Domain type must not be null!");
249250

250251
Iterable<T> items = triggerAfterLoad(accessStrategy.findAll(domainType, pageable));
251-
long totalCount = accessStrategy.count(domainType);
252+
List<T> content = StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList());
252253

253-
return new PageImpl<>(StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList()), pageable,
254-
totalCount);
254+
return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(domainType));
255255
}
256256

257257
/*

0 commit comments

Comments
 (0)