@@ -102,7 +102,11 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
|
||||
|
||||
if (scrollPosition instanceof OffsetScrollPosition osp) {
|
||||
|
||||
Query query = createQuery().sort(getSort()).offset(osp.getOffset());
|
||||
Query query = createQuery().sort(getSort());
|
||||
|
||||
if (!osp.isInitial()) {
|
||||
query = query.offset(osp.getOffset() + 1);
|
||||
}
|
||||
|
||||
if (getLimit() > 0) {
|
||||
query = query.limit(getLimit());
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ScrollDelegate {
|
||||
List<T> result = queryFunction.apply(query);
|
||||
|
||||
if (scrollPosition instanceof OffsetScrollPosition offset) {
|
||||
return createWindow(result, limit, OffsetScrollPosition.positionFunction(offset.getOffset()));
|
||||
return createWindow(result, limit, offset.positionFunction());
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("ScrollPosition " + scrollPosition + " not supported");
|
||||
|
||||
@@ -1137,7 +1137,7 @@ public class JdbcRepositoryIntegrationTests {
|
||||
assertThat(first.map(DummyEntity::getName)).containsExactly("one", "three");
|
||||
|
||||
Window<DummyEntity> second = repository.findBy(example, q -> q.limit(2).sortBy(Sort.by("name")))
|
||||
.scroll(ScrollPosition.offset(2));
|
||||
.scroll(ScrollPosition.offset(1));
|
||||
assertThat(second.map(DummyEntity::getName)).containsExactly("two");
|
||||
|
||||
WindowIterator<DummyEntity> iterator = WindowIterator.of(
|
||||
|
||||
@@ -409,7 +409,11 @@ public class SimpleR2dbcRepository<T, ID> implements R2dbcRepository<T, ID> {
|
||||
int limit = getLimit();
|
||||
return createQuery(q -> {
|
||||
|
||||
Query queryToUse = q.offset(osp.getOffset());
|
||||
Query queryToUse = q;
|
||||
|
||||
if (!osp.isInitial()) {
|
||||
queryToUse = queryToUse.offset(osp.getOffset() + 1);
|
||||
}
|
||||
|
||||
if (limit > 0) {
|
||||
queryToUse = queryToUse.limit(limit + 1);
|
||||
@@ -419,8 +423,7 @@ public class SimpleR2dbcRepository<T, ID> implements R2dbcRepository<T, ID> {
|
||||
}).all() //
|
||||
.collectList() //
|
||||
.map(content -> {
|
||||
return ScrollDelegate.createWindow(content, limit,
|
||||
OffsetScrollPosition.positionFunction(osp.getOffset()));
|
||||
return ScrollDelegate.createWindow(content, limit, osp.positionFunction());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user