Save This Page
Home » spring-framework-2.5.6-with-dependencies » org.springframework » transaction » interceptor » [javadoc | source]
org.springframework.transaction.interceptor
abstract public class: TransactionAspectSupport [javadoc | source]
java.lang.Object
   org.springframework.transaction.interceptor.TransactionAspectSupport

All Implemented Interfaces:
    InitializingBean

Direct Known Subclasses:
    TransactionInterceptor

Base class for transactional aspects, such as the AOP Alliance 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 it's PlatformTransactionManager and TransactionAttributeSource are serializable.

Nested Class Summary:
protected class  TransactionAspectSupport.TransactionInfo  Opaque object used to hold Transaction information. Subclasses must pass it back to methods on this class, but not see its internals. 
Field Summary
protected final  Log logger     
Method from org.springframework.transaction.interceptor.TransactionAspectSupport Summary:
afterPropertiesSet,   cleanupTransactionInfo,   commitTransactionAfterReturning,   completeTransactionAfterThrowing,   createTransactionIfNecessary,   createTransactionIfNecessary,   currentTransactionInfo,   currentTransactionStatus,   getTransactionAttributeSource,   getTransactionManager,   methodIdentification,   prepareTransactionInfo,   setTransactionAttributeSource,   setTransactionAttributeSources,   setTransactionAttributes,   setTransactionManager
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.transaction.interceptor.TransactionAspectSupport Detail:
 public  void afterPropertiesSet() 
    Check that required properties were set.
 protected  void cleanupTransactionInfo(TransactionAspectSupport.TransactionInfo txInfo) 
    Reset the TransactionInfo ThreadLocal.

    Call this in all cases: exception or normal return!

 protected  void commitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo) 
    Execute after successful completion of call, but not after an exception was handled. Do nothing if we didn't create a transaction.
 protected  void completeTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo,
    Throwable ex) 
    Handle a throwable, completing the transaction. We may commit or roll back, depending on the configuration.
 protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(Method method,
    Class targetClass) 
    Create a transaction if necessary, based on the given method and class.

    Performs a default TransactionAttribute lookup for the given method.

 protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(TransactionAttribute txAttr,
    String joinpointIdentification) 
    Create a transaction if necessary based on the given TransactionAttribute.

    Allows callers to perform custom TransactionAttribute lookups through the TransactionAttributeSource.

 protected static TransactionAspectSupport.TransactionInfo currentTransactionInfo() throws NoTransactionException 
    Subclasses can use this to return the current TransactionInfo. Only subclasses that cannot handle all operations in one method, such as an AspectJ aspect involving distinct before and after advice, need to use this mechanism to get at the current TransactionInfo. An around advice such as an AOP Alliance MethodInterceptor can hold a reference to the TransactionInfo throughout the aspect method.

    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.

 public static TransactionStatus currentTransactionStatus() throws NoTransactionException 
    Return the transaction status of the current method invocation. Mainly intended for code that wants to set the current transaction rollback-only but not throw an application exception.
 public TransactionAttributeSource getTransactionAttributeSource() 
    Return the transaction attribute source.
 public 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. Can be overridden in subclasses to provide a different identifier for the given method.
 protected TransactionAspectSupport.TransactionInfo prepareTransactionInfo(TransactionAttribute txAttr,
    String joinpointIdentification,
    TransactionStatus status) 
    Prepare a TransactionInfo for the given attribute and status object.
 public  void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) 
    Set the transaction attribute source which is used to find transaction attributes. If specifying a String property value, a PropertyEditor will create a MethodMapTransactionAttributeSource from the value.
 public  void setTransactionAttributeSources(TransactionAttributeSource[] transactionAttributeSources) 
    Set multiple transaction attribute sources which are used to find transaction attributes. Will build a CompositeTransactionAttributeSource for the given sources.
 public  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".

    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.

 public  void setTransactionManager(PlatformTransactionManager transactionManager) 
    Set the transaction manager. This will perform actual transaction management: This class is just a way of invoking it.