Class AnnotationTransactionAttributeSource
- All Implemented Interfaces:
Serializable,Aware,EmbeddedValueResolverAware,TransactionAttributeSource
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 JTA 1.2's Transactional and EJB3's
TransactionAttribute annotation (if present).
This class may also serve as base class for a custom TransactionAttributeSource,
or get customized through TransactionAnnotationParser strategies.
- Since:
- 1.2
- Author:
- Colin Sampaleanu, Juergen Hoeller
- See Also:
-
TransactionalTransactionAnnotationParserSpringTransactionAnnotationParserEjb3TransactionAnnotationParserTransactionAspectSupport.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
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionprotected booleanBy default, only public methods can be made transactional.protected TransactionAttributeDetermine the transaction attribute for the given method or class.booleanprotected 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()booleanisCandidateClass(Class<?> targetClass) Determine whether the given class is a candidate for transaction attributes in the metadata format of thisTransactionAttributeSource.Methods inherited from class org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource
computeTransactionAttribute, getCacheKey, getTransactionAttribute, setEmbeddedValueResolver
-
Constructor Details
-
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
Create a custom AnnotationTransactionAttributeSource.- Parameters:
annotationParser- the TransactionAnnotationParser to use
-
AnnotationTransactionAttributeSource
Create a custom AnnotationTransactionAttributeSource.- Parameters:
annotationParsers- the TransactionAnnotationParsers to use
-
AnnotationTransactionAttributeSource
Create a custom AnnotationTransactionAttributeSource.- Parameters:
annotationParsers- the TransactionAnnotationParsers to use
-
-
Method Details
-
isCandidateClass
Description copied from interface:TransactionAttributeSourceDetermine whether the given class is a candidate for transaction attributes in the metadata format of thisTransactionAttributeSource.If this method returns
false, the methods on the given class will not get traversed forTransactionAttributeSource.getTransactionAttribute(java.lang.reflect.Method, java.lang.Class<?>)introspection. Returningfalseis therefore an optimization for non-affected classes, whereastruesimply means that the class needs to get fully introspected for each method on the given class individually.- Specified by:
isCandidateClassin interfaceTransactionAttributeSource- Parameters:
targetClass- the class to introspect- Returns:
falseif the class is known to have no transaction attributes at class or method level;trueotherwise. The default implementation returnstrue, leading to regular introspection.
-
findTransactionAttribute
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
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
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
-
equals
-
hashCode
public int hashCode()
-