Interface StructReader

  • All Known Subinterfaces:
    AsyncResultSet, ResultSet
    All Known Implementing Classes:
    AbstractStructReader, ForwardingAsyncResultSet, ForwardingResultSet, ForwardingStructReader, Struct

    public interface StructReader
    A base interface for reading the fields of a STRUCT. The Cloud Spanner yields StructReader instances as one of the subclasses ResultSet or Struct, most commonly as the result of a read or query operation. At any point in time, a StructReader provides access to a single tuple of data comprising multiple typed columns. Each column may have a NULL or non-NULL value; in both cases, columns always have a type.

    Column values are accessed using the getTypeName() methods; a set of methods exists for each Java type that a column may be read as, and depending on the type of the column, only a subset of those methods will be appropriate. For example, getString(int) and getString(String) exist for reading columns of type Type.string(); attempting to call those methods for columns of other types will result in an IllegalStateException. The getTypeName() methods should only be called for non-NULL values, otherwise a NullPointerException is raised; isNull(int)/isNull(String) can be used to test for NULL-ness if necessary.

    All methods for accessing a column have overloads that accept an int column index and a String column name. Column indices are zero-based. The column name overloads will fail with IllegalArgumentException if the column name does not appear exactly once in this instance's getType(). The int overloads are typically more efficient than their String counterparts.

    StructReader itself does not define whether the implementing type is mutable or immutable. For example, ResultSet is a mutable implementation of StructReader, where the StructReader methods provide access to the row that the result set is currently positioned over and ResultSet.next() changes that view to the next row, whereas Struct is an immutable implementation of StructReader.

    • Method Detail

      • getType

        Type getType()
        Returns the type of the underlying data. This will always be a STRUCT type, with fields corresponding to the data's columns. For the result of a read or query, this will always match the columns passed to the read() call or named in the query text, in order.
      • getColumnCount

        int getColumnCount()
        Returns the number of columns in the underlying data. This includes any columns with NULL values.
      • getColumnType

        Type getColumnType​(int columnIndex)
        Returns the type of a column.
      • getColumnType

        Type getColumnType​(String columnName)
        Returns the type of a column.
      • isNull

        boolean isNull​(int columnIndex)
        Returns true if a column contains a NULL value.
      • isNull

        boolean isNull​(String columnName)
        Returns true if a column contains a NULL value.
      • getBoolean

        boolean getBoolean​(int columnIndex)
        Returns the value of a non-NULL column with type Type.bool().
      • getBoolean

        boolean getBoolean​(String columnName)
        Returns the value of a non-NULL column with type Type.bool().
      • getLong

        long getLong​(int columnIndex)
        Returns the value of a non-NULL column with type Type.int64().
      • getLong

        long getLong​(String columnName)
        Returns the value of a non-NULL column with type Type.int64().
      • getDouble

        double getDouble​(int columnIndex)
        Returns the value of a non-NULL column with type Type.float64().
      • getDouble

        double getDouble​(String columnName)
        Returns the value of a non-NULL column with type Type.float64().
      • getBigDecimal

        BigDecimal getBigDecimal​(int columnIndex)
        Returns the value of a non-NULL column with type Type.numeric().
      • getString

        String getString​(int columnIndex)
        Returns the value of a non-NULL column with type Type.string().
      • getJson

        default String getJson​(int columnIndex)
        Returns the value of a non-NULL column with type Type.string().
      • getBytes

        com.google.cloud.ByteArray getBytes​(int columnIndex)
        Returns the value of a non-NULL column with type Type.bytes().
      • getBytes

        com.google.cloud.ByteArray getBytes​(String columnName)
        Returns the value of a non-NULL column with type Type.bytes().
      • getTimestamp

        com.google.cloud.Timestamp getTimestamp​(int columnIndex)
        Returns the value of a non-NULL column with type Type.timestamp().
      • getTimestamp

        com.google.cloud.Timestamp getTimestamp​(String columnName)
        Returns the value of a non-NULL column with type Type.timestamp().
      • getDate

        com.google.cloud.Date getDate​(int columnIndex)
        Returns the value of a non-NULL column with type Type.date().
      • getDate

        com.google.cloud.Date getDate​(String columnName)
        Returns the value of a non-NULL column with type Type.date().
      • getValue

        default Value getValue​(int columnIndex)
        Returns the value of a nullable column as a Value.
      • getValue

        default Value getValue​(String columnName)
        Returns the value of a nullable column as a Value.
      • getBooleanArray

        boolean[] getBooleanArray​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.bool()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getBooleanList(int) instead.
      • getBooleanArray

        boolean[] getBooleanArray​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.bool()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getBooleanList(String) instead.
      • getBooleanList

        List<Boolean> getBooleanList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.bool()).
      • getBooleanList

        List<Boolean> getBooleanList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.bool()).
      • getLongArray

        long[] getLongArray​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.int64()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getLongList(int) instead.
      • getLongArray

        long[] getLongArray​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.int64()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getLongList(String) instead.
      • getLongList

        List<Long> getLongList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.int64()).
      • getLongList

        List<Long> getLongList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.int64()).
      • getDoubleArray

        double[] getDoubleArray​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.float64()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getDoubleList(int) instead.
      • getDoubleArray

        double[] getDoubleArray​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.float64()).
        Throws:
        NullPointerException - if any element of the array value is NULL. If the array may contain NULL values, use getDoubleList(String) instead.
      • getDoubleList

        List<Double> getDoubleList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.float64()).
      • getDoubleList

        List<Double> getDoubleList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.float64()).
      • getBigDecimalList

        List<BigDecimal> getBigDecimalList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.numeric()).
      • getBigDecimalList

        List<BigDecimal> getBigDecimalList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.numeric()).
      • getStringList

        List<String> getStringList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.string()).
      • getStringList

        List<String> getStringList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.string()).
      • getJsonList

        default List<String> getJsonList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.string()).
      • getJsonList

        default List<String> getJsonList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.string()).
      • getBytesList

        List<com.google.cloud.ByteArray> getBytesList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.bytes()).
      • getBytesList

        List<com.google.cloud.ByteArray> getBytesList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.bytes()).
      • getTimestampList

        List<com.google.cloud.Timestamp> getTimestampList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.timestamp()).
      • getTimestampList

        List<com.google.cloud.Timestamp> getTimestampList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.timestamp()).
      • getDateList

        List<com.google.cloud.Date> getDateList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.date()).
      • getDateList

        List<com.google.cloud.Date> getDateList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.date()).
      • getStructList

        List<Struct> getStructList​(int columnIndex)
        Returns the value of a non-NULL column with type Type.array(Type.struct(...)).
      • getStructList

        List<Struct> getStructList​(String columnName)
        Returns the value of a non-NULL column with type Type.array(Type.struct(...)).