Interface AsyncTransaction

All Superinterfaces:
AsyncQueryRunner
All Known Implementing Classes:
InternalAsyncTransaction

public interface AsyncTransaction extends AsyncQueryRunner
Logical container for an atomic unit of work. A driver Transaction object corresponds to a server transaction.

Transactions are typically obtained in a CompletionStage and all operations chain on this stage. Explicit commit with commitAsync() or rollback with rollbackAsync() is required. Without explicit commit/rollback corresponding transaction will remain open in the database.

 
 session.beginTransactionAsync()
        .thenCompose(tx ->
               tx.runAsync("CREATE (a:Person {name: $name})", parameters("name", "Alice"))
                 .exceptionally(e -> {
                    e.printStackTrace();
                    return null;
                 })
                 .thenApply(ignore -> tx)
        ).thenCompose(Transaction::commitAsync);
 
 
Async calls are: commitAsync(), rollbackAsync() and various overloads of AsyncQueryRunner.runAsync(Query).
Since:
4.0
See Also:
  • Method Details

    • commitAsync

      CompletionStage<Void> commitAsync()
      Commit this transaction in asynchronous fashion. This operation is typically executed as part of the CompletionStage chain that starts with a transaction. There is no need to close transaction after calling this method. Transaction object should not be used after calling this method.

      Returned stage can be completed by an IO thread which should never block. Otherwise IO operations on this and potentially other network connections might deadlock. Please do not chain blocking operations like CompletableFuture.get() on the returned stage. Consider using asynchronous calls throughout the chain or offloading blocking operation to a different Executor. This can be done using methods with "Async" suffix like CompletionStage.thenApplyAsync(Function) or CompletionStage.thenApplyAsync(Function, Executor).

      Returns:
      new CompletionStage that gets completed with null when commit is successful. Stage can be completed exceptionally when commit fails.
    • rollbackAsync

      CompletionStage<Void> rollbackAsync()
      Rollback this transaction in asynchronous fashion. This operation is typically executed as part of the CompletionStage chain that starts with a transaction. There is no need to close transaction after calling this method. Transaction object should not be used after calling this method.

      Returned stage can be completed by an IO thread which should never block. Otherwise IO operations on this and potentially other network connections might deadlock. Please do not chain blocking operations like CompletableFuture.get() on the returned stage. Consider using asynchronous calls throughout the chain or offloading blocking operation to a different Executor. This can be done using methods with "Async" suffix like CompletionStage.thenApplyAsync(Function) or CompletionStage.thenApplyAsync(Function, Executor).

      Returns:
      new CompletionStage that gets completed with null when rollback is successful. Stage can be completed exceptionally when rollback fails.
    • closeAsync

      CompletionStage<Void> closeAsync()
      Close the transaction. If the transaction has been committed or rolled back, the close is optional and no operation is performed. Otherwise, the transaction will be rolled back by default by this method.
      Returns:
      new CompletionStage that gets completed with null when close is successful, otherwise it gets completed exceptionally.
    • isOpenAsync

      CompletionStage<Boolean> isOpenAsync()
      Determine if transaction is open.
      Returns:
      a CompletionStage completed with true if transaction is open and false otherwise.