|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.transaction.interceptor.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.
Uses the Strategy design pattern. A PlatformTransactionManager implementation will perform the actual transaction management.
This class could set JTA as default transaction manager as that implementation does not need any specific configuration. JTA is not the default though to avoid unnecessary dependencies.
A transaction aspect is serializable if its PlatformTransactionManager and TransactionAttributeSource are serializable.
Nested Class Summary | |
protected class |
TransactionAspectSupport.TransactionInfo
Opaque object used to hold Transaction information. |
Field Summary | |
protected org.apache.commons.logging.Log |
logger
Transient to avoid serialization. |
protected TransactionAttributeSource |
transactionAttributeSource
Helper used to find transaction attributes |
protected PlatformTransactionManager |
transactionManager
Delegate used to create, commit and rollback transactions |
Constructor Summary | |
TransactionAspectSupport()
|
Method Summary | |
void |
afterPropertiesSet()
Check that required properties were set. |
protected TransactionAspectSupport.TransactionInfo |
createTransactionIfNecessary(java.lang.reflect.Method method,
java.lang.Class targetClass)
Create a transaction if necessary |
protected static TransactionAspectSupport.TransactionInfo |
currentTransactionInfo()
Subclasses can use this to return the current TransactionInfo. |
static TransactionStatus |
currentTransactionStatus()
Return the transaction transactionStatus of the current method invocation. |
protected void |
doCloseTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo,
java.lang.Throwable ex)
Handle a throwable, closing out the transaction. |
protected void |
doCommitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo)
Execute after successful completion of call, but not after an exception was handled. |
protected void |
doFinally(TransactionAspectSupport.TransactionInfo txInfo)
Call this in all cases: exception or normal return. |
TransactionAttributeSource |
getTransactionAttributeSource()
Return the transaction attribute source. |
PlatformTransactionManager |
getTransactionManager()
Return the transaction manager. |
protected java.lang.String |
methodIdentification(java.lang.reflect.Method method)
Convenience method to return a String representation of this Method for use in logging. |
void |
setTransactionAttributes(java.util.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 |
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 transient org.apache.commons.logging.Log logger
protected PlatformTransactionManager transactionManager
protected TransactionAttributeSource transactionAttributeSource
Constructor Detail |
public TransactionAspectSupport()
Method Detail |
public static TransactionStatus currentTransactionStatus() throws NoTransactionException
NoTransactionException
- if the transaction info cannot be found, because the method was invoked
outside an AOP invocation contextprotected static TransactionAspectSupport.TransactionInfo currentTransactionInfo() throws NoTransactionException
NoTransactionException
- if no transaction has been created
by an aspectpublic void setTransactionManager(PlatformTransactionManager transactionManager)
public PlatformTransactionManager getTransactionManager()
public void setTransactionAttributes(java.util.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 setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)
TransactionAttributeSourceEditor
,
MethodMapTransactionAttributeSource
,
NameMatchTransactionAttributeSource
public TransactionAttributeSource getTransactionAttributeSource()
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(java.lang.reflect.Method method, java.lang.Class targetClass)
method
- method about to executetargetClass
- class the method is on
protected java.lang.String methodIdentification(java.lang.reflect.Method method)
method
- method we're interested in
protected void doCommitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo)
txInfo
- information about the current transactionprotected void doCloseTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo, java.lang.Throwable ex)
txInfo
- information about the current transactionex
- throwable encounteredprotected void doFinally(TransactionAspectSupport.TransactionInfo txInfo)
txInfo
- information about the current transaction. May be null.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |