- All Superinterfaces:
AsyncQueryRunner
- All Known Implementing Classes:
InternalAsyncTransaction
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 Summary
Modifier and TypeMethodDescriptionClose the transaction.Commit this transaction in asynchronous fashion.Determine if transaction is open.Rollback this transaction in asynchronous fashion.
-
Method Details
-
commitAsync
CompletionStage<Void> commitAsync()Commit this transaction in asynchronous fashion. This operation is typically executed as part of theCompletionStage
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 differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Returns:
- new
CompletionStage
that gets completed withnull
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 theCompletionStage
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 differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Returns:
- new
CompletionStage
that gets completed withnull
when rollback is successful. Stage can be completed exceptionally when rollback fails.
-
closeAsync
CompletionStage<Void> closeAsync()Close the transaction. If the transaction has beencommitted
orrolled 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 withnull
when close is successful, otherwise it gets completed exceptionally.
-
isOpenAsync
CompletionStage<Boolean> isOpenAsync()Determine if transaction is open.- Returns:
- a
CompletionStage
completed withtrue
if transaction is open andfalse
otherwise.
-