Class InternalReactiveSession

java.lang.Object
org.neo4j.driver.internal.reactive.AbstractReactiveSession<ReactiveTransaction>
org.neo4j.driver.internal.reactive.InternalReactiveSession
All Implemented Interfaces:
BaseSession, ReactiveQueryRunner, ReactiveSession

public class InternalReactiveSession extends AbstractReactiveSession<ReactiveTransaction> implements ReactiveSession
  • Constructor Details

    • InternalReactiveSession

      public InternalReactiveSession(NetworkSession session)
  • Method Details

    • createTransaction

      protected ReactiveTransaction createTransaction(UnmanagedTransaction unmanagedTransaction)
      Specified by:
      createTransaction in class AbstractReactiveSession<ReactiveTransaction>
    • closeTransaction

      protected org.reactivestreams.Publisher<Void> closeTransaction(ReactiveTransaction transaction, boolean commit)
      Specified by:
      closeTransaction in class AbstractReactiveSession<ReactiveTransaction>
    • beginTransaction

      public Flow.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config)
      Description copied from interface: ReactiveSession
      Begin a new unmanaged transaction with the specified configuration. At most one transaction may exist in a session at any point in time. To maintain multiple concurrent transactions, use multiple concurrent sessions.

      It by default is executed in a Network IO thread, as a result no blocking operation is allowed in this thread.

      Specified by:
      beginTransaction in interface ReactiveSession
      Parameters:
      config - configuration for the new transaction.
      Returns:
      a new ReactiveTransaction
    • beginTransaction

      public Flow.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config, String txType, ApiTelemetryWork apiTelemetryWork)
    • executeRead

      public <T> Flow.Publisher<T> executeRead(ReactiveTransactionCallback<? extends Flow.Publisher<T>> callback, TransactionConfig config)
      Description copied from interface: ReactiveSession
      Execute a unit of work as a single, managed transaction with read access mode and retry behaviour. The transaction allows for one or more statements to be run.

      The driver will attempt committing the transaction when the provided unit of work completes successfully. Any exception emitted by the unit of work will result in a rollback attempt and abortion of execution unless exception is considered to be valid for retry attempt by the driver.

      The provided unit of work should not return ReactiveResult object as it won't be valid outside the scope of the transaction.

      It is prohibited to block the thread completing the returned CompletionStage. Please avoid blocking operations or hand processing over to a different thread.

      The driver uses the provided ReactiveTransactionCallback to get a publisher and emits its signals via the resulting publisher. If the supplied publisher emits a RetryableException and the driver is in a position to retry, it calls the provided callback again to get a new publisher and attempts to stream its signals. In case of retries, the resulting publisher contains the successfully emitted values from all retry attempts. For instance, if a retryable exception occurs after streaming values [v1, v2, v3] and a successful retry emits values [v1, v2, v3, v4] then the resulting publisher emits the following values: [v1, v2, v3, v1, v2, v3, v4].

      Specified by:
      executeRead in interface ReactiveSession
      Type Parameters:
      T - the return type of the given unit of work.
      Parameters:
      callback - the callback representing the unit of work.
      config - configuration for all transactions started to execute the unit of work.
      Returns:
      a publisher that emits the result of the unit of work and success signals on success or error otherwise.
    • executeWrite

      public <T> Flow.Publisher<T> executeWrite(ReactiveTransactionCallback<? extends Flow.Publisher<T>> callback, TransactionConfig config)
      Description copied from interface: ReactiveSession
      Execute a unit of work as a single, managed transaction with write access mode and retry behaviour. The transaction allows for one or more statements to be run.

      The driver will attempt committing the transaction when the provided unit of work completes successfully. Any exception emitted by the unit of work will result in a rollback attempt and abortion of execution unless exception is considered to be valid for retry attempt by the driver.

      The provided unit of work should not return ReactiveResult object as it won't be valid outside the scope of the transaction.

      It is prohibited to block the thread completing the returned CompletionStage. Please avoid blocking operations or hand processing over to a different thread.

      The driver uses the provided ReactiveTransactionCallback to get a publisher and emits its signals via the resulting publisher. If the supplied publisher emits a RetryableException and the driver is in a position to retry, it calls the provided callback again to get a new publisher and attempts to stream its signals. In case of retries, the resulting publisher contains the successfully emitted values from all retry attempts. For instance, if a retryable exception occurs after streaming values [v1, v2, v3] and a successful retry emits values [v1, v2, v3, v4] then the resulting publisher emits the following values: [v1, v2, v3, v1, v2, v3, v4].

      Specified by:
      executeWrite in interface ReactiveSession
      Type Parameters:
      T - the return type of the given unit of work.
      Parameters:
      callback - the callback representing the unit of work.
      config - configuration for all transactions started to execute the unit of work.
      Returns:
      a publisher that emits the result of the unit of work and success signals on success or error otherwise.
    • run

      public Flow.Publisher<ReactiveResult> run(Query query)
      Description copied from interface: ReactiveQueryRunner
      Register running of a query and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      Specified by:
      run in interface ReactiveQueryRunner
      Parameters:
      query - a Neo4j query
      Returns:
      a publisher of reactive result.
    • run

      public Flow.Publisher<ReactiveResult> run(Query query, TransactionConfig config)
      Description copied from interface: ReactiveSession
      Run a query in an auto-commit transaction with specified configuration and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      Example

       
       Map<String, Object> metadata = new HashMap<>();
       metadata.put("type", "update name");
      
       TransactionConfig config = TransactionConfig.builder()
                       .withTimeout(Duration.ofSeconds(3))
                       .withMetadata(metadata)
                       .build();
      
       Query query = new Query("MATCH (n) WHERE n.name = $myNameParam RETURN n.age");
      
       reactiveSession.run(query.withParameters(Values.parameters("myNameParam", "Bob")));
       
       
      Specified by:
      run in interface ReactiveSession
      Parameters:
      query - a Neo4j query.
      config - configuration for the new transaction.
      Returns:
      a publisher of reactive result.
    • lastBookmarks

      public Set<Bookmark> lastBookmarks()
      Description copied from interface: ReactiveSession
      Return a set of last bookmarks.

      When no new bookmark is received, the initial bookmarks are returned. This may happen when no work has been done using the session. Multivalued Bookmark instances will be mapped to distinct Bookmark instances. If no initial bookmarks have been provided, an empty set is returned.

      Specified by:
      lastBookmarks in interface ReactiveSession
      Overrides:
      lastBookmarks in class AbstractReactiveSession<ReactiveTransaction>
      Returns:
      the immutable set of last bookmarks.
    • close

      public <T> Flow.Publisher<T> close()
      Description copied from interface: ReactiveSession
      Signal that you are done using this session. In the default driver usage, closing and accessing sessions is very low cost.

      This operation is not needed if 1) all results created in the session have been fully consumed and 2) all transactions opened by this session have been either committed or rolled back.

      This method is a fallback if you failed to fulfill the two requirements above. This publisher is completed when all outstanding queries in the session have completed, meaning any writes you performed are guaranteed to be durably stored. It might be completed exceptionally when there are unconsumed errors from previous queries or transactions.

      Specified by:
      close in interface ReactiveSession
      Type Parameters:
      T - makes it easier to be chained.
      Returns:
      an empty publisher that represents the reactive close.
    • run

      default Flow.Publisher<ReactiveResult> run(String queryStr, Value parameters)
      Description copied from interface: ReactiveQueryRunner
      Register running of a query and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      This method takes a set of parameters that will be injected into the query by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.

      This particular method takes a Value as its input. This is useful if you want to take a map-like value that you've gotten from a prior result and send it back as parameters.

      If you are creating parameters programmatically, ReactiveQueryRunner.run(String, Map) might be more helpful, it converts your map to a Value for you.

      Specified by:
      run in interface ReactiveQueryRunner
      Parameters:
      queryStr - text of a Neo4j query
      parameters - input parameters, should be a map Value, see Values.parameters(Object...).
      Returns:
      a publisher of reactive result.
    • run

      default Flow.Publisher<ReactiveResult> run(String query, Map<String,Object> parameters)
      Description copied from interface: ReactiveQueryRunner
      Register running of a query and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      This method takes a set of parameters that will be injected into the query by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.

      This version of run takes a Map of parameters. The values in the map must be values that can be converted to Neo4j types. See Values.parameters(Object...) for a list of allowed types.

      Specified by:
      run in interface ReactiveQueryRunner
      Parameters:
      query - text of a Neo4j query
      parameters - input data for the query
      Returns:
      a publisher of reactive result.
    • run

      default Flow.Publisher<ReactiveResult> run(String query, Record parameters)
      Description copied from interface: ReactiveQueryRunner
      Register running of a query and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      This method takes a set of parameters that will be injected into the query by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.

      This version of run takes a Record of parameters, which can be useful if you want to use the output of one query as input for another.

      Specified by:
      run in interface ReactiveQueryRunner
      Parameters:
      query - text of a Neo4j query
      parameters - input data for the query
      Returns:
      a publisher of reactive result.
    • run

      default Flow.Publisher<ReactiveResult> run(String queryStr)
      Description copied from interface: ReactiveQueryRunner
      Register running of a query and return a publisher of ReactiveResult.

      Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of ReactiveResult on success or an error otherwise.

      Specified by:
      run in interface ReactiveQueryRunner
      Parameters:
      queryStr - text of a Neo4j query
      Returns:
      a publisher of reactive result.