Class AbstractCursor<T,R>

java.lang.Object
com.datastax.astra.internal.command.AbstractCursor<T,R>
Type Parameters:
T - working bean of parent table
R - working bean returned for the find
All Implemented Interfaces:
Cloneable, Iterable<R>
Direct Known Subclasses:
CollectionFindAndRerankCursor, CollectionFindCursor, TableFindCursor

public abstract class AbstractCursor<T,R> extends Object implements Iterable<R>, Cloneable
Implementation of a cursor across the find items
  • Field Details

    • state

      protected CursorState state
      Cursor state.
    • buffer

      protected List<R> buffer
      Records to process
    • currentPage

      protected Page<R> currentPage
      Current page
    • consumed

      protected int consumed
      How many consumed in the current buffer.
    • recordType

      protected Class<R> recordType
      Type of the row to return
  • Constructor Details

    • AbstractCursor

      protected AbstractCursor(Class<R> recordType)
      Cursor to iterate on the result of a query.
      Parameters:
      recordType - row type returned with the cursor
  • Method Details

    • close

      public void close()
      Change the state of the cursor to close.
    • rewind

      public void rewind()
      Rewind the cursor to the beginning.
    • consumeBuffer

      public List<R> consumeBuffer(int n)
      Consume the buffer and return the list of items.
      Parameters:
      n - number of items to consume
      Returns:
      list of items
    • checkIdleState

      protected void checkIdleState()
      Validate that the cursor is in the IDLE state.
    • iterator

      public Iterator<R> iterator()
      Iterate over the cursor.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      iterator over the results
    • fetchNextBatch

      protected abstract void fetchNextBatch()
      Fetches the next batch of documents into the buffer. This method handles paging, using the page state from the previous batch to fetch the next one.
    • hasNext

      public boolean hasNext()
      Checks if there are more elements in the cursor.
      Returns:
      true if there are more elements, false otherwise
    • next

      public R next()
      Retrieves the next element from the cursor.
      Returns:
      the next element of type R
      Throws:
      NoSuchElementException - if no more elements are available
    • toList

      public List<R> toList()
      Collects all remaining elements in the cursor into a list. Automatically closes the cursor after all elements are consumed.
      Returns:
      a List containing all remaining elements
    • stream

      public Stream<R> stream()
      Convert the current cursor as a stream
      Returns:
      current as a stream
    • getBufferedSize

      public int getBufferedSize()
      Access the size of the buffer.
      Returns:
      buffer count
    • getSortVector

      public Optional<DataAPIVector> getSortVector()
      Access to the Sort Vector.
      Returns:
      sort vector