Class TableCursor<T,R>

java.lang.Object
com.datastax.astra.client.tables.cursor.TableCursor<T,R>
Type Parameters:
T - working bean of parent table
R - working bean returned for the find
All Implemented Interfaces:
Closeable, AutoCloseable, Cloneable, Iterable<R>

public class TableCursor<T,R> extends Object implements Iterable<R>, Closeable, Cloneable
Implementation of a cursor across the find items
  • Constructor Details

    • TableCursor

      public TableCursor(Table<T> table, Filter filter, TableFindOptions options, Class<R> rowType)
      Cursor to iterate on the result of a query.
      Parameters:
      table - source table
      filter - current filter
      options - options of the find operation
      rowType - row type returned with the cursor
  • Method Details

    • clone

      public TableCursor<T,R> clone()
      Overrides:
      clone in class Object
    • filter

      public TableCursor<T,R> filter(Filter newFilter)
      Immutable methods that return a new Cursor instance.
      Parameters:
      newFilter - a new filter
      Returns:
      a new cursor
    • project

      public TableCursor<T,R> project(Projection... newProjection)
      Creates a new TableCursor with an updated projection.
      Parameters:
      newProjection - the new projection to apply
      Returns:
      a new TableCursor instance with the specified projection
    • sort

      public TableCursor<T,R> sort(Sort... sort)
      Creates a new TableCursor with a specified sort order.
      Parameters:
      sort - the sort criteria to apply
      Returns:
      a new TableCursor instance with the specified sort order
    • limit

      public TableCursor<T,R> limit(int newLimit)
      Creates a new TableCursor with a specified limit on the number of results.
      Parameters:
      newLimit - the maximum number of results to retrieve
      Returns:
      a new TableCursor instance with the specified limit
    • skip

      public TableCursor<T,R> skip(int newSkip)
      Creates a new TableCursor that skips a specified number of results.
      Parameters:
      newSkip - the number of results to skip
      Returns:
      a new TableCursor instance with the specified skip value
    • includeSimilarity

      public TableCursor<T,R> includeSimilarity()
      Creates a new TableCursor that includes similarity scores in the results.
      Returns:
      a new TableCursor instance with similarity scores included
    • includeSortVector

      public TableCursor<T,R> includeSortVector()
      Creates a new TableCursor that includes sort vector metadata in the results.
      Returns:
      a new TableCursor instance with sort vector metadata included
    • close

      public void close()
      Change the state of the cursor to close.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • consumeBuffer

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

      public Iterator<R> iterator()
      Iterate over the cursor.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      iterator over the results
    • 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
    • getBufferedCount

      public int getBufferedCount()
      Access the size of the buffer.
      Returns:
      buffer count
    • getKeyspace

      public String getKeyspace()
      Retrieve keyspace name.
      Returns:
      keyspace name
    • getSortVector

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