Package org.springframework.transaction.interceptor

# Class MethodMapTransactionAttributeSource

java.lang.Object
org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanClassLoaderAware`, `org.springframework.beans.factory.InitializingBean`, `org.springframework.context.EmbeddedValueResolverAware`, `TransactionAttributeSource`

public class MethodMapTransactionAttributeSource extends Object implements TransactionAttributeSource, org.springframework.context.EmbeddedValueResolverAware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.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:
  - `isMatch(java.lang.String, java.lang.String)`
  - `NameMatchTransactionAttributeSource`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`
Logger available to subclasses.

## Constructor Summary

Constructors
Constructor
Description
`MethodMapTransactionAttributeSource()`

## Method Summary

Modifier and Type
Method
Description
`void`
`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`
`afterPropertiesSet()`
Eagerly initializes the specified `"methodMap"`, if any.
`boolean`
`equals(Object other)`
`TransactionAttribute`
`getTransactionAttribute(Method method, Class<?> targetClass)`
Return the transaction attribute for the given method, or `null` if the method is non-transactional.
`int`
`hashCode()`
`protected void`
`initMethodMap(Map<String,TransactionAttribute> methodMap)`
Initialize the specified `"methodMap"`, if any.
`protected boolean`
`isMatch(String methodName, String mappedName)`
Return if the given method name matches the mapped name.
`void`
`setBeanClassLoader(ClassLoader beanClassLoader)`
`void`
`setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)`
`void`
`setMethodMap(Map<String,TransactionAttribute> methodMap)`
Set a name/attribute map, consisting of "`<fully-qualified class name>.<method-name>`" method names (for example, "com.mycompany.mycode.MyClass.myMethod") and `TransactionAttribute` instances (or Strings to be converted to `TransactionAttribute` instances).
`String`
`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

`hasTransactionAttribute, isCandidateClass`

## Field Details

### logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses.

## Constructor Details

### MethodMapTransactionAttributeSource

public MethodMapTransactionAttributeSource()

## Method Details

### setMethodMap

public void setMethodMap(Map<String,TransactionAttribute> methodMap)
Set a name/attribute map, consisting of "`<fully-qualified class name>.<method-name>`" method names (for example, "com.mycompany.mycode.MyClass.myMethod") and `TransactionAttribute` instances (or Strings to be converted to `TransactionAttribute` instances).

Intended for configuration via setter injection, typically within a Spring bean factory. Relies on `afterPropertiesSet()` being called afterwards.

Parameters:
  `methodMap` - said `Map` from method name to attribute value
See Also:
  - `TransactionAttribute`
  - `TransactionAttributeEditor`

### setEmbeddedValueResolver

public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver)

Specified by:
  `setEmbeddedValueResolver` in interface `org.springframework.context.EmbeddedValueResolverAware`

### setBeanClassLoader

public void setBeanClassLoader(ClassLoader beanClassLoader)

Specified by:
  `setBeanClassLoader` in interface `org.springframework.beans.factory.BeanClassLoaderAware`

### afterPropertiesSet

public void afterPropertiesSet()
Eagerly initializes the specified `"methodMap"`, if any.

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
See Also:
  - `initMethodMap(java.util.Map)`

### initMethodMap

protected void initMethodMap(@Nullable Map<String,TransactionAttribute> methodMap)
Initialize the specified `"methodMap"`, if any.

Parameters:
  `methodMap` - a Map from method names to `TransactionAttribute` instances
See Also:
  - `setMethodMap(java.util.Map<java.lang.String, org.springframework.transaction.interceptor.TransactionAttribute>)`

### addTransactionalMethod

public void addTransactionalMethod(String name, TransactionAttribute attr)
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 dot
  `attr` - attribute associated with the method
Throws:
  `IllegalArgumentException` - in case of an invalid name

### addTransactionalMethod

public void addTransactionalMethod(Class<?> clazz, String mappedName, TransactionAttribute attr)
Add an attribute for a transactional method. Method names can end or start with "*" for matching multiple methods.

Parameters:
  `clazz` - target interface or class
  `mappedName` - mapped method name
  `attr` - attribute associated with the method

### addTransactionalMethod

public void addTransactionalMethod(Method method, TransactionAttribute attr)
Add an attribute for a transactional method.

Parameters:
  `method` - the method
  `attr` - attribute associated with the method

### isMatch

protected boolean isMatch(String methodName, String mappedName)
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 class
  `mappedName` - the name in the descriptor
Returns:
  if the names match
See Also:
  - `PatternMatchUtils.simpleMatch(String, String)`

### getTransactionAttribute

@Nullable public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass)
Description copied from interface: `TransactionAttributeSource`
Return the transaction attribute for the given method, or `null` if the method is non-transactional.

Specified by:
  `getTransactionAttribute` in interface `TransactionAttributeSource`
Parameters:
  `method` - the method to introspect
  `targetClass` - the target class (can be `null`, in which case the declaring class of the method must be used)
Returns:
  the matching transaction attribute, or `null` if none found

### equals

public boolean equals(@Nullable Object other)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`