Polishing.

Introduce method to obtain a position function from OffsetScrollPosition. Tweak documentation wording.

See #3070
Original pull request: #3072
This commit is contained in:
Mark Paluch
2024-04-10 10:41:04 +02:00
parent eb184669db
commit 855194a13d
2 changed files with 18 additions and 7 deletions

View File

@@ -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]
@@ -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`.
@@ -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]]

View File

@@ -24,7 +24,8 @@ import org.springframework.util.Assert;
/**
* 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
@@ -69,7 +70,7 @@ public final class OffsetScrollPosition implements ScrollPosition {
}
/**
* 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.
@@ -81,6 +82,16 @@ public final class OffsetScrollPosition implements ScrollPosition {
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>