public class AnnotationTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource implements java.io.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 javax.transaction.Transactional
and EJB3's
javax.ejb.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 FormModifier and Type | Field and Description |
---|---|
private java.util.Set<TransactionAnnotationParser> |
annotationParsers |
private static boolean |
ejb3Present |
private static boolean |
jta12Present |
private boolean |
publicMethodsOnly |
logger
Constructor and Description |
---|
AnnotationTransactionAttributeSource()
Create a default AnnotationTransactionAttributeSource, supporting
public methods that carry the
Transactional annotation
or the EJB3 javax.ejb.TransactionAttribute annotation. |
AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
Create a custom AnnotationTransactionAttributeSource, supporting
public methods that carry the
Transactional annotation
or the EJB3 javax.ejb.TransactionAttribute annotation. |
AnnotationTransactionAttributeSource(java.util.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(java.lang.reflect.AnnotatedElement element)
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() |
boolean |
isCandidateClass(java.lang.Class<?> targetClass)
Determine whether the given class is a candidate for transaction attributes
in the metadata format of this
TransactionAttributeSource . |
computeTransactionAttribute, getCacheKey, getTransactionAttribute
private static final boolean jta12Present
private static final boolean ejb3Present
private final boolean publicMethodsOnly
private final java.util.Set<TransactionAnnotationParser> annotationParsers
public AnnotationTransactionAttributeSource()
Transactional
annotation
or the EJB3 javax.ejb.TransactionAttribute
annotation.public AnnotationTransactionAttributeSource(boolean publicMethodsOnly)
Transactional
annotation
or the EJB3 javax.ejb.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(java.util.Set<TransactionAnnotationParser> annotationParsers)
annotationParsers
- the TransactionAnnotationParsers to usepublic boolean isCandidateClass(java.lang.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(java.lang.Class<?> clazz)
AbstractFallbackTransactionAttributeSource
findTransactionAttribute
in class AbstractFallbackTransactionAttributeSource
clazz
- the class to retrieve the attribute fornull
if none@Nullable protected TransactionAttribute findTransactionAttribute(java.lang.reflect.Method method)
AbstractFallbackTransactionAttributeSource
findTransactionAttribute
in class AbstractFallbackTransactionAttributeSource
method
- the method to retrieve the attribute fornull
if none@Nullable protected TransactionAttribute determineTransactionAttribute(java.lang.reflect.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
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object