Interface StructReader
-
- All Known Subinterfaces:
AsyncResultSet,PartitionedQueryResultSet,ResultSet
- All Known Implementing Classes:
AbstractStructReader,ForwardingAsyncResultSet,ForwardingResultSet,ForwardingStructReader,Struct
public interface StructReaderA base interface for reading the fields of aSTRUCT. The Cloud Spanner yieldsStructReaderinstances as one of the subclassesResultSetorStruct, most commonly as the result of a read or query operation. At any point in time, aStructReaderprovides access to a single tuple of data comprising multiple typed columns. Each column may have aNULLor non-NULLvalue; 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)andgetString(String)exist for reading columns of typeType.string(); attempting to call those methods for columns of other types will result in anIllegalStateException. ThegetTypeName()methods should only be called for non-NULLvalues, otherwise aNullPointerExceptionis raised;isNull(int)/isNull(String)can be used to test forNULL-ness if necessary.All methods for accessing a column have overloads that accept an
intcolumn index and aStringcolumn name. Column indices are zero-based. The column name overloads will fail withIllegalArgumentExceptionif the column name does not appear exactly once in this instance'sgetType(). Theintoverloads are typically more efficient than theirStringcounterparts.StructReaderitself does not define whether the implementing type is mutable or immutable. For example,ResultSetis a mutable implementation ofStructReader, where theStructReadermethods provide access to the row that the result set is currently positioned over andResultSet.next()changes that view to the next row, whereasStructis an immutable implementation ofStructReader.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description BigDecimalgetBigDecimal(int columnIndex)BigDecimalgetBigDecimal(String columnName)List<BigDecimal>getBigDecimalList(int columnIndex)List<BigDecimal>getBigDecimalList(String columnName)booleangetBoolean(int columnIndex)booleangetBoolean(String columnName)boolean[]getBooleanArray(int columnIndex)boolean[]getBooleanArray(String columnName)List<Boolean>getBooleanList(int columnIndex)List<Boolean>getBooleanList(String columnName)com.google.cloud.ByteArraygetBytes(int columnIndex)com.google.cloud.ByteArraygetBytes(String columnName)List<com.google.cloud.ByteArray>getBytesList(int columnIndex)List<com.google.cloud.ByteArray>getBytesList(String columnName)intgetColumnCount()intgetColumnIndex(String columnName)TypegetColumnType(int columnIndex)TypegetColumnType(String columnName)com.google.cloud.DategetDate(int columnIndex)com.google.cloud.DategetDate(String columnName)List<com.google.cloud.Date>getDateList(int columnIndex)List<com.google.cloud.Date>getDateList(String columnName)doublegetDouble(int columnIndex)doublegetDouble(String columnName)double[]getDoubleArray(int columnIndex)double[]getDoubleArray(String columnName)List<Double>getDoubleList(int columnIndex)List<Double>getDoubleList(String columnName)default StringgetJson(int columnIndex)default StringgetJson(String columnName)default List<String>getJsonList(int columnIndex)default List<String>getJsonList(String columnName)longgetLong(int columnIndex)longgetLong(String columnName)long[]getLongArray(int columnIndex)long[]getLongArray(String columnName)List<Long>getLongList(int columnIndex)List<Long>getLongList(String columnName)default StringgetPgJsonb(int columnIndex)default StringgetPgJsonb(String columnName)default List<String>getPgJsonbList(int columnIndex)default List<String>getPgJsonbList(String columnName)StringgetString(int columnIndex)StringgetString(String columnName)List<String>getStringList(int columnIndex)List<String>getStringList(String columnName)List<Struct>getStructList(int columnIndex)List<Struct>getStructList(String columnName)com.google.cloud.TimestampgetTimestamp(int columnIndex)com.google.cloud.TimestampgetTimestamp(String columnName)List<com.google.cloud.Timestamp>getTimestampList(int columnIndex)List<com.google.cloud.Timestamp>getTimestampList(String columnName)TypegetType()default ValuegetValue(int columnIndex)default ValuegetValue(String columnName)booleanisNull(int columnIndex)booleanisNull(String columnName)
-
-
-
Method Detail
-
getType
Type getType()
- Returns:
- the type of the underlying data. This will always be a
STRUCTtype, with fields corresponding to the data's columns. For the result of a read or query, this will always match the columns passed to theread()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
NULLvalues.
-
getColumnIndex
int getColumnIndex(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the index of the column named
columnName. - Throws:
IllegalArgumentException- if there is not exactly one element oftype().structFields()withType.StructField.getName()equal tocolumnName
-
getColumnType
Type getColumnType(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the type of a column.
-
getColumnType
Type getColumnType(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the type of a column.
-
isNull
boolean isNull(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
trueif a column contains aNULLvalue.
-
isNull
boolean isNull(String columnName)
- Parameters:
columnName- name of the column- Returns:
trueif a column contains aNULLvalue.
-
getBoolean
boolean getBoolean(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bool().
-
getBoolean
boolean getBoolean(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bool().
-
getLong
long getLong(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.int64().
-
getLong
long getLong(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.int64().
-
getDouble
double getDouble(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float64().
-
getDouble
double getDouble(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.float64().
-
getBigDecimal
BigDecimal getBigDecimal(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.numeric().
-
getBigDecimal
BigDecimal getBigDecimal(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.numeric().
-
getString
String getString(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.string().
-
getString
String getString(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.string().
-
getJson
default String getJson(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.json().
-
getJson
default String getJson(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.json().
-
getPgJsonb
default String getPgJsonb(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.pgJsonb().
-
getPgJsonb
default String getPgJsonb(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.pgJsonb().
-
getBytes
com.google.cloud.ByteArray getBytes(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bytes().
-
getBytes
com.google.cloud.ByteArray getBytes(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.bytes().
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.timestamp().
-
getTimestamp
com.google.cloud.Timestamp getTimestamp(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.timestamp().
-
getDate
com.google.cloud.Date getDate(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.date().
-
getDate
com.google.cloud.Date getDate(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.date().
-
getValue
default Value getValue(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a nullable column as a
Value.
-
getValue
default Value getValue(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a nullable column as a
Value.
-
getBooleanArray
boolean[] getBooleanArray(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bool()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetBooleanList(int)instead.
-
getBooleanArray
boolean[] getBooleanArray(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bool()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetBooleanList(String)instead.
-
getBooleanList
List<Boolean> getBooleanList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bool()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBooleanList
List<Boolean> getBooleanList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bool()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getLongArray
long[] getLongArray(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.int64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetLongList(int)instead.
-
getLongArray
long[] getLongArray(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.int64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetLongList(String)instead.
-
getLongList
List<Long> getLongList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.int64()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getLongList
List<Long> getLongList(String columnName)
- Parameters:
columnName-- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.int64()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDoubleArray
double[] getDoubleArray(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetDoubleList(int)instead.
-
getDoubleArray
double[] getDoubleArray(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float64()). - Throws:
NullPointerException- if any element of the array value isNULL. If the array may containNULLvalues, usegetDoubleList(String)instead.
-
getDoubleList
List<Double> getDoubleList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float64())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDoubleList
List<Double> getDoubleList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.float64())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.numeric())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBigDecimalList
List<BigDecimal> getBigDecimalList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.numeric())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStringList
List<String> getStringList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.string()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStringList
List<String> getStringList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.string()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getJsonList
default List<String> getJsonList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.json()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getJsonList
default List<String> getJsonList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.json()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getPgJsonbList
default List<String> getPgJsonbList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.pgJsonb())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getPgJsonbList
default List<String> getPgJsonbList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.pgJsonb())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bytes()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getBytesList
List<com.google.cloud.ByteArray> getBytesList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.bytes()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.timestamp())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getTimestampList
List<com.google.cloud.Timestamp> getTimestampList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.timestamp())The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDateList
List<com.google.cloud.Date> getDateList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.date()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getDateList
List<com.google.cloud.Date> getDateList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.date()). The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStructList
List<Struct> getStructList(int columnIndex)
- Parameters:
columnIndex- index of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.struct(...))The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
getStructList
List<Struct> getStructList(String columnName)
- Parameters:
columnName- name of the column- Returns:
- the value of a non-
NULLcolumn with typeType.array(Type.struct(...))The list returned by this method is lazily constructed. Create a copy of it if you intend to access each element in the list multiple times.
-
-