Interface Result

All Superinterfaces:
Iterator<Record>

public interface Result extends Iterator<Record>
The result of running a Cypher query, conceptually a stream of records.

The standard way of navigating through the result returned by the database is to iterate over it.

Results are valid until the next query is run or until the end of the current transaction, whichever comes first. To keep a result around while further queries are run, or to use a result outside the scope of the current transaction, see list().

Important note on semantics

In order to handle very large results, and to minimize memory overhead and maximize performance, results are retrieved lazily. Please see QueryRunner for important details on the effects of this.

The short version is that, if you want a hard guarantee that the underlying query has completed, you need to either call Resource.close() on the Transaction or Session that created this result, or you need to use the result.

Calling any method on this interface will guarantee that any write operation has completed on the remote database.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the result summary.
    boolean
    Test if there is another record we can navigate to in this result.
    boolean
    Determine if result is open.
    Retrieve the keys of the records this result contains.
    Retrieve and store the entire result stream.
    <T> List<T>
    list(Function<Record,T> mapFunction)
    Retrieve and store a projection of the entire result.
    Navigate to and retrieve the next Record in this result.
    Investigate the next upcoming record without moving forward in the result.
    Return the first record in the result, failing if there is not exactly one record left in the stream
    Convert this result to a sequential Stream of records.

    Methods inherited from interface java.util.Iterator

    forEachRemaining, remove
  • Method Details

    • keys

      List<String> keys()
      Retrieve the keys of the records this result contains.
      Returns:
      all keys
    • hasNext

      boolean hasNext()
      Test if there is another record we can navigate to in this result.
      Specified by:
      hasNext in interface Iterator<Record>
      Returns:
      true if next() will return another record
    • next

      Record next()
      Navigate to and retrieve the next Record in this result.
      Specified by:
      next in interface Iterator<Record>
      Returns:
      the next record
      Throws:
      NoSuchRecordException - if there is no record left in the stream
    • single

      Record single() throws NoSuchRecordException
      Return the first record in the result, failing if there is not exactly one record left in the stream

      Calling this method always exhausts the result, even when NoSuchRecordException is thrown.

      Returns:
      the first and only record in the stream
      Throws:
      NoSuchRecordException - if there is not exactly one record left in the stream
    • peek

      Record peek()
      Investigate the next upcoming record without moving forward in the result.
      Returns:
      the next record
      Throws:
      NoSuchRecordException - if there is no record left in the stream
    • stream

      Stream<Record> stream()
      Convert this result to a sequential Stream of records.

      Result is exhausted when a terminal operation on the returned stream is executed.

      Returns:
      sequential Stream of records. Empty stream if this result has already been consumed or is empty.
    • list

      List<Record> list()
      Retrieve and store the entire result stream. This can be used if you want to iterate over the stream multiple times or to store the whole result for later use.

      Note that this method can only be used if you know that the query that yielded this result returns a finite stream. Some queries can yield infinite results, in which case calling this method will lead to running out of memory.

      Calling this method exhausts the result.

      Returns:
      list of all remaining immutable records
    • list

      <T> List<T> list(Function<Record,T> mapFunction)
      Retrieve and store a projection of the entire result. This can be used if you want to iterate over the stream multiple times or to store the whole result for later use.

      Note that this method can only be used if you know that the query that yielded this result returns a finite stream. Some queries can yield infinite results, in which case calling this method will lead to running out of memory.

      Calling this method exhausts the result.

      Type Parameters:
      T - the type of result list elements
      Parameters:
      mapFunction - a function to map from Record to T. See Records for some predefined functions.
      Returns:
      list of all mapped remaining immutable records
    • consume

      ResultSummary consume()
      Return the result summary.

      If the records in the result is not fully consumed, then calling this method will exhausts the result.

      If you want to access unconsumed records after summary, you shall use list() to buffer all records into memory before summary.

      Returns:
      a summary for the whole query result.
    • isOpen

      boolean isOpen()
      Determine if result is open.

      Result is considered to be open if it has not been consumed (consume()) and its creator object (e.g. session or transaction) has not been closed (including committed or rolled back).

      Attempts to access data on closed result will produce ResultConsumedException.

      Returns:
      true if result is open and false otherwise.