Class SpringAwareUserTransaction

  • All Implemented Interfaces:
    UserTransaction, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.transaction.interceptor.TransactionAttribute, org.springframework.transaction.interceptor.TransactionAttributeSource, org.springframework.transaction.TransactionDefinition

    public class SpringAwareUserTransaction
    extends org.springframework.transaction.interceptor.TransactionAspectSupport
    implements UserTransaction, org.springframework.transaction.interceptor.TransactionAttributeSource, org.springframework.transaction.interceptor.TransactionAttribute
    A UserTransaction that will allow the thread using it to participate in transactions that are normally only begun and committed by the SpringFramework transaction aware components.

    Client code can use this class directly, but should be very careful to handle the exception conditions with the appropriate finally blocks and rollback code. It is recommended that clients use this class indirectly via an instance of the org.alfresco.repo.transaction.RetryingTransactionHelper.

    This class is thread-safe in that it will detect multithreaded access and throw exceptions. Therefore do not use on multiple threads. Instances should be used only for the duration of the required user transaction and then discarded. Any attempt to reuse an instance will result in failure.

    Nested user transaction are allowed.

    Logging:
    To dump exceptions during commits, turn debugging on for this class.
    To log leaked transactions i.e. a begin() is not matched by a commit() or rollback(), add .trace to the usual classname-based debug category and set to WARN log level. This will log the first detection of a leaked transaction and automatically enable transaction call stack logging for subsequent leaked transactions. To enforce call stack logging from the start set the .trace log level to DEBUG. Call stack logging will hamper performance but is useful when it appears that something is eating connections or holding onto resources - usually a sign that client code hasn't handled all possible exception conditions.

    Author:
    Derek Hulley
    See Also:
    PlatformTransactionManager, DefaultTransactionDefinition
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.springframework.transaction.interceptor.TransactionAspectSupport

        org.springframework.transaction.interceptor.TransactionAspectSupport.InvocationCallback, org.springframework.transaction.interceptor.TransactionAspectSupport.TransactionInfo
    • Field Summary

      • Fields inherited from interface org.springframework.transaction.TransactionDefinition

        ISOLATION_DEFAULT, ISOLATION_READ_COMMITTED, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, PROPAGATION_MANDATORY, PROPAGATION_NESTED, PROPAGATION_NEVER, PROPAGATION_NOT_SUPPORTED, PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, PROPAGATION_SUPPORTS, TIMEOUT_DEFAULT
    • Constructor Summary

      Constructors 
      Constructor Description
      SpringAwareUserTransaction​(org.springframework.transaction.PlatformTransactionManager transactionManager, boolean readOnly, int isolationLevel, int propagationBehaviour, int timeout)
      Creates a user transaction that defaults to TransactionDefinition.PROPAGATION_REQUIRED.
    • Constructor Detail

      • SpringAwareUserTransaction

        public SpringAwareUserTransaction​(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                          boolean readOnly,
                                          int isolationLevel,
                                          int propagationBehaviour,
                                          int timeout)
        Creates a user transaction that defaults to TransactionDefinition.PROPAGATION_REQUIRED.
        Parameters:
        transactionManager - the transaction manager to use
        readOnly - true to force a read-only transaction
        isolationLevel - one of the TransactionDefinition.ISOLATION_XXX constants
        propagationBehaviour - one of the TransactionDefinition.PROPAGATION__XXX constants
        timeout - the transaction timeout in seconds.
        See Also:
        TransactionDefinition.getTimeout()