Class MethodMapTransactionAttributeSource
java.lang.Object
org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,InitializingBean
,EmbeddedValueResolverAware
,TransactionAttributeSource
public class MethodMapTransactionAttributeSource
extends Object
implements TransactionAttributeSource, EmbeddedValueResolverAware, BeanClassLoaderAware, InitializingBean
Simple
TransactionAttributeSource
implementation that
allows attributes to be stored per method in a Map
.- Since:
- 24.04.2003
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTransactionalMethod
(Class<?> clazz, String mappedName, TransactionAttribute attr) Add an attribute for a transactional method.void
addTransactionalMethod
(Method method, TransactionAttribute attr) Add an attribute for a transactional method.void
addTransactionalMethod
(String name, TransactionAttribute attr) Add an attribute for a transactional method.void
Eagerly initializes the specified"methodMap"
, if any.boolean
getTransactionAttribute
(Method method, Class<?> targetClass) Return the transaction attribute for the given method, ornull
if the method is non-transactional.int
hashCode()
protected void
initMethodMap
(Map<String, TransactionAttribute> methodMap) Initialize the specified"methodMap"
, if any.protected boolean
Return if the given method name matches the mapped name.void
setBeanClassLoader
(ClassLoader beanClassLoader) Callback that supplies the beanclass loader
to a bean instance.void
setEmbeddedValueResolver
(StringValueResolver resolver) Set the StringValueResolver to use for resolving embedded definition values.void
setMethodMap
(Map<String, TransactionAttribute> methodMap) Set a name/attribute map, consisting of "FQCN.method" method names (e.g.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.transaction.interceptor.TransactionAttributeSource
isCandidateClass
-
Field Details
-
logger
Logger available to subclasses.
-
-
Constructor Details
-
MethodMapTransactionAttributeSource
public MethodMapTransactionAttributeSource()
-
-
Method Details
-
setMethodMap
Set a name/attribute map, consisting of "FQCN.method" method names (e.g. "com.mycompany.mycode.MyClass.myMethod") andTransactionAttribute
instances (or Strings to be converted toTransactionAttribute
instances).Intended for configuration via setter injection, typically within a Spring bean factory. Relies on
afterPropertiesSet()
being called afterwards.- Parameters:
methodMap
- saidMap
from method name to attribute value- See Also:
-
setEmbeddedValueResolver
Description copied from interface:EmbeddedValueResolverAware
Set the StringValueResolver to use for resolving embedded definition values.- Specified by:
setEmbeddedValueResolver
in interfaceEmbeddedValueResolverAware
-
setBeanClassLoader
Description copied from interface:BeanClassLoaderAware
Callback that supplies the beanclass loader
to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
- Parameters:
beanClassLoader
- the owning class loader
-
afterPropertiesSet
public void afterPropertiesSet()Eagerly initializes the specified"methodMap"
, if any.- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- See Also:
-
initMethodMap
Initialize the specified"methodMap"
, if any.- Parameters:
methodMap
- a Map from method names toTransactionAttribute
instances- See Also:
-
addTransactionalMethod
Add an attribute for a transactional method.Method names can end or start with "*" for matching multiple methods.
- Parameters:
name
- class and method name, separated by a dotattr
- attribute associated with the method- Throws:
IllegalArgumentException
- in case of an invalid name
-
addTransactionalMethod
Add an attribute for a transactional method. Method names can end or start with "*" for matching multiple methods.- Parameters:
clazz
- target interface or classmappedName
- mapped method nameattr
- attribute associated with the method
-
addTransactionalMethod
Add an attribute for a transactional method.- Parameters:
method
- the methodattr
- attribute associated with the method
-
isMatch
Return if the given method name matches the mapped name.The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality.
- Parameters:
methodName
- the method name of the classmappedName
- the name in the descriptor- Returns:
- if the names match
- See Also:
-
getTransactionAttribute
@Nullable public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass) Description copied from interface:TransactionAttributeSource
Return the transaction attribute for the given method, ornull
if the method is non-transactional.- Specified by:
getTransactionAttribute
in interfaceTransactionAttributeSource
- Parameters:
method
- the method to introspecttargetClass
- the target class (may benull
, in which case the declaring class of the method must be used)- Returns:
- the matching transaction attribute, or
null
if none found
-
equals
-
hashCode
public int hashCode() -
toString
-