Package org.springframework.transaction.interceptor

# Class DefaultTransactionAttribute

java.lang.Object
org.springframework.transaction.support.DefaultTransactionDefinition
org.springframework.transaction.interceptor.DefaultTransactionAttribute

All Implemented Interfaces:
  `Serializable`, `TransactionAttribute`, `TransactionDefinition`

Direct Known Subclasses:
  `RuleBasedTransactionAttribute`

public class DefaultTransactionAttribute extends DefaultTransactionDefinition implements TransactionAttribute
Spring's common transaction attribute implementation. Rolls back on runtime, but not checked, exceptions by default.

Since:
  16.03.2003
Author:
  Rod Johnson, Juergen Hoeller, Mark Paluch
See Also:
  - Serialized Form

## Field Summary

### Fields inherited from class org.springframework.transaction.support.DefaultTransactionDefinition

`PREFIX_ISOLATION, PREFIX_PROPAGATION, PREFIX_TIMEOUT, READ_ONLY_MARKER`

### Fields inherited from interface org.springframework.transaction.TransactionDefinition

`ISOLATION_DEFAULT, ISOLATION_READ_COMMITTED, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, PROPAGATION_MANDATORY, PROPAGATION_NESTED, PROPAGATION_NEVER, PROPAGATION_NOT_SUPPORTED, PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, PROPAGATION_SUPPORTS, TIMEOUT_DEFAULT`

## Constructor Summary

Constructors
Constructor
Description
`DefaultTransactionAttribute()`
Create a new `DefaultTransactionAttribute` with default settings.
`DefaultTransactionAttribute(int propagationBehavior)`
Create a new `DefaultTransactionAttribute` with the given propagation behavior.
`DefaultTransactionAttribute(TransactionAttribute other)`
Copy constructor.

## Method Summary

Modifier and Type
Method
Description
`protected final StringBuilder`
`getAttributeDescription()`
Return an identifying description for this transaction attribute.
`String`
`getDescriptor()`
Return a descriptor for this transaction attribute, or `null` if none.
`Collection<String>`
`getLabels()`
Return labels associated with this transaction attribute.
`String`
`getQualifier()`
Return a qualifier value associated with this transaction attribute.
`String`
`getTimeoutString()`
Return the timeout to apply, if any, as a String value that resolves to a number of seconds.
`void`
`resolveAttributeStrings(org.springframework.util.StringValueResolver resolver)`
Resolve attribute values that are defined as resolvable Strings: `setTimeoutString(java.lang.String)`, `setQualifier(java.lang.String)`, `setLabels(java.util.Collection<java.lang.String>)`.
`boolean`
`rollbackOn(Throwable ex)`
The default behavior is as with EJB: rollback on unchecked exception (`RuntimeException`), assuming an unexpected outcome outside any business rules.
`void`
`setDescriptor(String descriptor)`
Set a descriptor for this transaction attribute, for example, indicating where the attribute is applying.
`void`
`setLabels(Collection<String> labels)`
Associate one or more labels with this transaction attribute.
`void`
`setQualifier(String qualifier)`
Associate a qualifier value with this transaction attribute.
`void`
`setTimeoutString(String timeoutString)`
Set the timeout to apply, if any, as a String value that resolves to a number of seconds.

### Methods inherited from class org.springframework.transaction.support.DefaultTransactionDefinition

