org.springframework.transaction.annotation
Class AnnotationTransactionAttributeSource

java.lang.Object
  extended by org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
      extended by org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
All Implemented Interfaces:
java.io.Serializable, TransactionAttributeSource

public class AnnotationTransactionAttributeSource
extends AbstractFallbackTransactionAttributeSource
implements java.io.Serializable

Implementation of the TransactionAttributeSource interface for working with transaction metadata in JDK 1.5+ annotation format.

This class reads Spring's JDK 1.5+ Transactional annotation and exposes corresponding transaction attributes to Spring's transaction infrastructure. Also supports EJB3's TransactionAttribute annotation (if present). This class may also serve as base class for a custom TransactionAttributeSource, or get customized through TransactionAnnotationParser strategies.

This is a direct alternative to org.springframework.transaction.interceptor.AttributesTransactionAttributeSource, which is able to read in source-level attributes via Commons Attributes.

Since:
1.2
Author:
Colin Sampaleanu, Juergen Hoeller
See Also:
Transactional, TransactionAnnotationParser, SpringTransactionAnnotationParser, Ejb3TransactionAnnotationParser, TransactionAspectSupport.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource), TransactionProxyFactoryBean.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource), Serialized Form

Field Summary
 
Fields inherited from class org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
logger
 
Constructor Summary
AnnotationTransactionAttributeSource()
          Create a default AnnotationTransactionAttributeSource, supporting public methods that carry the Transactional annotation or the EJB3 TransactionAttribute annotation.
AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
          Create a custom AnnotationTransactionAttributeSource, supporting public methods that carry the Transactional annotation or the EJB3 TransactionAttribute annotation.
AnnotationTransactionAttributeSource(java.util.Set<TransactionAnnotationParser> annotationParsers)
          Create a custom AnnotationTransactionAttributeSource.
AnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser)
          Create a custom AnnotationTransactionAttributeSource.
 
Method Summary
protected  boolean allowPublicMethodsOnly()
          By default, only public methods can be made transactional.
protected  TransactionAttribute determineTransactionAttribute(java.lang.reflect.AnnotatedElement ae)
          Determine the transaction attribute for the given method or class.
 boolean equals(java.lang.Object other)
           
protected  TransactionAttribute findTransactionAttribute(java.lang.Class clazz)
          Subclasses need to implement this to return the transaction attribute for the given class, if any.
protected  TransactionAttribute findTransactionAttribute(java.lang.reflect.Method method)
          Subclasses need to implement this to return the transaction attribute for the given method, if any.
 int hashCode()
           
 
Methods inherited from class org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
getCacheKey, getTransactionAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationTransactionAttributeSource

public AnnotationTransactionAttributeSource()
Create a default AnnotationTransactionAttributeSource, supporting public methods that carry the Transactional annotation or the EJB3 TransactionAttribute annotation.


AnnotationTransactionAttributeSource

public AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
Create a custom AnnotationTransactionAttributeSource, supporting public methods that carry the Transactional annotation or the EJB3 TransactionAttribute annotation.

Parameters:
publicMethodsOnly - whether to support public methods that carry the Transactional annotation only (typically for use with proxy-based AOP), or protected/private methods as well (typically used with AspectJ class weaving)

AnnotationTransactionAttributeSource

public AnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser)
Create a custom AnnotationTransactionAttributeSource.

Parameters:
annotationParser - the TransactionAnnotationParser to use

AnnotationTransactionAttributeSource

public AnnotationTransactionAttributeSource(java.util.Set<TransactionAnnotationParser> annotationParsers)
Create a custom AnnotationTransactionAttributeSource.

Parameters:
annotationParsers - the TransactionAnnotationParsers to use
Method Detail

findTransactionAttribute

protected TransactionAttribute findTransactionAttribute(java.lang.reflect.Method method)
Description copied from class: AbstractFallbackTransactionAttributeSource
Subclasses need to implement this to return the transaction attribute for the given method, if any.

Specified by:
findTransactionAttribute in class AbstractFallbackTransactionAttributeSource
Parameters:
method - the method to retrieve the attribute for
Returns:
all transaction attribute associated with this method (or null if none)

findTransactionAttribute

protected TransactionAttribute findTransactionAttribute(java.lang.Class clazz)
Description copied from class: AbstractFallbackTransactionAttributeSource
Subclasses need to implement this to return the transaction attribute for the given class, if any.

Specified by:
findTransactionAttribute in class AbstractFallbackTransactionAttributeSource
Parameters:
clazz - the class to retrieve the attribute for
Returns:
all transaction attribute associated with this class (or null if none)

determineTransactionAttribute

protected TransactionAttribute determineTransactionAttribute(java.lang.reflect.AnnotatedElement ae)
Determine the transaction attribute for the given method or class.

This implementation delegates to configured TransactionAnnotationParsers for parsing known annotations into Spring's metadata attribute class. Returns null if it's not transactional.

Can be overridden to support custom annotations that carry transaction metadata.

Parameters:
ae - the annotated method or class
Returns:
TransactionAttribute the configured transaction attribute, or null if none was found

allowPublicMethodsOnly

protected boolean allowPublicMethodsOnly()
By default, only public methods can be made transactional.

Overrides:
allowPublicMethodsOnly in class AbstractFallbackTransactionAttributeSource

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object