public interface ResultSet extends Iterable<Row>
It uses asynchronous calls
internally, but blocks on the results in
order to provide a synchronous API to its clients. If the query is paged, only the first page
will be fetched initially, and iteration will trigger background fetches of the next pages when
necessary.
Note that this object can only be iterated once: rows are "consumed" as they are read,
subsequent calls to iterator()
will the same iterator instance.
Implementations of this type are not thread-safe. They can only be iterated by the
thread that invoked session.execute
.
Modifier and Type | Method and Description |
---|---|
default List<Row> |
all()
Returns all the remaining rows as a list; not recommended for queries that return a large
number of rows.
|
ColumnDefinitions |
getColumnDefinitions() |
default ExecutionInfo |
getExecutionInfo()
The execution information for the last query performed for this result set.
|
List<ExecutionInfo> |
getExecutionInfos()
The execution information for all the queries that have been performed so far to assemble this
result set.
|
default Row |
one()
Returns the next row, or
null if the result set is exhausted. |
boolean |
wasApplied()
If the query that produced this result was a conditional update, indicate whether it was
successfully applied.
|
forEach, iterator, spliterator
@NonNull ColumnDefinitions getColumnDefinitions()
@NonNull default ExecutionInfo getExecutionInfo()
This is a shortcut for:
getExecutionInfos().get(getExecutionInfos().size() - 1)
getExecutionInfos()
@NonNull List<ExecutionInfo> getExecutionInfos()
This will have multiple elements if the query is paged, since the driver performs blocking background queries to fetch additional pages transparently as the result set is being iterated.
@Nullable default Row one()
null
if the result set is exhausted.
This is convenient for queries that are known to return exactly one row, for example count queries.
@NonNull default List<Row> all()
Contrary to Iterable.iterator()
or successive calls to one()
, this method forces
fetching the full contents of the result set at once; in particular, this means that a
large number of background queries might have to be run, and that all the data will be held in
memory locally. Therefore it is crucial to only call this method for queries that are known to
return a reasonable number of results.
boolean wasApplied()
This is equivalent to calling:
this.iterator().next().getBoolean("[applied]")Except that this method peeks at the next row without consuming it.
For consistency, this method always returns true
for non-conditional queries
(although there is no reason to call the method in that case). This is also the case for
conditional DDL statements (CREATE KEYSPACE... IF NOT EXISTS
, CREATE TABLE... IF
NOT EXISTS
), for which Cassandra doesn't return an [applied]
column.
Note that, for versions of Cassandra strictly lower than 2.1.0-rc2, a server-side bug (CASSANDRA-7337) causes this
method to always return true
for batches containing conditional queries.
Copyright © 2017–2018. All rights reserved.