Skip to content

Commit 1e6f212

Browse files
mp911der6hk
andcommitted
Refine raw Window scrolling documentation example.
Avoid skipping last batch, avoid out-of-bounds exception. Closes #3352 Co-authored-by: r6hk <rennen0929@gmail.com>
1 parent 530a602 commit 1e6f212

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can define simple sorting expressions by using property names and define sta
77
You can concatenate expressions to collect multiple criteria into one expression.
88

99
Scroll queries return a `Window<T>` that allows obtaining the element's scroll position to fetch the next `Window<T>` until your application has consumed the entire query result.
10-
Similar to consuming a Java `Iterator<List<…>>` by obtaining the next batch of results, query result scrolling lets you access the a `ScrollPosition` through `Window.positionAt(...)`.
10+
Similar to consuming a Java `Iterator<List<…>>` by obtaining the next batch of results, query result scrolling lets you access the a `ScrollPosition` through `Window.positionAt(…)`, as in the following example:
1111

1212
[source,java]
1313
----
@@ -18,9 +18,13 @@ do {
1818
// consume the user
1919
}
2020
21+
if (users.isLast() || users.isEmpty()) {
22+
break;
23+
}
24+
2125
// obtain the next Scroll
2226
users = repository.findFirst10ByLastnameOrderByFirstname("Doe", users.positionAt(users.size() - 1));
23-
} while (!users.isEmpty() && users.hasNext());
27+
} while (!users.isEmpty());
2428
----
2529

2630
[NOTE]
@@ -38,6 +42,8 @@ In a similar way, providing a `Limit` object allows you to define a dynamic limi
3842
Read more on dynamic sorting and limiting in the xref:repositories/query-methods-details.adoc#repositories.special-parameters[Query Methods Details].
3943
====
4044

45+
Scrolling through consuming `Window` instances requires quite a few conditionals to reach optimum database round-trips and can quickly become a repetitive task that can be simplified using `WindowIterator`.
46+
4147
`WindowIterator` provides a utility to simplify scrolling across ``Window``s by removing the need to check for the presence of a next `Window` and applying the `ScrollPosition`.
4248

4349
[source,java]

0 commit comments

Comments
 (0)