diff --git a/src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc b/src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc index aa6adb340..a1cf078a3 100644 --- a/src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc +++ b/src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc @@ -7,7 +7,7 @@ You can define simple sorting expressions by using property names and define sta You can concatenate expressions to collect multiple criteria into one expression. Scroll queries return a `Window` that allows obtaining the element's scroll position to fetch the next `Window` until your application has consumed the entire query result. -Similar to consuming a Java `Iterator>` by obtaining the next batch of results, query result scrolling lets you access the a `ScrollPosition` through `Window.positionAt(...)`. +Similar to consuming a Java `Iterator>` by obtaining the next batch of results, query result scrolling lets you access the a `ScrollPosition` through `Window.positionAt(…)`, as in the following example: [source,java] ---- @@ -18,9 +18,13 @@ do { // consume the user } + if (users.isLast() || users.isEmpty()) { + break; + } + // obtain the next Scroll users = repository.findFirst10ByLastnameOrderByFirstname("Doe", users.positionAt(users.size() - 1)); -} while (!users.isEmpty() && users.hasNext()); +} while (!users.isEmpty()); ---- [NOTE] @@ -38,6 +42,8 @@ In a similar way, providing a `Limit` object allows you to define a dynamic limi Read more on dynamic sorting and limiting in the xref:repositories/query-methods-details.adoc#repositories.special-parameters[Query Methods Details]. ==== +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`. + `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`. [source,java]