|
24 | 24 | import org.springframework.context.ApplicationContext;
|
25 | 25 | import org.springframework.context.ApplicationEventPublisher;
|
26 | 26 | import org.springframework.data.domain.Page;
|
27 |
| -import org.springframework.data.domain.PageImpl; |
28 | 27 | import org.springframework.data.domain.Pageable;
|
29 | 28 | import org.springframework.data.domain.Sort;
|
30 | 29 | import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
|
|
39 | 38 | import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
40 | 39 | import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
41 | 40 | import org.springframework.data.relational.core.mapping.event.*;
|
| 41 | +import org.springframework.data.support.PageableExecutionUtils; |
42 | 42 | import org.springframework.lang.Nullable;
|
43 | 43 | import org.springframework.util.Assert;
|
44 | 44 |
|
|
50 | 50 | * @author Thomas Lang
|
51 | 51 | * @author Christoph Strobl
|
52 | 52 | * @author Milan Milanov
|
| 53 | + * @author Myeonghyeon Lee |
53 | 54 | */
|
54 | 55 | public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
55 | 56 |
|
@@ -248,10 +249,9 @@ public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
|
248 | 249 | Assert.notNull(domainType, "Domain type must not be null!");
|
249 | 250 |
|
250 | 251 | 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()); |
252 | 253 |
|
253 |
| - return new PageImpl<>(StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList()), pageable, |
254 |
| - totalCount); |
| 254 | + return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(domainType)); |
255 | 255 | }
|
256 | 256 |
|
257 | 257 | /*
|
|
0 commit comments