Top Description Fields Constructors Methods
org.springframework.transaction.interceptor

public abstract Class AbstractFallbackTransactionAttributeSource

extends Object
implements TransactionAttributeSource, EmbeddedValueResolverAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.EmbeddedValueResolverAware, org.springframework.beans.factory.Aware, org.springframework.transaction.interceptor.TransactionAttributeSource
Known Direct Subclasses
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
Imports
java.lang.reflect.Method, .Modifier, java.util.Map, java.util.concurrent.ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.aop.support.AopUtils, org.springframework.context.EmbeddedValueResolverAware, org.springframework.core.MethodClassKey, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .StringValueResolver

Abstract implementation of TransactionAttributeSource that caches attributes for methods and implements a fallback policy: 1. specific target method; 2. target class; 3. declaring method; 4. declaring class/interface.

Defaults to using the target class's transaction attribute if none is associated with the target method. Any transaction attribute associated with the target method completely overrides a class transaction attribute. If none found on the target class, the interface that the invoked method has been called through (in case of a JDK proxy) will be checked.

This implementation caches attributes by method after they are first used. If it is ever desirable to allow dynamic changing of transaction attributes (which is very unlikely), caching could be made configurable. Caching is desirable because of the cost of evaluating rollback rules.

Authors
Rod Johnson, Juergen Hoeller
Since
1.1

Field Summary

Modifier and TypeField and Description
private final Map<Object, TransactionAttribute>
attributeCache

Cache of TransactionAttributes, keyed by method on a specific target class.

private transient StringValueResolver
protected final Log
logger

Logger available to subclasses.

private static final TransactionAttribute
NULL_TRANSACTION_ATTRIBUTE

Canonical value held in cache to indicate no transaction attribute was found for this method, and we don't need to look again.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
allowPublicMethodsOnly()

Should only public methods be allowed to have transactional semantics?

protected TransactionAttribute
computeTransactionAttribute(Method method, Class<?> targetClass)

Same signature as getTransactionAttribute, but doesn't cache the result.

protected abstract TransactionAttribute

Returns:

all transaction attribute associated with this class, or null if none
findTransactionAttribute
(Class<?>
the class to retrieve the attribute for
clazz
)

Subclasses need to implement this to return the transaction attribute for the given class, if any.

protected abstract TransactionAttribute

Returns:

all transaction attribute associated with this method, or null if none
findTransactionAttribute
(Method
the method to retrieve the attribute for
method
)

Subclasses need to implement this to return the transaction attribute for the given method, if any.

protected Object

Returns:

the cache key (never null)
getCacheKey
(Method
the method (never null)
method
,
Class<?>
the target class (may be null)
targetClass
)

Determine a cache key for the given method and target class.

public TransactionAttribute

Returns:

a TransactionAttribute for this method, or null if the method is not transactional
getTransactionAttribute
(Method
the method for the current invocation (never null)
method
,
Class<?>
the target class for this invocation (may be null)
targetClass
)

Implements org.springframework.transaction.interceptor.TransactionAttributeSource.getTransactionAttribute.

Determine the transaction attribute for this method invocation.
public void
setEmbeddedValueResolver(StringValueResolver resolver)

Implements org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Set the StringValueResolver to use for resolving embedded definition values.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeCacheback to summary
private final Map<Object, TransactionAttribute> attributeCache

Cache of TransactionAttributes, keyed by method on a specific target class.

As this base class is not marked Serializable, the cache will be recreated after serialization - provided that the concrete subclass is Serializable.

embeddedValueResolverback to summary
private transient StringValueResolver embeddedValueResolver
Annotations
@Nullable
loggerback to summary
protected final Log logger

Logger available to subclasses.

As this base class is not marked Serializable, the logger will be recreated after serialization - provided that the concrete subclass is Serializable.

NULL_TRANSACTION_ATTRIBUTEback to summary
private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE

Canonical value held in cache to indicate no transaction attribute was found for this method, and we don't need to look again.

Annotations
@SuppressWarnings:serial

Constructor Detail

AbstractFallbackTransactionAttributeSourceback to summary
public AbstractFallbackTransactionAttributeSource()

Method Detail

allowPublicMethodsOnlyback to summary
protected boolean allowPublicMethodsOnly()

Should only public methods be allowed to have transactional semantics?

The default implementation returns false.

computeTransactionAttributeback to summary
protected TransactionAttribute computeTransactionAttribute(Method method, Class<?> targetClass)

Same signature as getTransactionAttribute, but doesn't cache the result. getTransactionAttribute is effectively a caching decorator for this method.

As of 4.1.8, this method can be overridden.

Annotations
@Nullable
Since
4.1.8
See Also
getTransactionAttribute
findTransactionAttributeback to summary
protected abstract TransactionAttribute findTransactionAttribute(Class<?> clazz)

Subclasses need to implement this to return the transaction attribute for the given class, if any.

Parameters
clazz:Class<?>

the class to retrieve the attribute for

Returns:TransactionAttribute

all transaction attribute associated with this class, or null if none

Annotations
@Nullable
findTransactionAttributeback to summary
protected abstract TransactionAttribute findTransactionAttribute(Method method)

Subclasses need to implement this to return the transaction attribute for the given method, if any.

Parameters
method:Method

the method to retrieve the attribute for

Returns:TransactionAttribute

all transaction attribute associated with this method, or null if none

Annotations
@Nullable
getCacheKeyback to summary
protected Object getCacheKey(Method method, Class<?> targetClass)

Determine a cache key for the given method and target class.

Must not produce same key for overloaded methods. Must produce same key for different instances of the same method.

Parameters
method:Method

the method (never null)

targetClass:Class<?>

the target class (may be null)

Returns:Object

the cache key (never null)

getTransactionAttributeback to summary
public TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass)

Implements org.springframework.transaction.interceptor.TransactionAttributeSource.getTransactionAttribute.

Determine the transaction attribute for this method invocation.

Defaults to the class's transaction attribute if no method attribute is found.

Parameters
method:Method

the method for the current invocation (never null)

targetClass:Class<?>

the target class for this invocation (may be null)

Returns:TransactionAttribute

a TransactionAttribute for this method, or null if the method is not transactional

Annotations
@Override
@Nullable
setEmbeddedValueResolverback to summary
public void setEmbeddedValueResolver(StringValueResolver resolver)

Implements org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Doc from org.springframework.context.EmbeddedValueResolverAware.setEmbeddedValueResolver.

Set the StringValueResolver to use for resolving embedded definition values.

Annotations
@Override