org.springframework.transaction.support

## Interface TransactionOperations

- All Known Implementing Classes:
    TransactionTemplate

      public interface TransactionOperations

  Interface specifying basic transaction execution operations. Implemented by `TransactionTemplate`. Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.
  Since:
    2.0.4
  Author:
    Juergen Hoeller

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `execute(TransactionCallback<T> action)` Execute the action specified by the given callback object within a transaction.
    `default void` | `executeWithoutResult(Consumer<TransactionStatus> action)` Execute the action specified by the given `Runnable` within a transaction.
    `static TransactionOperations` | `withoutTransaction()` Return an implementation of the `TransactionOperations` interface which executes a given `TransactionCallback` without an actual transaction.

- - ### Method Detail

    - #### execute

          @Nullable
          <T> T execute(TransactionCallback<T> action)
                           throws TransactionException

      Execute the action specified by the given callback object within a transaction.

      Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.

      Parameters:
        `action` - the callback object that specifies the transactional action
      Returns:
        a result object returned by the callback, or `null` if none
      Throws:
        `TransactionException` - in case of initialization, rollback, or system errors
        `RuntimeException` - if thrown by the TransactionCallback
      See Also:
        `executeWithoutResult(Consumer)`

    - #### executeWithoutResult

          default void executeWithoutResult(Consumer<TransactionStatus> action)
                                     throws TransactionException

      Execute the action specified by the given `Runnable` within a transaction.

      If you need to return an object from the callback or access the `TransactionStatus` from within the callback, use `execute(TransactionCallback)` instead.

      This variant is analogous to using a `TransactionCallbackWithoutResult` but with a simplified signature for common cases - and conveniently usable with Java 8 lambda expressions.

      Parameters:
        `action` - the Runnable that specifies the transactional action
      Throws:
        `TransactionException` - in case of initialization, rollback, or system errors
        `RuntimeException` - if thrown by the Runnable
      Since:
        5.2
      See Also:
        `execute(TransactionCallback)`, `TransactionCallbackWithoutResult`

    - #### withoutTransaction

          static TransactionOperations withoutTransaction()

      Return an implementation of the `TransactionOperations` interface which executes a given `TransactionCallback` without an actual transaction.

      Useful for testing: The behavior is equivalent to running with a transaction manager with no actual transaction (PROPAGATION_SUPPORTS) and no synchronization (SYNCHRONIZATION_NEVER).

      For a `TransactionOperations` implementation with actual transaction processing, use `TransactionTemplate` with an appropriate `PlatformTransactionManager`.

      Since:
        5.2
      See Also:
        `TransactionDefinition.PROPAGATION_SUPPORTS`, `AbstractPlatformTransactionManager.SYNCHRONIZATION_NEVER`, `TransactionTemplate`