Skip to content

Commit 619e4d6

Browse files
committed
Align OffsetScrolling to zero-based indexes.
Closes #1764
1 parent ad8ca20 commit 619e4d6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/FetchableFluentQueryByExample.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ public Window<R> scroll(ScrollPosition scrollPosition) {
102102

103103
if (scrollPosition instanceof OffsetScrollPosition osp) {
104104

105-
Query query = createQuery().sort(getSort()).offset(osp.getOffset());
105+
Query query = createQuery().sort(getSort());
106+
107+
if (!osp.isInitial()) {
108+
query.offset(osp.getOffset() + 1);
109+
}
106110

107111
if (getLimit() > 0) {
108112
query = query.limit(getLimit());

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/ScrollDelegate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static <T> Window<T> scroll(Query query, Function<Query, List<T>> queryFu
5454
List<T> result = queryFunction.apply(query);
5555

5656
if (scrollPosition instanceof OffsetScrollPosition offset) {
57-
return createWindow(result, limit, OffsetScrollPosition.positionFunction(offset.getOffset()));
57+
return createWindow(result, limit, offset.positionFunction());
5858
}
5959

6060
throw new UnsupportedOperationException("ScrollPosition " + scrollPosition + " not supported");

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ public Mono<Window<T>> scroll(ScrollPosition scrollPosition) {
409409
int limit = getLimit();
410410
return createQuery(q -> {
411411

412-
Query queryToUse = q.offset(osp.getOffset());
412+
Query queryToUse = q;
413+
414+
if (!osp.isInitial()) {
415+
queryToUse = queryToUse.offset(osp.getOffset() + 1);
416+
}
413417

414418
if (limit > 0) {
415419
queryToUse = queryToUse.limit(limit + 1);
@@ -419,8 +423,7 @@ public Mono<Window<T>> scroll(ScrollPosition scrollPosition) {
419423
}).all() //
420424
.collectList() //
421425
.map(content -> {
422-
return ScrollDelegate.createWindow(content, limit,
423-
OffsetScrollPosition.positionFunction(osp.getOffset()));
426+
return ScrollDelegate.createWindow(content, limit, osp.positionFunction());
424427
});
425428
}
426429

0 commit comments

Comments
 (0)