public interface AsyncTransaction extends AsyncQueryRunner
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)
.Session.run(java.lang.String, org.neo4j.driver.TransactionConfig)
,
QueryRunner
Modifier and Type | Method and Description |
---|---|
CompletionStage<Void> |
commitAsync()
Commit this transaction in asynchronous fashion.
|
CompletionStage<Void> |
rollbackAsync()
Rollback this transaction in asynchronous fashion.
|
CompletionStage<Void> commitAsync()
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)
.
CompletionStage
that gets completed with null
when commit is successful. Stage can
be completed exceptionally when commit fails.CompletionStage<Void> rollbackAsync()
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)
.
CompletionStage
that gets completed with null
when rollback is successful. Stage can
be completed exceptionally when rollback fails.