`equals, getDefinitionDescription, getIsolationLevel, getName, getPropagationBehavior, getTimeout, hashCode, isReadOnly, setIsolationLevel, setIsolationLevelName, setName, setPropagationBehavior, setPropagationBehaviorName, setReadOnly, setTimeout, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.transaction.TransactionDefinition

`getIsolationLevel, getName, getPropagationBehavior, getTimeout, isReadOnly`

## Constructor Details

### DefaultTransactionAttribute

public DefaultTransactionAttribute()
Create a new `DefaultTransactionAttribute` with default settings. Can be modified through bean property setters.

See Also:
  - `DefaultTransactionDefinition.setPropagationBehavior(int)`
  - `DefaultTransactionDefinition.setIsolationLevel(int)`
  - `DefaultTransactionDefinition.setTimeout(int)`
  - `DefaultTransactionDefinition.setReadOnly(boolean)`
  - `DefaultTransactionDefinition.setName(java.lang.String)`

### DefaultTransactionAttribute

public DefaultTransactionAttribute(TransactionAttribute other)
Copy constructor. Definition can be modified through bean property setters.

See Also:
  - `DefaultTransactionDefinition.setPropagationBehavior(int)`
  - `DefaultTransactionDefinition.setIsolationLevel(int)`
  - `DefaultTransactionDefinition.setTimeout(int)`
  - `DefaultTransactionDefinition.setReadOnly(boolean)`
  - `DefaultTransactionDefinition.setName(java.lang.String)`

### DefaultTransactionAttribute

public DefaultTransactionAttribute(int propagationBehavior)
Create a new `DefaultTransactionAttribute` with the given propagation behavior. Can be modified through bean property setters.

Parameters:
  `propagationBehavior` - one of the propagation constants in the TransactionDefinition interface
See Also:
  - `DefaultTransactionDefinition.setIsolationLevel(int)`
  - `DefaultTransactionDefinition.setTimeout(int)`
  - `DefaultTransactionDefinition.setReadOnly(boolean)`

## Method Details

### setDescriptor

public void setDescriptor(@Nullable String descriptor)
Set a descriptor for this transaction attribute, for example, indicating where the attribute is applying.

Since:
  4.3.4

### getDescriptor

@Nullable public String getDescriptor()
Return a descriptor for this transaction attribute, or `null` if none.

Since:
  4.3.4

### setTimeoutString

public void setTimeoutString(@Nullable String timeoutString)
Set the timeout to apply, if any, as a String value that resolves to a number of seconds.

Since:
  5.3
See Also:
  - `DefaultTransactionDefinition.setTimeout(int)`
  - `resolveAttributeStrings(org.springframework.util.StringValueResolver)`

### getTimeoutString

@Nullable public String getTimeoutString()
Return the timeout to apply, if any, as a String value that resolves to a number of seconds.

Since:
  5.3
See Also:
  - `DefaultTransactionDefinition.getTimeout()`
  - `resolveAttributeStrings(org.springframework.util.StringValueResolver)`

### setQualifier

public void setQualifier(@Nullable String qualifier)
Associate a qualifier value with this transaction attribute.

This may be used for choosing a corresponding transaction manager to process this specific transaction.

Since:
  3.0
See Also:
  - `resolveAttributeStrings(org.springframework.util.StringValueResolver)`

### getQualifier

@Nullable public String getQualifier()
Return a qualifier value associated with this transaction attribute.

Specified by:
  `getQualifier` in interface `TransactionAttribute`
Since:
  3.0

### setLabels

public void setLabels(Collection<String> labels)
Associate one or more labels with this transaction attribute.

This may be used for applying specific transactional behavior or follow a purely descriptive nature.

Since:
  5.3
See Also:
  - `resolveAttributeStrings(org.springframework.util.StringValueResolver)`

### getLabels

public Collection<String> getLabels()
Description copied from interface: `TransactionAttribute`
Return labels associated with this transaction attribute.

This may be used for applying specific transactional behavior or follow a purely descriptive nature.

Specified by:
  `getLabels` in interface `TransactionAttribute`

### rollbackOn

public boolean rollbackOn(Throwable ex)
The default behavior is as with EJB: rollback on unchecked exception (`RuntimeException`), assuming an unexpected outcome outside any business rules. Additionally, we also attempt to rollback on `Error` which is clearly an unexpected outcome as well. By contrast, a checked exception is considered a business exception and therefore a regular expected outcome of the transactional business method, i.e. a kind of alternative return value which still allows for regular completion of resource operations.

This is largely consistent with TransactionTemplate's default behavior, except that TransactionTemplate also rolls back on undeclared checked exceptions (a corner case). For declarative transactions, we expect checked exceptions to be intentionally declared as business exceptions, leading to a commit by default.

Specified by:
  `rollbackOn` in interface `TransactionAttribute`
Parameters:
  `ex` - the exception to evaluate
Returns:
  whether to perform a rollback or not
See Also:
  - `TransactionTemplate.execute(org.springframework.transaction.support.TransactionCallback<T>)`

### resolveAttributeStrings

public void resolveAttributeStrings(@Nullable org.springframework.util.StringValueResolver resolver)
Resolve attribute values that are defined as resolvable Strings: `setTimeoutString(java.lang.String)`, `setQualifier(java.lang.String)`, `setLabels(java.util.Collection<java.lang.String>)`. This is typically used for resolving "${...}" placeholders.

Parameters:
  `resolver` - the embedded value resolver to apply, if any
Since:
  5.3

### getAttributeDescription

protected final StringBuilder getAttributeDescription()
Return an identifying description for this transaction attribute.

Available to subclasses, for inclusion in their `toString()` result.