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

public Class DefaultTransactionAttribute

extends DefaultTransactionDefinition
implements TransactionAttribute
Class Inheritance
All Implemented Interfaces
org.springframework.transaction.interceptor.TransactionAttribute, org.springframework.transaction.TransactionDefinition
Known Direct Subclasses
org.springframework.transaction.interceptor.RuleBasedTransactionAttribute, org.springframework.transaction.annotation.Ejb3TransactionAnnotationParser.Ejb3TransactionAttribute
Annotations
@SuppressWarnings:serial
Imports
java.util.Collection, .Collections, .LinkedHashSet, .Set, org.springframework.lang.Nullable, org.springframework.transaction.support.DefaultTransactionDefinition, org.springframework.util.StringUtils, .StringValueResolver

Spring's common transaction attribute implementation. Rolls back on runtime, but not checked, exceptions by default.
Authors
Rod Johnson, Juergen Hoeller, Mark Paluch
Since
16.03.2003

Field Summary

Modifier and TypeField and Description
private String
private Collection<String>
private String
private String
Inherited from org.springframework.transaction.support.DefaultTransactionDefinition:
PREFIX_ISOLATIONPREFIX_PROPAGATIONPREFIX_TIMEOUTREAD_ONLY_MARKER

Constructor Summary

AccessConstructor and Description
public
DefaultTransactionAttribute()

Create a new DefaultTransactionAttribute, with default settings.

public
public
DefaultTransactionAttribute(int
one of the propagation constants in the TransactionDefinition interface
propagationBehavior
)

Create a new DefaultTransactionAttribute with the given propagation behavior.

Method Summary

Modifier and TypeMethod and Description
protected final StringBuilder
getAttributeDescription()

Return an identifying description for this transaction attribute.

public String
getDescriptor()

Return a descriptor for this transaction attribute, or null if none.

public Collection<String>
getLabels()

Implements org.springframework.transaction.interceptor.TransactionAttribute.getLabels.

Return labels associated with this transaction attribute.
public String
getQualifier()

Implements org.springframework.transaction.interceptor.TransactionAttribute.getQualifier.

Return a qualifier value associated with this transaction attribute.
public String
getTimeoutString()

Return the timeout to apply, if any, as a String value that resolves to a number of seconds.

public void
resolveAttributeStrings(StringValueResolver
the embedded value resolver to apply, if any
resolver
)

Resolve attribute values that are defined as resolvable Strings: setTimeoutString, setQualifier, setLabels.

public boolean
rollbackOn(Throwable
the exception to evaluate
ex
)

Implements org.springframework.transaction.interceptor.TransactionAttribute.rollbackOn.

The default behavior is as with EJB: rollback on unchecked exception (RuntimeException), assuming an unexpected outcome outside any business rules.
public void
setDescriptor(String descriptor)

Set a descriptor for this transaction attribute, e.g. indicating where the attribute is applying.

public void
setLabels(Collection<String> labels)

Associate one or more labels with this transaction attribute.

public void
setQualifier(String qualifier)

Associate a qualifier value with this transaction attribute.

public void
setTimeoutString(String timeoutString)

Set the timeout to apply, if any, as a String value that resolves to a number of seconds.

Inherited from org.springframework.transaction.support.DefaultTransactionDefinition:
equalsgetDefinitionDescriptiongetIsolationLevelgetNamegetPropagationBehaviorgetTimeouthashCodeisReadOnlysetIsolationLevelsetIsolationLevelNamesetNamesetPropagationBehaviorsetPropagationBehaviorNamesetReadOnlysetTimeouttoString

Field Detail

descriptorback to summary
private String descriptor
Annotations
@Nullable
labelsback to summary
private Collection<String> labels
qualifierback to summary
private String qualifier
Annotations
@Nullable
timeoutStringback to summary
private String timeoutString
Annotations
@Nullable

Constructor Detail

DefaultTransactionAttributeback to summary
public DefaultTransactionAttribute()

Create a new DefaultTransactionAttribute, with default settings. Can be modified through bean property setters.

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName
DefaultTransactionAttributeback to summary
public DefaultTransactionAttribute(TransactionAttribute other)

Copy constructor. Definition can be modified through bean property setters.

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName
DefaultTransactionAttributeback to summary
public DefaultTransactionAttribute(int propagationBehavior)

Create a new DefaultTransactionAttribute with the given propagation behavior. Can be modified through bean property setters.

Parameters
propagationBehavior:int

one of the propagation constants in the TransactionDefinition interface

See Also
setIsolationLevel, setTimeout, setReadOnly

Method Detail

getAttributeDescriptionback to summary
protected final StringBuilder getAttributeDescription()

Return an identifying description for this transaction attribute.

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

getDescriptorback to summary
public String getDescriptor()

Return a descriptor for this transaction attribute, or null if none.

Annotations
@Nullable
Since
4.3.4
getLabelsback to summary
public Collection<String> getLabels()

Implements org.springframework.transaction.interceptor.TransactionAttribute.getLabels.

Doc from org.springframework.transaction.interceptor.TransactionAttribute.getLabels.

Return labels associated with this transaction attribute.

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

Annotations
@Override
getQualifierback to summary
public String getQualifier()

Implements org.springframework.transaction.interceptor.TransactionAttribute.getQualifier.

Return a qualifier value associated with this transaction attribute.

Annotations
@Override
@Nullable
Since
3.0
getTimeoutStringback to summary
public String getTimeoutString()

Return the timeout to apply, if any, as a String value that resolves to a number of seconds.

Annotations
@Nullable
Since
5.3
See Also
getTimeout, resolveAttributeStrings
resolveAttributeStringsback to summary
public void resolveAttributeStrings(StringValueResolver resolver)

Resolve attribute values that are defined as resolvable Strings: setTimeoutString, setQualifier, setLabels. This is typically used for resolving "${...}" placeholders.

Parameters
resolver:StringValueResolver

the embedded value resolver to apply, if any

Since
5.3
rollbackOnback to summary
public boolean rollbackOn(Throwable ex)

Implements org.springframework.transaction.interceptor.TransactionAttribute.rollbackOn.

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.

Parameters
ex:Throwable

Doc from org.springframework.transaction.interceptor.TransactionAttribute.rollbackOn.

the exception to evaluate

Returns:boolean

Doc from org.springframework.transaction.interceptor.TransactionAttribute.rollbackOn.

whether to perform a rollback or not

Annotations
@Override
See Also
org.springframework.transaction.support.TransactionTemplate#execute
setDescriptorback to summary
public void setDescriptor(String descriptor)

Set a descriptor for this transaction attribute, e.g. indicating where the attribute is applying.

Since
4.3.4
setLabelsback to summary
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
setQualifierback to summary
public void setQualifier(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
setTimeoutStringback to summary
public void setTimeoutString(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
setTimeout, resolveAttributeStrings