Class ChangeStreamResultSet

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ChangeStreamResultSet
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Decorator class over a ResultSet that provides telemetry for the streamed records. It will be returned for a change stream query. By using this class one can obtain the following metadata:
    • The timestamp at which the query first started.
    • The timestamp at which a record streaming started.
    • The timestamp at which a record streaming ended.
    • The timestamp at which a record was read by the caller.
    • The total time for streaming all records within the query.
    • The total number of records streamed within the query.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the current change stream ResultSet.
      com.google.cloud.spanner.Struct getCurrentRowAsStruct()
      Returns the record at the current pointer as a Struct.
      ChangeStreamResultSetMetadata getMetadata()
      Returns the gathered metadata for the change stream query so far.
      java.lang.String getPgJsonb​(int index)
      Returns the record at the current pointer as JsonB.
      boolean next()
      Moves the pointer to the next record in the ResultSet if there is one.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • next

        public boolean next()
        Moves the pointer to the next record in the ResultSet if there is one. It also gathers metrics for the next record, such as:
        • If this is the first record consumed, updates the time at which the query started.
        • The timestamp at which a record streaming started.
        • The timestamp at which a record streaming ended.
        • Increments the total time for streaming the all the records so far.
        • Increments the total number of all the records streamed so far.
        Returns:
        true if there is another record within the result set. Returns false otherwise.
      • getCurrentRowAsStruct

        public com.google.cloud.spanner.Struct getCurrentRowAsStruct()
        Returns the record at the current pointer as a Struct. It also updates the timestamp at which the record was read.

        If next() was not called or if it was called but there are no more records in the stream, null will be returned.

        Should only be used for GoogleSQL databases.

        Returns:
        a change stream record as a Struct or null
      • getPgJsonb

        public java.lang.String getPgJsonb​(int index)
        Returns the record at the current pointer as JsonB. It also updates the timestamp at which the record was read.

        If next() was not called or if it was called but there are no more records in the stream, null will be returned.

        Should only be used for PostgreSQL databases.

        Returns:
        a change stream record as a Struct or null
      • close

        public void close()
        Closes the current change stream ResultSet. The stream will be terminated when this method is called.

        This method must always be called after the consumption of the result set or when an error occurs. This makes sure there are no Session leaks and all the underlying resources are released.

        Specified by:
        close in interface java.lang.AutoCloseable