Class ResultCursor

java.lang.Object
dev.grafeo.gwp.ResultCursor
All Implemented Interfaces:
AutoCloseable, Iterator<List<Object>>

public class ResultCursor extends Object implements Iterator<List<Object>>, AutoCloseable
Cursor over streaming result frames from an Execute RPC.

Implements Iterator over rows (each row is a List<Object>) and AutoCloseable for use with try-with-resources.

This is a blocking cursor. Rows are consumed from the gRPC response stream on demand. The cursor buffers rows from each RowBatch frame.

  • Constructor Details

    • ResultCursor

      public ResultCursor(Iterator<GqlServiceOuterClass.ExecuteResponse> stream)
      Create a new ResultCursor wrapping a gRPC response stream.
      Parameters:
      stream - the response stream iterator from an Execute RPC
  • Method Details

    • columnNames

      public List<String> columnNames()
      Get the column names from the result header.

      Consumes frames from the stream if the header has not been received yet.

      Returns:
      the list of column names, or an empty list if no header
    • nextRow

      public List<Object> nextRow()
      Get the next row. Returns null when there are no more rows.
      Returns:
      the next row as a list of native Java objects, or null if done
    • collectRows

      public List<List<Object>> collectRows()
      Collect all remaining rows into a list.
      Returns:
      all remaining rows
    • summary

      public ResultCursor.ResultSummary summary()
      Get the result summary. Consumes all remaining frames if needed.
      Returns:
      the result summary, or null if the stream ended without one
    • isSuccess

      public boolean isSuccess()
      Check if the execution was successful.
      Returns:
      true if the result summary indicates success
    • rowsAffected

      public long rowsAffected()
      Get the number of rows affected.
      Returns:
      the row count, or 0 if no summary
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<List<Object>>
    • next

      public List<Object> next()
      Specified by:
      next in interface Iterator<List<Object>>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable