Class ConnectionExecutor
- All Implemented Interfaces:
MaterializationAware,TransactionalExecutor<Connection>
TransactionalExecutor implementation for JDBC Connections.
The connection is obtained from the given ConnectionProvider at most once, the first time
apply(org.axonframework.common.function.ThrowingFunction<java.sql.Connection, R, java.lang.Exception>) is called, and reused for the remainder of this instance's lifetime. Concurrent
apply(org.axonframework.common.function.ThrowingFunction<java.sql.Connection, R, java.lang.Exception>) calls are serialized, since a single Connection is not safe for concurrent
use.
This executor never commits, rolls back, or closes the connection itself; that remains the
responsibility of whoever supplied it through ConnectionProvider. This is deliberate: a
connection reached through this class is typically an ambient one bound to an externally-managed
unit of work (e.g. published by a container's transaction manager), whose commit, rollback, and
close lifecycle is controlled by that external owner, not this executor.
- Since:
- 5.0.2
- Author:
- John Hendrikx
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<R> CompletableFuture<R> apply(ThrowingFunction<Connection, R, Exception> function) Executes a transactional operation that returns a result.<R> RwithMaterializationShielded(Function<Boolean, R> decision) Runsdecision, passing whether this executor already has a resource materialized, while preventing a concurrentTransactionalExecutor.apply(org.axonframework.common.function.ThrowingFunction<T, R, java.lang.Exception>)call from materializing it for the duration - so a caller can fall back to an independent executor without racing a concurrent materialization.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.common.tx.TransactionalExecutor
accept
-
Constructor Details
-
ConnectionExecutor
Creates a new instance.- Parameters:
provider- AConnectionProvider, cannot benull.- Throws:
NullPointerException- If any argument isnull.
-
-
Method Details
-
withMaterializationShielded
Description copied from interface:MaterializationAwareRunsdecision, passing whether this executor already has a resource materialized, while preventing a concurrentTransactionalExecutor.apply(org.axonframework.common.function.ThrowingFunction<T, R, java.lang.Exception>)call from materializing it for the duration - so a caller can fall back to an independent executor without racing a concurrent materialization.- Specified by:
withMaterializationShieldedin interfaceMaterializationAware- Type Parameters:
R- the type of the result produced bydecision- Parameters:
decision- giventrueif this executor already has a resource materialized, otherwisefalse; run shielded from a concurrent materialization, cannot benull- Returns:
- the result of
decision
-
apply
Description copied from interface:TransactionalExecutorExecutes a transactional operation that returns a result.Implementations are responsible for managing the lifecycle of the provided resource, including obtaining, closing, commit and rollback.
- Specified by:
applyin interfaceTransactionalExecutor<Connection>- 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
-