DATACMNS-713 - PageImpl now adapts total if necessary.
On a last page the total handed into a PageImpl constructor might not necessarily fit the content as there's the change of an insertion or deletion between the calculated count and the retrieval of the content. We now leniently mitigate those differences if the page created is the last page of the result. Related tickets: DATAJPA-728, DATACMNS-615.
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.data.domain;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Basic {@code Page} implementation.
|
||||
@@ -38,16 +37,16 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
|
||||
*
|
||||
* @param content the content of this page, must not be {@literal null}.
|
||||
* @param pageable the paging information, can be {@literal null}.
|
||||
* @param total the total amount of items available
|
||||
* @param total the total amount of items available. The total might be adapted considering the length of the content
|
||||
* given, if it is going to be the content of the last page. This is in place to mitigate inconsistencies
|
||||
*/
|
||||
public PageImpl(List<T> content, Pageable pageable, long total) {
|
||||
|
||||
super(content, pageable);
|
||||
|
||||
Assert.isTrue(total >= content.size(), "Total must not be less than the number of elements given!");
|
||||
|
||||
this.total = total;
|
||||
this.pageable = pageable;
|
||||
this.total = pageable != null && pageable.getOffset() + pageable.getPageSize() > total
|
||||
? pageable.getOffset() + content.size() : total;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user