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:
- 
Field SummaryFields inherited from class org.springframework.transaction.support.DefaultTransactionDefinitionPREFIX_ISOLATION, PREFIX_PROPAGATION, PREFIX_TIMEOUT, READ_ONLY_MARKERFields inherited from interface org.springframework.transaction.TransactionDefinitionISOLATION_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 SummaryConstructorsConstructorDescriptionCreate a new DefaultTransactionAttribute, with default settings.DefaultTransactionAttribute(int propagationBehavior) Create a new DefaultTransactionAttribute with the given propagation behavior.Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final StringBuilderReturn an identifying description for this transaction attribute.Return a descriptor for this transaction attribute, ornullif none.Return labels associated with this transaction attribute.Return a qualifier value associated with this transaction attribute.Return the timeout to apply, if any, as a String value that resolves to a number of seconds.voidresolveAttributeStrings(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>).booleanrollbackOn(Throwable ex) The default behavior is as with EJB: rollback on unchecked exception (RuntimeException), assuming an unexpected outcome outside any business rules.voidsetDescriptor(String descriptor) Set a descriptor for this transaction attribute, e.g.voidsetLabels(Collection<String> labels) Associate one or more labels with this transaction attribute.voidsetQualifier(String qualifier) Associate a qualifier value with this transaction attribute.voidsetTimeoutString(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.DefaultTransactionDefinitionequals, getDefinitionDescription, getIsolationLevel, getName, getPropagationBehavior, getTimeout, hashCode, isReadOnly, setIsolationLevel, setIsolationLevelName, setName, setPropagationBehavior, setPropagationBehaviorName, setReadOnly, setTimeout, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.transaction.TransactionDefinitiongetIsolationLevel, getName, getPropagationBehavior, getTimeout, isReadOnly
- 
Constructor Details- 
DefaultTransactionAttributepublic DefaultTransactionAttribute()Create a new DefaultTransactionAttribute, with default settings. Can be modified through bean property setters.
- 
DefaultTransactionAttributeCopy constructor. Definition can be modified through bean property setters.
- 
DefaultTransactionAttributepublic 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:
 
 
- 
- 
Method Details- 
setDescriptorSet a descriptor for this transaction attribute, e.g. indicating where the attribute is applying.- Since:
- 4.3.4
 
- 
getDescriptorReturn a descriptor for this transaction attribute, ornullif none.- Since:
- 4.3.4
 
- 
setTimeoutStringSet the timeout to apply, if any, as a String value that resolves to a number of seconds.
- 
getTimeoutStringReturn the timeout to apply, if any, as a String value that resolves to a number of seconds.
- 
setQualifierAssociate 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:
 
- 
getQualifierReturn a qualifier value associated with this transaction attribute.- Specified by:
- getQualifierin interface- TransactionAttribute
- Since:
- 3.0
 
- 
setLabelsAssociate 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:
 
- 
getLabelsDescription copied from interface:TransactionAttributeReturn labels associated with this transaction attribute.This may be used for applying specific transactional behavior or follow a purely descriptive nature. - Specified by:
- getLabelsin interface- TransactionAttribute
 
- 
rollbackOnThe 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 onErrorwhich 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:
- rollbackOnin interface- TransactionAttribute
- Parameters:
- ex- the exception to evaluate
- Returns:
- whether to perform a rollback or not
- See Also:
 
- 
resolveAttributeStringsResolve 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
 
- 
getAttributeDescriptionReturn an identifying description for this transaction attribute.Available to subclasses, for inclusion in their toString()result.
 
-