Package org.axonframework.common.tx
Interface TransactionalExecutor<T>
- Type Parameters:
T- The type of the resource.
- All Known Implementing Classes:
ConnectionExecutor,EntityManagerExecutor
Executes transactional operations with automatic transaction management. The
user of this interface will get (limited) access to a transactional resource,
like a JDBC connection or an Entity Manager, with which to perform operations.
At the appropriate time in the lifecycle of this executor, commit or rollback is called on the transactional resource managed by it. Any (uncaught) exceptions will result in the resource to be rolled back, and any associated lifecycle to be put into an error state.
This interface provides convenience methods for both operations that return a result and operations that are purely side-effecting.
- Since:
- 5.0.2
- Author:
- John Hendrikx
-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Void> accept(ThrowingConsumer<T, Exception> consumer) Executes a transactional operation that does not return a result.<R> CompletableFuture<R> apply(ThrowingFunction<T, R, Exception> function) Executes a transactional operation that returns a result.
-
Method Details
-
accept
Executes a transactional operation that does not return a result.Implementations are responsible for managing the lifecycle of the provided resource, including obtaining, closing, commit and rollback.
- Parameters:
consumer- A consumer which accepts the transactional resource of typeT; cannot benull.- Returns:
- A
CompletableFuturewith a void result, nevernull. - Throws:
NullPointerException- Whenconsumerisnull.
-
apply
Executes a transactional operation that returns a result.Implementations are responsible for managing the lifecycle of the provided resource, including obtaining, closing, commit and rollback.
- Type Parameters:
R- The type of the result returned by the function.- Parameters:
function- A function that accepts the transactional resource of typeTand produces a result of typeR; cannot benull.- Returns:
- A
CompletableFuturewhich when it completes contains the result of the provided function, nevernull. - Throws:
NullPointerException- Whenfunctionisnull.
-