Package org.eclipse.rdf4j.spring.resultcache

## Class ReusableGraphQueryResult

- java.lang.Object
- - org.eclipse.rdf4j.spring.resultcache.ReusableGraphQueryResult

- All Implemented Interfaces:
    `AutoCloseable`, `Iterable<Statement>`, `CloseableIteration<Statement,​QueryEvaluationException>`, `Iteration<Statement,​QueryEvaluationException>`, `GraphQueryResult`, `QueryResult<Statement>`, `ThrowableRecorder`

      public class ReusableGraphQueryResult
      extends Object
      implements GraphQueryResult, ThrowableRecorder

  Wrapper for a TupleQueryResult, allowing the result to be replayed. Not thread-safe. The wrapper copies the result data, consuming the original result fully on `close()`.

  Example:

       TupleQueryResult result = tupleQuery.execute();
       ReuseableTupleQueryResult reusable = new ReuseableTupleQueryResult(result);
       while (reusable.hasNext()) {
              reuseable.next();
       }
       reuseable.close();
       GraphQueryResult cached = reuseable.recreateGraphQueryResult();
       while (cached.hasNext()) {
              cached.next();
       }
       cached.close();

  Since:
    4.0.0
  Author:
    Florian Kleedorfer

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ReusableGraphQueryResult​(GraphQueryResult result, BindingSet queryBindings)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `canReuse()` |
    `void` | `close()` | Closes this iteration, freeing any resources that it is holding.
    `void` | `forEach​(Consumer<? super Statement> action)` |
    `Map<String,​String>` | `getNamespaces()` | Retrieves relevant namespaces from the query result.
    `boolean` | `hasNext()` | Returns true if the iteration has more elements.
    `Iterator<Statement>` | `iterator()` |
    `Statement` | `next()` | Returns the next element in the iteration.
    `boolean` | `queryBindingsAreIdentical​(BindingSet candidate)` |
    `void` | `recordThrowable​(Throwable t)` |
    `CachedGraphQueryResult` | `recreateGraphQueryResult()` |
    `void` | `remove()` | Removes from the underlying collection the last element returned by the iteration (optional operation).
    `Spliterator<Statement>` | `spliterator()` |
    `Stream<Statement>` | `stream()` | Convert the results to a Java 8 Stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ReusableGraphQueryResult

          public ReusableGraphQueryResult​(GraphQueryResult result,
                                          BindingSet queryBindings)

  - ### Method Detail

    - #### queryBindingsAreIdentical

          public boolean queryBindingsAreIdentical​(BindingSet candidate)

    - #### canReuse

          public boolean canReuse()

    - #### recreateGraphQueryResult

          public CachedGraphQueryResult recreateGraphQueryResult()

    - #### recordThrowable

          public void recordThrowable​(Throwable t)

      Specified by:
        `recordThrowable` in interface `ThrowableRecorder`

    - #### getNamespaces

          public Map<String,​String> getNamespaces()
                                                 throws QueryEvaluationException

      Description copied from interface: `GraphQueryResult`
      Retrieves relevant namespaces from the query result.
      The contents of the Map may be modified after it is returned, as the initial return may be performed when the first RDF Statement is encountered.
      Specified by:
        `getNamespaces` in interface `GraphQueryResult`
      Returns:
        a Map<String, String> object containing (prefix, namespace) pairs.
      Throws:
        `QueryEvaluationException`

    - #### iterator

          public Iterator<Statement> iterator()

      Specified by:
        `iterator` in interface `Iterable<Statement>`
      Specified by:
        `iterator` in interface `QueryResult<Statement>`

    - #### close

          public void close()
                     throws QueryEvaluationException

      Description copied from interface: `CloseableIteration`
      Closes this iteration, freeing any resources that it is holding. If the iteration has already been closed then invoking this method has no effect.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `CloseableIteration<Statement,​QueryEvaluationException>`
      Throws:
        `QueryEvaluationException`

    - #### hasNext

          public boolean hasNext()
                          throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Returns true if the iteration has more elements. (In other words, returns true if `Iteration.next()` would return an element rather than throwing a NoSuchElementException.)
      Specified by:
        `hasNext` in interface `Iteration<Statement,​QueryEvaluationException>`
      Returns:
        true if the iteration has more elements.
      Throws:
        `QueryEvaluationException`

    - #### next

          public Statement next()
                         throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Returns the next element in the iteration.
      Specified by:
        `next` in interface `Iteration<Statement,​QueryEvaluationException>`
      Returns:
        the next element in the iteration.
      Throws:
        `QueryEvaluationException`

    - #### remove

          public void remove()
                      throws QueryEvaluationException

      Description copied from interface: `Iteration`
      Removes from the underlying collection the last element returned by the iteration (optional operation). This method can be called only once per call to next.
      Specified by:
        `remove` in interface `Iteration<Statement,​QueryEvaluationException>`
      Throws:
        `QueryEvaluationException`

    - #### stream

          public Stream<Statement> stream()

      Description copied from interface: `Iteration`
      Convert the results to a Java 8 Stream. If this iteration implements CloseableIteration it should be closed (by calling Stream#close() or using try-with-resource) if it is not fully consumed.
      Specified by:
        `stream` in interface `Iteration<Statement,​QueryEvaluationException>`
      Returns:
        stream

    - #### forEach

          public void forEach​(Consumer<? super Statement> action)

      Specified by:
        `forEach` in interface `Iterable<Statement>`

    - #### spliterator

          public Spliterator<Statement> spliterator()

      Specified by:
        `spliterator` in interface `Iterable<Statement>`