-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keyset positionFunction does not retain directional state and uses position of one-off #2999
Labels
type: bug
A general bug
Milestone
Comments
quaff
added a commit
to quaff/spring-data-jpa
that referenced
this issue
Jun 6, 2023
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
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged
label
Jun 6, 2023
Scrolling forward after retrieving a window is by design as the |
It's weird that I cannot using @ParameterizedTest
@MethodSource("provideParameters")
void keysetScrolling(Sort.Direction sortDirection, ScrollPosition.Direction scrollDirection) {
List<List<TestEntity>> contents = new ArrayList<>();
String propertyName = "index";
Object anchor = null;
Sort sort = Sort.by(sortDirection, propertyName);
Map<String, ?> keys = anchor != null ? Map.of(propertyName, anchor) : Map.of();
ScrollPosition pos = ScrollPosition.of(keys, scrollDirection);
while (true) {
ScrollPosition spToUse = pos;
Window<TestEntity> window = this.repository.findBy((root, query, cb) -> {
return null;
}, q -> q.limit(pageSize).sortBy(sort).scroll(spToUse));
contents.add(window.getContent());
if (!window.hasNext()) {
break;
}
pos = window.positionAt(((KeysetScrollPosition) pos).scrollsForward() ? window.size() - 1 : 0);
}
// asserts
}
private static Stream<Arguments> provideParameters() {
return cartesian(Sort.Direction.class, ScrollPosition.Direction.class);
}
private static Stream<Arguments> cartesian(Class<? extends Enum<?>> enumA, Class<? extends Enum<?>> enumB) {
return Stream.of(enumA.getEnumConstants())
.flatMap(a -> Stream.of(enumB.getEnumConstants()).map(b -> Arguments.of(a, b)));
} |
mp911de
changed the title
positionFunction created by ScrollDelegate retains incorrect state when perform backward scrolling
Keyset positionFunction does not retain directional state and uses position of one-off
Jun 13, 2023
mp911de
added
type: bug
A general bug
and removed
status: waiting-for-triage
An issue we've not yet triaged
labels
Jun 13, 2023
mp911de
added a commit
that referenced
this issue
Jun 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
spring-data-jpa/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ScrollDelegate.java
Line 87 in 8cae8cd
We must use
window.positionAt(1)
instead ofwindow.positionAt(0)
if we want position at the begin of window, we should callgetResultWindow()
first.spring-data-jpa/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ScrollDelegate.java
Line 90 in 8cae8cd
The direction always be
FORWARD
, it should beBACKWARD
if the original direction isBACKWARD
.The text was updated successfully, but these errors were encountered: