|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.transaction.interceptor.TransactionAspectSupport
public abstract class TransactionAspectSupport
Superclass for transactional aspects, such as the AOP Alliance-compatible TransactionInterceptor, or an AspectJ aspect. This enables the underlying Spring transaction infrastructure to be used easily to implement an aspect for any aspect system.
Subclasses are responsible for calling methods in this class in the correct order.
If no transaction name has been specified in the TransactionAttribute, the exposed name will be the fully-qualified class name + "." + method name (by default).
Uses the Strategy design pattern. A PlatformTransactionManager implementation will perform the actual transaction management, and a TransactionAttributeSource is used for determining transaction definitions.
A transaction aspect is serializable if its PlatformTransactionManager and TransactionAttributeSource are serializable.
setTransactionManager(org.springframework.transaction.PlatformTransactionManager)
,
setTransactionAttributes(java.util.Properties)
,
setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource)
Nested Class Summary | |
---|---|
protected class |
TransactionAspectSupport.TransactionInfo
Opaque object used to hold Transaction information. |
Field Summary | |
---|---|
protected Log |
logger
|
Constructor Summary | |
---|---|
TransactionAspectSupport()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Check that required properties were set. |
protected void |
cleanupTransactionInfo(TransactionAspectSupport.TransactionInfo txInfo)
Reset the TransactionInfo ThreadLocal. |
protected void |
commitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo)
Execute after successful completion of call, but not after an exception was handled. |
protected void |
completeTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo,
Throwable ex)
Handle a throwable, completing the transaction. |
protected TransactionAspectSupport.TransactionInfo |
createTransactionIfNecessary(Method method,
Class targetClass)
Create a transaction if necessary, based on the given method and class. |
protected TransactionAspectSupport.TransactionInfo |
createTransactionIfNecessary(TransactionAttribute txAttr,
String joinpointIdentification)
Create a transaction if necessary based on the given TransactionAttribute. |
protected static TransactionAspectSupport.TransactionInfo |
currentTransactionInfo()
Subclasses can use this to return the current TransactionInfo. |
static TransactionStatus |
currentTransactionStatus()
Return the transaction status of the current method invocation. |
TransactionAttributeSource |
getTransactionAttributeSource()
Return the transaction attribute source. |
PlatformTransactionManager |
getTransactionManager()
Return the transaction manager. |
protected String |
methodIdentification(Method method)
Convenience method to return a String representation of this Method for use in logging. |
protected TransactionAspectSupport.TransactionInfo |
prepareTransactionInfo(TransactionAttribute txAttr,
String joinpointIdentification,
TransactionStatus status)
Prepare a TransactionInfo for the given attribute and status object. |
void |
setTransactionAttributes(Properties transactionAttributes)
Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly". |
void |
setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
Set the transaction attribute source which is used to find transaction attributes. |
void |
setTransactionAttributeSources(TransactionAttributeSource[] transactionAttributeSources)
Set multiple transaction attribute sources which are used to find transaction attributes. |
void |
setTransactionManager(PlatformTransactionManager transactionManager)
Set the transaction manager. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public TransactionAspectSupport()
Method Detail |
---|
protected static TransactionAspectSupport.TransactionInfo currentTransactionInfo() throws NoTransactionException
A TransactionInfo will be returned even if no transaction was created.
The TransactionInfo.hasTransaction()
method can be used to query this.
To find out about specific transaction characteristics, consider using
TransactionSynchronizationManager's isSynchronizationActive()
and/or isActualTransactionActive()
methods.
null
if none
NoTransactionException
TransactionAspectSupport.TransactionInfo.hasTransaction()
,
TransactionSynchronizationManager.isSynchronizationActive()
,
TransactionSynchronizationManager.isActualTransactionActive()
public static TransactionStatus currentTransactionStatus() throws NoTransactionException
NoTransactionException
- if the transaction info cannot be found,
because the method was invoked outside an AOP invocation contextpublic void setTransactionManager(PlatformTransactionManager transactionManager)
public PlatformTransactionManager getTransactionManager()
public void setTransactionAttributes(Properties transactionAttributes)
Note: Method names are always applied to the target class, no matter if defined in an interface or the class itself.
Internally, a NameMatchTransactionAttributeSource will be created from the given properties.
setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource)
,
TransactionAttributeEditor
,
NameMatchTransactionAttributeSource
public void setTransactionAttributeSources(TransactionAttributeSource[] transactionAttributeSources)
CompositeTransactionAttributeSource
,
MethodMapTransactionAttributeSource
,
NameMatchTransactionAttributeSource
,
AttributesTransactionAttributeSource
,
AnnotationTransactionAttributeSource
public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
TransactionAttributeSourceEditor
,
MethodMapTransactionAttributeSource
,
NameMatchTransactionAttributeSource
,
AttributesTransactionAttributeSource
,
AnnotationTransactionAttributeSource
public TransactionAttributeSource getTransactionAttributeSource()
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(Method method, Class targetClass)
Performs a default TransactionAttribute lookup for the given method.
method
- method about to executetargetClass
- class the method is on
getTransactionAttributeSource()
protected String methodIdentification(Method method)
method
- the method we're interested in
ClassUtils.getQualifiedMethodName(java.lang.reflect.Method)
protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(TransactionAttribute txAttr, String joinpointIdentification)
Allows callers to perform custom TransactionAttribute lookups through the TransactionAttributeSource.
txAttr
- the TransactionAttribute (may be null
)joinpointIdentification
- the fully qualified method name
(used for monitoring and logging purposes)
hasTransaction()
method on TransactionInfo can be used to
tell if there was a transaction created.getTransactionAttributeSource()
protected TransactionAspectSupport.TransactionInfo prepareTransactionInfo(TransactionAttribute txAttr, String joinpointIdentification, TransactionStatus status)
txAttr
- the TransactionAttribute (may be null
)joinpointIdentification
- the fully qualified method name
(used for monitoring and logging purposes)status
- the TransactionStatus for the current transaction
protected void commitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo)
txInfo
- information about the current transactionprotected void completeTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo, Throwable ex)
txInfo
- information about the current transactionex
- throwable encounteredprotected void cleanupTransactionInfo(TransactionAspectSupport.TransactionInfo txInfo)
Call this in all cases: exception or normal return!
txInfo
- information about the current transaction (may be null
)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |