com.datastax.driver.dse.graph

## Class GraphResultSet

• All Implemented Interfaces:
Iterable<GraphNode>

public class GraphResultSet
extends Object
implements Iterable<GraphNode>
The result of a graph query.
• ### Constructor Summary

Constructors
Constructor and Description
GraphResultSet(ResultSet wrapped)
This constructor is intended for internal use only, users should normally obtain instances from DseSession.executeGraph(GraphStatement).
• ### Method Summary

All Methods
Modifier and Type Method and Description
List<GraphNode> all()
Returns all the remaining results as a list.
com.google.common.util.concurrent.ListenableFuture<GraphResultSet> fetchMoreResults()
Force fetching the next page of results for this result set, if any.
List<ExecutionInfo> getAllExecutionInfo()
Returns the execution information for all queries made to retrieve this result set.
int getAvailableWithoutFetching()
The number of results that can be retrieved without blocking to fetch.
ExecutionInfo getExecutionInfo()
Returns information on the execution of the last query made for this result set.
boolean isExhausted()
Returns whether there are more results.
boolean isFullyFetched()
Whether all results have been fetched from the database.
Iterator<GraphNode> iterator()
Returns an iterator over the results.
GraphNode one()
Returns the next result.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface java.lang.Iterable

forEach, spliterator

• ### Method Detail

• #### isExhausted

public boolean isExhausted()
Returns whether there are more results.
Returns:
whether there are more results.
• #### one

public GraphNode one()
Returns the next result.
Returns:
the next result, or null if there are no more of them.
• #### all

public List<GraphNode> all()
Returns all the remaining results as a list.

Note that, contrary to iterator() or successive calls to one(), this method force-fetches all remaining results from the server, holding them all in memory. It is thus recommended to prefer iterations through iterator() when possible, especially when there is a large number of results.

Returns:
a list containing the remaining results. The returned list is empty if and only this result set is exhausted. The result set will be exhausted after a call to this method.
• #### iterator

public Iterator<GraphNode> iterator()
Returns an iterator over the results.

The Iterator.next() method is equivalent to calling one(). After a full iteration, the result set will be exhausted.

The returned iterator does not support the Iterator.remove() method.

Specified by:
iterator in interface Iterable<GraphNode>
Returns:
an iterator that will consume and return the remaining results.
• #### getAvailableWithoutFetching

public int getAvailableWithoutFetching()
The number of results that can be retrieved without blocking to fetch.
Returns:
the number of results readily available. If isFullyFetched(), this is the total number of results remaining, otherwise going past that limit will trigger background fetches.
• #### isFullyFetched

public boolean isFullyFetched()
Whether all results have been fetched from the database.

If isFullyFetched(), then getAvailableWithoutFetching() will return the number of results remaining before exhaustion.

But !isFullyFetched() does not necessarily mean that the result set is not exhausted (you should call isExhausted() to verify it).

Returns:
whether all results have been fetched.
• #### fetchMoreResults

public com.google.common.util.concurrent.ListenableFuture<GraphResultSet> fetchMoreResults()
Force fetching the next page of results for this result set, if any.

This method is entirely optional. It will be called automatically while the result set is consumed (through one(), all() or iteration) when needed (i.e. when getAvailableWithoutFetching() == 0 and isFullyFetched() == false).

You can however call this method manually to force the fetching of the next page of results. This can allow to prefetch results before they are strictly needed. For instance, if you want to prefetch the next page of results as soon as there is less than 100 rows readily available in this result set, you can do:

   GraphResultSet rs = session.executeGraph(...);
Iterator<GraphNode> iter = rs.iterator();
while (iter.hasNext()) {
if (rs.getAvailableWithoutFetching() == 100 && !rs.isFullyFetched())
rs.fetchMoreResults();
GraphNode result = iter.next()
... process the result ...
}

This method is not blocking, so in the example above, the call to fetchMoreResults will not block the processing of the 100 currently available results (but iter.hasNext() will block once those results have been processed until the fetch query returns, if it hasn't yet).

Only one page of results (for a given result set) can be fetched at any given time. If this method is called twice and the query triggered by the first call has not returned yet when the second one is performed, then the 2nd call will simply return a future on the currently in progress query.

Returns:
a future on the completion of fetching the next page of results. If the result set is already fully retrieved (isFullyFetched() == true), then the returned future will return immediately, but not particular error will be thrown (you should thus call isFullyFetched() to know if calling this method can be of any use).
• #### getExecutionInfo

public ExecutionInfo getExecutionInfo()
Returns information on the execution of the last query made for this result set.

Note that in most cases, a result set is fetched with only one query, but large result sets can be paged and thus be retrieved by multiple queries. In that case this method return the ExecutionInfo for the last query performed. To retrieve the information for all queries, use getAllExecutionInfo().

The returned object includes basic information such as the queried hosts, but also the Cassandra query trace if tracing was enabled for the query.

Returns:
the execution info for the last query made for this GraphResultSet.
• #### getAllExecutionInfo

public List<ExecutionInfo> getAllExecutionInfo()
Returns the execution information for all queries made to retrieve this result set.

If paging was used, the returned list contains the ExecutionInfo for all the queries done to obtain the results (at the time of the call), in the order those queries were made.

If no paging was used (because the result set was small enough), the list only contains one element.

Returns:
a list of the execution info for all the queries made for this GraphResultSet.