Package com.google.cloud.spanner
Interface ResultSet
-
- All Superinterfaces:
AutoCloseable,StructReader
- All Known Subinterfaces:
AsyncResultSet
- All Known Implementing Classes:
ForwardingAsyncResultSet,ForwardingResultSet
public interface ResultSet extends AutoCloseable, StructReader
Provides access to the data returned by a Cloud Spanner read or query.ResultSetallows a single row to be inspected at a time through the methods from theStructReaderinterface, in the order that the rows were returned by the read or query. The result set can be positioned over the next row, if one exists, by callingnext(); this method returnsfalsewhen all rows returned have been seen. The result set is initially positioned before the first row, so a call tonext()is required before the first row can be inspected.ResultSetimplementations may buffer data ahead and/or maintain a persistent streaming connection to the remote service until all data has been returned or the resultSet closed. As such, it is important that all uses ofResultSeteither fully consume it (that is, callnext()untilfalseis returned or it throws an exception) or explicitly callclose(): failure to do so may result in wasted work or leaked resources.ResultSetimplementations are not required to be thread-safe: if methods are called from multiple threads, external synchronization must be used.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Explicitly close the result set, releasing any associated resources.StructgetCurrentRowAsStruct()Creates an immutable version of the row that the result set is positioned over.default ResultSetMetadatagetMetadata()Returns theResultSetMetadatafor thisResultSet.ResultSetStatsgetStats()Returns theResultSetStatsfor the query only if the query was executed in either thePLANor thePROFILEmode via theReadContext.analyzeQuery(Statement, com.google.cloud.spanner.ReadContext.QueryAnalyzeMode)method or for DML statements inReadContext.executeQuery(Statement, QueryOption...).booleannext()Advances the result set to the next row, returning false if no such row exists.-
Methods inherited from interface com.google.cloud.spanner.StructReader
getBigDecimal, getBigDecimal, getBigDecimalList, getBigDecimalList, getBoolean, getBoolean, getBooleanArray, getBooleanArray, getBooleanList, getBooleanList, getBytes, getBytes, getBytesList, getBytesList, getColumnCount, getColumnIndex, getColumnType, getColumnType, getDate, getDate, getDateList, getDateList, getDouble, getDouble, getDoubleArray, getDoubleArray, getDoubleList, getDoubleList, getJson, getJson, getJsonList, getJsonList, getLong, getLong, getLongArray, getLongArray, getLongList, getLongList, getPgJsonb, getPgJsonb, getPgJsonbList, getPgJsonbList, getString, getString, getStringList, getStringList, getStructList, getStructList, getTimestamp, getTimestamp, getTimestampList, getTimestampList, getType, getValue, getValue, isNull, isNull
-
-
-
-
Method Detail
-
next
boolean next() throws SpannerExceptionAdvances the result set to the next row, returning false if no such row exists. This method may block.- Throws:
SpannerException
-
getCurrentRowAsStruct
Struct getCurrentRowAsStruct()
Creates an immutable version of the row that the result set is positioned over. This may involve copying internal data structures, and so converting all rows toStructobjects is generally more expensive than processing theResultSetdirectly.
-
close
void close()
Explicitly close the result set, releasing any associated resources. This must always be called when disposing of aResultSetbeforenext()has returnedfalseor raised an exception. Callingclose()is also allowed if the result set has been fully consumed, so a recommended practice is to unconditionally close the result set once it is done with, typically using a try-with-resources construct.- Specified by:
closein interfaceAutoCloseable
-
getStats
@Nullable ResultSetStats getStats()
Returns theResultSetStatsfor the query only if the query was executed in either thePLANor thePROFILEmode via theReadContext.analyzeQuery(Statement, com.google.cloud.spanner.ReadContext.QueryAnalyzeMode)method or for DML statements inReadContext.executeQuery(Statement, QueryOption...). Attempts to call this method on aResultSetnot obtained fromanalyzeQueryorexecuteQuerywill return anullResultSetStats. This method must be called afternext()has returned @{code false}. Calling it before that will result innullResultSetStatstoo.
-
getMetadata
default ResultSetMetadata getMetadata()
Returns theResultSetMetadatafor thisResultSet. This is method may only be called after callingnext()at least once.
-
-