Class AnnotationTransactionAttributeSource
- java.lang.Object
- org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
- org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
- All Implemented Interfaces:
Serializable,TransactionAttributeSource
public class AnnotationTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource implements Serializable
Implementation of theTransactionAttributeSourceinterface for working with transaction metadata in JDK 1.5+ annotation format.This class reads Spring's JDK 1.5+
Transactionalannotation and exposes corresponding transaction attributes to Spring's transaction infrastructure. Also supports JTA 1.2'sTransactionaland EJB3'sTransactionAttributeannotation (if present). This class may also serve as base class for a custom TransactionAttributeSource, or get customized throughTransactionAnnotationParserstrategies.- 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
Constructors Constructor Description AnnotationTransactionAttributeSource()Create a default AnnotationTransactionAttributeSource, supporting public methods that carry theTransactionalannotation or the EJB3TransactionAttributeannotation.AnnotationTransactionAttributeSource(boolean publicMethodsOnly)Create a custom AnnotationTransactionAttributeSource, supporting public methods that carry theTransactionalannotation or the EJB3TransactionAttributeannotation.AnnotationTransactionAttributeSource(Set<TransactionAnnotationParser> annotationParsers)Create a custom AnnotationTransactionAttributeSource.AnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser)Create a custom AnnotationTransactionAttributeSource.AnnotationTransactionAttributeSource(TransactionAnnotationParser... annotationParsers)Create a custom AnnotationTransactionAttributeSource.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanallowPublicMethodsOnly()By default, only public methods can be made transactional.protected TransactionAttributedetermineTransactionAttribute(AnnotatedElement element)Determine the transaction attribute for the given method or class.booleanequals(Object other)protected TransactionAttributefindTransactionAttribute(Class<?> clazz)Subclasses need to implement this to return the transaction attribute for the given class, if any.protected TransactionAttributefindTransactionAttribute(Method method)Subclasses need to implement this to return the transaction attribute for the given method, if any.inthashCode()Methods inherited from class org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
computeTransactionAttribute, getCacheKey, getTransactionAttribute
Constructor Detail
AnnotationTransactionAttributeSource
public AnnotationTransactionAttributeSource()
Create a default AnnotationTransactionAttributeSource, supporting public methods that carry theTransactionalannotation or the EJB3TransactionAttributeannotation.
AnnotationTransactionAttributeSource
public AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
Create a custom AnnotationTransactionAttributeSource, supporting public methods that carry theTransactionalannotation or the EJB3TransactionAttributeannotation.- Parameters:
publicMethodsOnly- whether to support public methods that carry theTransactionalannotation 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(TransactionAnnotationParser... annotationParsers)
Create a custom AnnotationTransactionAttributeSource.- Parameters:
annotationParsers- the TransactionAnnotationParsers to use
AnnotationTransactionAttributeSource
public AnnotationTransactionAttributeSource(Set<TransactionAnnotationParser> annotationParsers)
Create a custom AnnotationTransactionAttributeSource.- Parameters:
annotationParsers- the TransactionAnnotationParsers to use
Method Detail
findTransactionAttribute
protected TransactionAttribute findTransactionAttribute(Class<?> clazz)
Description copied from class:AbstractFallbackTransactionAttributeSourceSubclasses need to implement this to return the transaction attribute for the given class, if any.- Specified by:
findTransactionAttributein classAbstractFallbackTransactionAttributeSource- Parameters:
clazz- the class to retrieve the attribute for- Returns:
- all transaction attribute associated with this class, or
nullif none
findTransactionAttribute
protected TransactionAttribute findTransactionAttribute(Method method)
Description copied from class:AbstractFallbackTransactionAttributeSourceSubclasses need to implement this to return the transaction attribute for the given method, if any.- Specified by:
findTransactionAttributein classAbstractFallbackTransactionAttributeSource- Parameters:
method- the method to retrieve the attribute for- Returns:
- all transaction attribute associated with this method, or
nullif none
determineTransactionAttribute
protected TransactionAttribute determineTransactionAttribute(AnnotatedElement element)
Determine the transaction attribute for the given method or class.This implementation delegates to configured
TransactionAnnotationParsersfor parsing known annotations into Spring's metadata attribute class. Returnsnullif it's not transactional.Can be overridden to support custom annotations that carry transaction metadata.
- Parameters:
element- the annotated method or class- Returns:
- the configured transaction attribute, or
nullif none was found
allowPublicMethodsOnly
protected boolean allowPublicMethodsOnly()
By default, only public methods can be made transactional.- Overrides:
allowPublicMethodsOnlyin classAbstractFallbackTransactionAttributeSource