# Interface TransactionManager

All Known Implementing Classes:
  `DefaultTransactionManager`

public interface TransactionManager
An optional utility service that simplifies wrapping multiple operations in transactions. Users only rarely need to invoke it directly, as all standard Cayenne operations are managing their own transactions internally.

Since:
  4.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `performInTransaction(TransactionalOperation<T> op)`
  Starts a new transaction (or joins an existing one) calling `TransactionalOperation.perform()`, and then committing or rolling back the transaction.
  `<T> T`
  `performInTransaction(TransactionalOperation<T> op, TransactionDescriptor descriptor)`
  Performs operation in a transaction which parameters described by descriptor.
  `<T> T`
  `performInTransaction(TransactionalOperation<T> op, TransactionFactory transactionFactory)`
  Performs an operation in a transaction created by the supplied factory, instead of the configured one.
  `<T> T`
  `performInTransaction(TransactionalOperation<T> op, TransactionListener callback)`
  Starts a new transaction (or joins an existing one) calling `TransactionalOperation.perform()`, and then committing or rolling back the transaction.
  `<T> T`
  `performInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor)`
  Performs operation in a transaction which parameters described by descriptor.

- ## Method Details

  - ### performInTransaction

    <T> T performInTransaction(TransactionalOperation<T> op)
    Starts a new transaction (or joins an existing one) calling `TransactionalOperation.perform()`, and then committing or rolling back the transaction.
    Type Parameters:
      `T` - returned value type
    Parameters:
      `op` - an operation to perform within the transaction.
    Returns:
      a value returned by the "op" operation.

  - ### performInTransaction

    <T> T performInTransaction(TransactionalOperation<T> op, TransactionListener callback)
    Starts a new transaction (or joins an existing one) calling `TransactionalOperation.perform()`, and then committing or rolling back the transaction. As transaction goes through stages, callback methods are invoked allowing the caller to customize transaction parameters.
    Type Parameters:
      `T` - returned value type
    Parameters:
      `op` - an operation to perform within the transaction.
      `callback` - a callback to notify as transaction progresses through stages.
    Returns:
      a value returned by the "op" operation.

  - ### performInTransaction

    <T> T performInTransaction(TransactionalOperation<T> op, TransactionDescriptor descriptor)
    Performs operation in a transaction which parameters described by descriptor.
    Type Parameters:
      `T` - result type
    Parameters:
      `op` - an operation to perform within the transaction.
      `descriptor` - transaction descriptor
    Returns:
      a value returned by the "op" operation.
    Since:
      4.1

  - ### performInTransaction

    <T> T performInTransaction(TransactionalOperation<T> op, TransactionListener callback, TransactionDescriptor descriptor)
    Performs operation in a transaction which parameters described by descriptor. As transaction goes through stages, callback methods are invoked allowing the caller to customize transaction parameters.
    Type Parameters:
      `T` - returned value type
    Parameters:
      `op` - an operation to perform within the transaction.
      `callback` - a callback to notify as transaction progresses through stages.
      `descriptor` - transaction descriptor
    Returns:
      a value returned by the "op" operation.
    Since:
      4.1

  - ### performInTransaction

    <T> T performInTransaction(TransactionalOperation<T> op, TransactionFactory transactionFactory)
    Performs an operation in a transaction created by the supplied factory, instead of the configured one. This lets callers run an operation in a special transaction, such as a `ReadOnlyTransaction`. Behaves like `TransactionPropagation.NESTED` - joining an existing transaction if one is bound, otherwise creating a new one from the given factory.
    Type Parameters:
      `T` - returned value type
    Parameters:
      `op` - an operation to perform within the transaction.
      `transactionFactory` - a factory for the transaction to run the operation in.
    Returns:
      a value returned by the "op" operation.
    Since:
      5.0