public class AnnotationTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource implements Serializable
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.
Transactional
,
TransactionAnnotationParser
,
SpringTransactionAnnotationParser
,
Ejb3TransactionAnnotationParser
,
TransactionAspectSupport.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource)
,
TransactionProxyFactoryBean.setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource)
,
Serialized Formlogger
Constructor and Description |
---|
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(Set<TransactionAnnotationParser> annotationParsers)
Create a custom AnnotationTransactionAttributeSource.
|
AnnotationTransactionAttributeSource(TransactionAnnotationParser... annotationParsers)
Create a custom AnnotationTransactionAttributeSource.
|
AnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser)
Create a custom AnnotationTransactionAttributeSource.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowPublicMethodsOnly()
By default, only public methods can be made transactional.
|
protected TransactionAttribute |
determineTransactionAttribute(AnnotatedElement element)
Determine the transaction attribute for the given method or class.
|
boolean |
equals(Object other) |
protected TransactionAttribute |
findTransactionAttribute(Class<?> clazz)
Subclasses need to implement this to return the transaction attribute for the
given class, if any.
|
protected TransactionAttribute |
findTransactionAttribute(Method method)
Subclasses need to implement this to return the transaction attribute for the
given method, if any.
|
int |
hashCode() |
boolean |
isCandidateClass(Class<?> targetClass)
Determine whether the given class is a candidate for transaction attributes
in the metadata format of this
TransactionAttributeSource . |
computeTransactionAttribute, getCacheKey, getTransactionAttribute
public AnnotationTransactionAttributeSource()
Transactional
annotation
or the EJB3 TransactionAttribute
annotation.public AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
Transactional
annotation
or the EJB3 TransactionAttribute
annotation.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)public AnnotationTransactionAttributeSource(TransactionAnnotationParser annotationParser)
annotationParser
- the TransactionAnnotationParser to usepublic AnnotationTransactionAttributeSource(TransactionAnnotationParser... annotationParsers)
annotationParsers
- the TransactionAnnotationParsers to usepublic AnnotationTransactionAttributeSource(Set<TransactionAnnotationParser> annotationParsers)
annotationParsers
- the TransactionAnnotationParsers to usepublic boolean isCandidateClass(Class<?> targetClass)
TransactionAttributeSource
TransactionAttributeSource
.
If this method returns false
, the methods on the given class
will not get traversed for TransactionAttributeSource.getTransactionAttribute(java.lang.reflect.Method, java.lang.Class<?>)
introspection.
Returning false
is therefore an optimization for non-affected
classes, whereas true
simply means that the class needs to get
fully introspected for each method on the given class individually.
isCandidateClass
in interface TransactionAttributeSource
targetClass
- the class to introspectfalse
if the class is known to have no transaction
attributes at class or method level; true
otherwise. The default
implementation returns true
, leading to regular introspection.@Nullable protected TransactionAttribute findTransactionAttribute(Class<?> clazz)
AbstractFallbackTransactionAttributeSource
findTransactionAttribute
in class AbstractFallbackTransactionAttributeSource
clazz
- the class to retrieve the attribute fornull
if none@Nullable protected TransactionAttribute findTransactionAttribute(Method method)
AbstractFallbackTransactionAttributeSource
findTransactionAttribute
in class AbstractFallbackTransactionAttributeSource
method
- the method to retrieve the attribute fornull
if none@Nullable protected TransactionAttribute determineTransactionAttribute(AnnotatedElement element)
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.
element
- the annotated method or classnull
if none was foundprotected boolean allowPublicMethodsOnly()
allowPublicMethodsOnly
in class AbstractFallbackTransactionAttributeSource