Class SpringAwareUserTransaction
- java.lang.Object
-
- org.springframework.transaction.interceptor.TransactionAspectSupport
-
- org.alfresco.util.transaction.SpringAwareUserTransaction
-
- All Implemented Interfaces:
javax.transaction.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 javax.transaction.UserTransaction, org.springframework.transaction.interceptor.TransactionAttributeSource, org.springframework.transaction.interceptor.TransactionAttributeAUserTransactionthat 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
finallyblocks androllbackcode. It is recommended that clients use this class indirectly via an instance of theorg.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.CoroutinesInvocationCallback, 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 toTransactionDefinition.PROPAGATION_REQUIRED.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbegin()voidcommit()protected voidcompleteTransactionAfterThrowing(org.springframework.transaction.interceptor.TransactionAspectSupport.TransactionInfo txInfo, Throwable ex)protected voidfinalize()intgetIsolationLevel()Collection<String>getLabels()StringgetName()intgetPropagationBehavior()StringgetQualifier()Return a qualifier value associated with this transaction attribute.intgetStatus()This status is a combination of the internal status, as recorded during explicit operations, and the status provided by the Spring support.intgetTimeout()org.springframework.transaction.interceptor.TransactionAttributegetTransactionAttribute(Method method, Class<?> targetClass)This class carries all the information required to fullfil requests about the transaction attributes.booleanisReadOnly()voidrollback()booleanrollbackOn(Throwable ex)TheUserTransactionmust rollback regardless of the error.voidsetLabels(Collection<String> labels)Associate one or more labels with this transaction attribute.voidsetRollbackOnly()voidsetTransactionTimeout(int timeout)Implementation required forUserTransaction.StringtoString()-
Methods inherited from class org.springframework.transaction.interceptor.TransactionAspectSupport
afterPropertiesSet, cleanupTransactionInfo, clearTransactionManagerCache, commitTransactionAfterReturning, createTransactionIfNecessary, currentTransactionInfo, currentTransactionStatus, determineTransactionManager, getBeanFactory, getTransactionAttributeSource, getTransactionManager, getTransactionManagerBeanName, invokeWithinTransaction, methodIdentification, prepareTransactionInfo, setBeanFactory, setTransactionAttributes, setTransactionAttributeSource, setTransactionAttributeSources, setTransactionManager, setTransactionManagerBeanName
-
-
-
-
Constructor Detail
-
SpringAwareUserTransaction
public SpringAwareUserTransaction(org.springframework.transaction.PlatformTransactionManager transactionManager, boolean readOnly, int isolationLevel, int propagationBehaviour, int timeout)Creates a user transaction that defaults toTransactionDefinition.PROPAGATION_REQUIRED.- Parameters:
transactionManager- the transaction manager to usereadOnly- true to force a read-only transactionisolationLevel- one of theTransactionDefinition.ISOLATION_XXXconstantspropagationBehaviour- one of theTransactionDefinition.PROPAGATION__XXXconstantstimeout- the transaction timeout in seconds.- See Also:
TransactionDefinition.getTimeout()
-
-
Method Detail
-
getTransactionAttribute
public org.springframework.transaction.interceptor.TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass)
This class carries all the information required to fullfil requests about the transaction attributes. It acts as a source of the transaction attributes.- Specified by:
getTransactionAttributein interfaceorg.springframework.transaction.interceptor.TransactionAttributeSource- Returns:
- Return
thisinstance
-
getQualifier
public String getQualifier()
Return a qualifier value associated with this transaction attribute. This is not used as the transaction manager has been selected for us.- Specified by:
getQualifierin interfaceorg.springframework.transaction.interceptor.TransactionAttribute- Returns:
- null always
-
setLabels
public void setLabels(Collection<String> labels)
Associate one or more labels with this transaction attribute.This may be used for applying specific transactional behavior or follow a purely descriptive nature.
-
getLabels
public Collection<String> getLabels()
- Specified by:
getLabelsin interfaceorg.springframework.transaction.interceptor.TransactionAttribute
-
rollbackOn
public boolean rollbackOn(Throwable ex)
TheUserTransactionmust rollback regardless of the error. Therollbackbehaviour is implemented by simulating a caught exception. As this method will always returntrue, the rollback behaviour will be to rollback the transaction or mark it for rollback.- Specified by:
rollbackOnin interfaceorg.springframework.transaction.interceptor.TransactionAttribute- Returns:
- Returns true always
-
getName
public String getName()
- Specified by:
getNamein interfaceorg.springframework.transaction.TransactionDefinition
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceorg.springframework.transaction.TransactionDefinition
-
getIsolationLevel
public int getIsolationLevel()
- Specified by:
getIsolationLevelin interfaceorg.springframework.transaction.TransactionDefinition
-
getPropagationBehavior
public int getPropagationBehavior()
- Specified by:
getPropagationBehaviorin interfaceorg.springframework.transaction.TransactionDefinition
-
getTimeout
public int getTimeout()
- Specified by:
getTimeoutin interfaceorg.springframework.transaction.TransactionDefinition
-
setTransactionTimeout
public void setTransactionTimeout(int timeout) throws javax.transaction.SystemExceptionImplementation required forUserTransaction.- Specified by:
setTransactionTimeoutin interfacejavax.transaction.UserTransaction- Throws:
javax.transaction.SystemException
-
getStatus
public int getStatus() throws javax.transaction.SystemExceptionThis status is a combination of the internal status, as recorded during explicit operations, and the status provided by the Spring support.- Specified by:
getStatusin interfacejavax.transaction.UserTransaction- Throws:
javax.transaction.SystemException- See Also:
Status
-
setRollbackOnly
public void setRollbackOnly() throws IllegalStateException, javax.transaction.SystemException- Specified by:
setRollbackOnlyin interfacejavax.transaction.UserTransaction- Throws:
IllegalStateExceptionjavax.transaction.SystemException
-
begin
public void begin() throws javax.transaction.NotSupportedException, javax.transaction.SystemException- Specified by:
beginin interfacejavax.transaction.UserTransaction- Throws:
javax.transaction.NotSupportedException- if an attempt is made to reuse this instancejavax.transaction.SystemException
-
commit
public void commit() throws javax.transaction.RollbackException, javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, SecurityException, IllegalStateException, javax.transaction.SystemException- Specified by:
commitin interfacejavax.transaction.UserTransaction- Throws:
IllegalStateException- if a transaction was not startedjavax.transaction.RollbackExceptionjavax.transaction.HeuristicMixedExceptionjavax.transaction.HeuristicRollbackExceptionSecurityExceptionjavax.transaction.SystemException
-
rollback
public void rollback() throws IllegalStateException, SecurityException, javax.transaction.SystemException- Specified by:
rollbackin interfacejavax.transaction.UserTransaction- Throws:
IllegalStateExceptionSecurityExceptionjavax.transaction.SystemException
-
completeTransactionAfterThrowing
protected void completeTransactionAfterThrowing(org.springframework.transaction.interceptor.TransactionAspectSupport.TransactionInfo txInfo, Throwable ex)- Overrides:
completeTransactionAfterThrowingin classorg.springframework.transaction.interceptor.TransactionAspectSupport
-
-