File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
main/java/org/springframework/data/jdbc/repository/query
test/java/org/springframework/data/jdbc/repository Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -350,8 +350,11 @@ SelectBuilder.SelectWhere applyLimitAndOffset(SelectBuilder.SelectLimitOffset li
350350 }
351351
352352 if (mode == Mode .SCROLL && scrollPosition != null && scrollPosition instanceof OffsetScrollPosition
353- && !scrollPosition .isInitial ())
354- limitOffsetBuilder = limitOffsetBuilder .offset (((OffsetScrollPosition ) scrollPosition ).getOffset () + 1 );
353+ && !scrollPosition .isInitial ()) {
354+ int pageSize = limit .isLimited () ? limit .max () : Integer .MAX_VALUE ;
355+
356+ limitOffsetBuilder = limitOffsetBuilder .offset (((OffsetScrollPosition ) scrollPosition ).getOffset () * pageSize );
357+ }
355358
356359 return (SelectBuilder .SelectWhere ) limitOffsetBuilder ;
357360 }
Original file line number Diff line number Diff line change @@ -1577,6 +1577,23 @@ void queryByWindowKeySetTwoKeys() {
15771577 assertThat (entities ).extracting ("idProp" ).contains (five .idProp );
15781578 }
15791579
1580+ @ Test
1581+ void queryByWindowOffsetPosition () {
1582+ DummyEntity one = repository .save (createEntity ("one" , it -> it .setPointInTime (Instant .ofEpochSecond (1000 ))));
1583+ DummyEntity two = repository .save (createEntity ("two" , it -> it .setPointInTime (Instant .ofEpochSecond (2000 ))));
1584+ DummyEntity three = repository .save (createEntity ("three" , it -> it .setPointInTime (Instant .ofEpochSecond (3000 ))));
1585+
1586+ Window <DummyEntity > result = repository .findFirst2ByOrderByIdPropAsc (ScrollPosition .offset ());
1587+ assertSoftly (softAssertions -> {
1588+ softAssertions .assertThat (result .hasNext ()).isTrue ();
1589+ softAssertions .assertThat (result .size ()).isEqualTo (2 );
1590+
1591+ ScrollPosition position = result .positionAt (1 );
1592+ softAssertions .assertThat (position .isInitial ()).isFalse ();
1593+ softAssertions .assertThat (((OffsetScrollPosition ) position ).getOffset ()).isEqualTo (1 );
1594+ });
1595+ }
1596+
15801597 private Root createRoot (String namePrefix ) {
15811598
15821599 return new Root (null , namePrefix ,
You can’t perform that action at this time.
0 commit comments