Interface TransactionalExecutor<T>

Type Parameters:
T - The type of the resource.
All Known Implementing Classes:
ConnectionExecutor, EntityManagerExecutor

@Internal public interface TransactionalExecutor<T>
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 Details

    • accept

      @Nonnull default CompletableFuture<Void> accept(@Nonnull ThrowingConsumer<T,Exception> consumer)
      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 type T; cannot be null.
      Returns:
      A CompletableFuture with a void result, never null.
      Throws:
      NullPointerException - When consumer is null.
    • apply

      @Nonnull <R> CompletableFuture<R> apply(@Nonnull ThrowingFunction<T,R,Exception> function)
      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 type T and produces a result of type R; cannot be null.
      Returns:
      A CompletableFuture which when it completes contains the result of the provided function, never null.
      Throws:
      NullPointerException - When function is null.