Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Introduce method to obtain a position function from OffsetScrollPosition. Tweak documentation wording.

See spring-projects#3070
Original pull request: spring-projects#3072
  • Loading branch information
mp911de authored and app committed May 20, 2024
1 parent eb55c0d commit 890195e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Scrolling consists of a stable sort, a scroll type (Offset- or Keyset-based scro
You can define simple sorting expressions by using property names and define static result limiting using the xref:repositories/query-methods-details.adoc#repositories.limit-query-result[`Top` or `First` keyword] through query derivation.
You can concatenate expressions to collect multiple criteria into one expression.

Scroll queries return a `Window<T>` that allows obtaining the elements scroll position which can be used 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(...)`.

[source,java]
Expand All @@ -26,8 +26,8 @@ do {
[NOTE]
====
The `ScrollPosition` identifies the exact position of an element with the entire query result.
Query execution treats the position parameter as _exclusive_, which means results will start _after_ the given position.
`ScrollPosition#offset` and `ScrollPosition#keyset()` as special incarnations of a `ScrollPosition` indicating the start of a scroll operation.
Query execution treats the position parameter _exclusive_, results will start _after_ the given position.
`ScrollPosition#offset()` and `ScrollPosition#keyset()` as special incarnations of a `ScrollPosition` indicating the start of a scroll operation.
====

`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`.
Expand Down Expand Up @@ -69,8 +69,8 @@ WindowIterator<User> users = WindowIterator.of(position -> repository.findFirst1
[CAUTION]
====
There is a difference between `ScollPosition.offset()` and `ScollPosition.offset(0L)`.
The former indicates the start of scroll operation, pointing to no specific offset where as the latter identifies the first element (at position `0`) of the result.
Given the _exclusive_ nature of scrolling using `ScollPosition.offset(0)` will skip the first element and translate to an offset of 1.
The former indicates the start of scroll operation, pointing to no specific offset whereas the latter identifies the first element (at position `0`) of the result.
Given the _exclusive_ nature of scrolling, using `ScollPosition.offset(0)` skips the first element and translate to an offset of `1`.
====

[[repositories.scrolling.keyset]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
/**
* A {@link ScrollPosition} based on the offsets within query results.
* <p>
* An initial {@link OffsetScrollPosition} does not point to a specific element and is different to a the Po
* An initial {@link OffsetScrollPosition} does not point to a specific element and is different to a position
* {{@link ScrollPosition#offset(long)}.
*
* @author Mark Paluch
* @author Oliver Drotbohm
Expand Down Expand Up @@ -69,7 +70,7 @@ static OffsetScrollPosition of(long offset) {
}

/**
* Returns the {@link IntFunction position function} to calculate.
* Returns a {@link IntFunction position function} starting at {@code startOffset}.
*
* @param startOffset the start offset to be used. Must not be negative.
* @return the offset-based position function.
Expand All @@ -81,6 +82,16 @@ public static IntFunction<OffsetScrollPosition> positionFunction(long startOffse
return startOffset == 0 ? OffsetPositionFunction.ZERO : new OffsetPositionFunction(startOffset);
}

/**
* Returns the {@link IntFunction position function} starting after the current {@code offset}.
*
* @return the offset-based position function.
* @since 3.3
*/
public IntFunction<OffsetScrollPosition> positionFunction() {
return positionFunction(isInitial() ? 0 : getOffset() + 1);
}

/**
* The zero or positive offset.
* <p>
Expand Down

0 comments on commit 890195e

Please sign in to comment.