Browse Source

Refine raw Window scrolling documentation example.

Avoid skipping last batch, avoid out-of-bounds exception.

Closes #3352
Co-authored-by: r6hk <rennen0929@gmail.com>
pull/3357/head
Mark Paluch 3 months ago
parent
commit
46644b0f70
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 10
      src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc

10
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. You can concatenate expressions to collect multiple criteria into one expression.
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. 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.
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(...)`. 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:
[source,java] [source,java]
---- ----
@ -18,9 +18,13 @@ do {
// consume the user // consume the user
} }
if (users.isLast() || users.isEmpty()) {
break;
}
// obtain the next Scroll // obtain the next Scroll
users = repository.findFirst10ByLastnameOrderByFirstname("Doe", users.positionAt(users.size() - 1)); users = repository.findFirst10ByLastnameOrderByFirstname("Doe", users.positionAt(users.size() - 1));
} while (!users.isEmpty() && users.hasNext()); } while (!users.isEmpty());
---- ----
[NOTE] [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]. 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`. `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] [source,java]

Loading…
Cancel
Save