Package st.orm

Record Class Window<R>

Type Parameters:
R - the result type (e.g., User for entity queries, Ref<User> for ref queries).
Record Components:
content - the list of results in this window; never contains null elements.
hasNext - true if more results existed beyond this window in the scroll direction at query time.
hasPrevious - true if this window was fetched with a cursor position (i.e., not the first page).
nextScrollable - the scrollable to fetch the next window, or null if the window is empty.
previousScrollable - the scrollable to fetch the previous window, or null if the window is empty.
All Implemented Interfaces:
Slice<R>

public record Window<R>(@Nonnull List<R> content, boolean hasNext, boolean hasPrevious, @Nullable Scrollable<?> nextScrollable, @Nullable Scrollable<?> previousScrollable) extends Record implements Slice<R>
Represents a window of query results from a scrolling operation with Scrollable navigation tokens.

A Window implements Slice and provides cursor-based navigation for sequential traversal through large result sets. Use next() and previous() for typed programmatic navigation, or nextCursor() and previousCursor() for serialized cursor strings suitable for REST APIs.


 Window<User> window = userRepository.scroll(Scrollable.of(User_.id, 20));
 if (window.hasNext()) {
     Window<User> next = userRepository.scroll(window.next());
 }
 

The next() and previous() navigation tokens are always provided when the window has content, regardless of whether hasNext or hasPrevious is true. This allows developers to follow the cursor even when no more results were detected at query time, which is useful for polling scenarios where new data may appear after the initial query. The hasNext and hasPrevious flags are informational: they indicate whether more results existed at the time of the query, but the decision to follow the cursor is left to the developer.

Since:
1.11
  • Constructor Details

    • Window

      public Window(@Nonnull List<R> content, boolean hasNext, boolean hasPrevious, @Nullable Scrollable<?> nextScrollable, @Nullable Scrollable<?> previousScrollable)
      Creates an instance of a Window record class.
      Parameters:
      content - the value for the content record component
      hasNext - the value for the hasNext record component
      hasPrevious - the value for the hasPrevious record component
      nextScrollable - the value for the nextScrollable record component
      previousScrollable - the value for the previousScrollable record component
  • Method Details

    • empty

      public static <R> Window<R> empty()
      Returns an empty window with no content and no navigation tokens.
      Type Parameters:
      R - the result type.
      Returns:
      an empty window.
    • next

      @Nullable public <T extends Data> Scrollable<T> next()
      Returns a typed scrollable for fetching the next window, or null if the window is empty.

      The type parameter T is inferred from the call-site context, typically from the scroll(Scrollable<T>) method parameter:

      
       Window<User> next = userRepository.scroll(window.next());
       
      Type Parameters:
      T - the data type, inferred from context.
      Returns:
      the scrollable for the next window, or null.
    • previous

      @Nullable public <T extends Data> Scrollable<T> previous()
      Returns a typed scrollable for fetching the previous window, or null if the window is empty.

      The type parameter T is inferred from the call-site context, typically from the scroll(Scrollable<T>) method parameter:

      
       Window<User> prev = userRepository.scroll(window.previous());
       
      Type Parameters:
      T - the data type, inferred from context.
      Returns:
      the scrollable for the previous window, or null.
    • nextCursor

      @Nullable public String nextCursor()
      Returns an opaque cursor string for fetching the next window, or null if there is no next window according to hasNext().

      This method is a convenience for REST APIs that want to include a cursor only when more results were detected. For polling or streaming use cases where you want to follow the cursor regardless, use next() directly.

      Returns:
      the cursor string, or null.
      See Also:
    • previousCursor

      @Nullable public String previousCursor()
      Returns an opaque cursor string for fetching the previous window, or null if this is the first window according to hasPrevious().

      This method is a convenience for REST APIs that want to include a cursor only when previous results exist. For use cases where you want to follow the cursor regardless, use previous() directly.

      Returns:
      the cursor string, or null.
      See Also:
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • content

      @Nonnull public List<R> content()
      Returns the value of the content record component.
      Specified by:
      content in interface Slice<R>
      Returns:
      the value of the content record component
    • hasNext

      public boolean hasNext()
      Returns the value of the hasNext record component.
      Specified by:
      hasNext in interface Slice<R>
      Returns:
      the value of the hasNext record component
    • hasPrevious

      public boolean hasPrevious()
      Returns the value of the hasPrevious record component.
      Specified by:
      hasPrevious in interface Slice<R>
      Returns:
      the value of the hasPrevious record component
    • nextScrollable

      @Nullable public Scrollable<?> nextScrollable()
      Returns the value of the nextScrollable record component.
      Returns:
      the value of the nextScrollable record component
    • previousScrollable

      @Nullable public Scrollable<?> previousScrollable()
      Returns the value of the previousScrollable record component.
      Returns:
      the value of the previousScrollable record component