Class AbstractSynchronousTransactionManager<T>

  • Type Parameters:
    T - The resource type
    All Implemented Interfaces:
    TransactionStateOperations<T,​SynchronousTransactionState>, SynchronousTransactionManager<T>, TransactionManager, TransactionOperations<T>, java.io.Serializable
    Direct Known Subclasses:
    DataSourceTransactionManager, HibernateTransactionManager, MongoSynchronousTransactionManagerImpl

    @Internal
    public abstract class AbstractSynchronousTransactionManager<T>
    extends AbstractSynchronousStateTransactionManager<T>
    implements SynchronousTransactionManager<T>, java.io.Serializable
    NOTICE: This is a fork of Spring's AbstractPlatformTransactionManager modernizing it to use enums, Slf4j and decoupling from Spring. Abstract base class that implements standard transaction workflow, serving as basis for concrete platform transaction managers.

    This base class provides the following workflow handling:

    • determines if there is an existing transaction;
    • applies the appropriate propagation behavior;
    • suspends and resumes transactions if necessary;
    • checks the rollback-only flag on commit;
    • applies the appropriate modification on rollback (actual rollback or setting rollback-only);
    • triggers registered synchronization callbacks (if transaction synchronization is active).

    Subclasses have to implement specific template methods for specific states of a transaction, e.g.: begin, suspend, resume, commit, rollback. The most important of them are abstract and must be provided by a concrete implementation; for the rest, defaults are provided, so overriding is optional.

    Transaction synchronization is a generic mechanism for registering callbacks that get invoked at transaction completion time. This is mainly used internally by the data access support classes for JDBC, Hibernate, JPA, etc when running within a JTA transaction: They register resources that are opened within the transaction for closing at transaction completion time, allowing e.g. for reuse of the same Hibernate Session within the transaction. The same mechanism can also be leveraged for custom synchronization needs in an application.

    The state of this class is serializable, to allow for serializing the transaction strategy along with proxies that carry a transaction interceptor. It is up to subclasses if they wish to make their state to be serializable too. They should implement the java.io.Serializable marker interface in that case, and potentially a private readObject() method (according to Java serialization rules) if they need to restore any transient state.

    Since:
    28.03.2003
    Author:
    Juergen Hoeller, graemerocher
    See Also:
    AbstractSynchronousStateTransactionManager.setTransactionSynchronization(io.micronaut.transaction.support.AbstractSynchronousStateTransactionManager.Synchronization), TransactionSynchronizationManager, Serialized Form