Skip to content

Commit 673a4df

Browse files
committed
Fix positionFunction created by ScrollDelegate
Before this commit, positionFunction created by ScrollDelegate retains incorrect state when perform backward scrolling. 1. We must use window.positionAt(1) instead of window.positionAt(0) if we want position at the begin of window, we should call getResultWindow() first. 2. The direction always be FORWARD, it should be BACKWARD if the original direction is BACKWARD. Closes spring-projectsGH-2999
1 parent 8cae8cd commit 673a4df

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ScrollDelegate.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* Delegate to run {@link ScrollPosition scroll queries} and create result {@link Window}.
3636
*
3737
* @author Mark Paluch
38+
* @author Yanming Zhou
3839
* @since 3.1
3940
*/
4041
public class ScrollDelegate<T> {
@@ -80,17 +81,17 @@ private static <T> Window<T> createWindow(Sort sort, int limit, Direction direct
8081
JpaEntityInformation<T, ?> entity, List<T> result) {
8182

8283
KeysetScrollDelegate delegate = KeysetScrollDelegate.of(direction);
83-
List<T> resultsToUse = delegate.postProcessResults(result);
84+
List<T> resultsToUse = delegate.getResultWindow(delegate.postProcessResults(result), limit);
8485

8586
IntFunction<ScrollPosition> positionFunction = value -> {
8687

87-
T object = result.get(value);
88+
T object = resultsToUse.get(value);
8889
Map<String, Object> keys = entity.getKeyset(sort.stream().map(Order::getProperty).toList(), object);
8990

90-
return ScrollPosition.forward(keys);
91+
return ScrollPosition.of(keys, direction);
9192
};
9293

93-
return Window.from(delegate.getResultWindow(resultsToUse, limit), positionFunction, hasMoreElements(result, limit));
94+
return Window.from(resultsToUse, positionFunction, hasMoreElements(result, limit));
9495
}
9596

9697
private static <T> Window<T> createWindow(List<T> result, int limit,

0 commit comments

Comments
 (0)