Class RuleBasedTransactionAttribute
java.lang.Object
org.springframework.transaction.support.DefaultTransactionDefinition
org.springframework.transaction.interceptor.DefaultTransactionAttribute
org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
- All Implemented Interfaces:
- Serializable,- TransactionAttribute,- TransactionDefinition
public class RuleBasedTransactionAttribute
extends DefaultTransactionAttribute
implements Serializable
TransactionAttribute implementation that works out whether a given exception
 should cause transaction rollback by applying a number of rollback rules,
 both positive and negative. If no custom rollback rules apply, this attribute
 behaves like DefaultTransactionAttribute (rolling back on runtime exceptions).
 
TransactionAttributeEditor creates objects of this class.
- Since:
- 09.04.2003
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringPrefix for commit-on-exception rules in description strings.static final StringPrefix for rollback-on-exception rules in description strings.Fields 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 RuleBasedTransactionAttribute, with default settings.RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules) Create a new DefaultTransactionAttribute with the given propagation behavior.Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionReturn the list ofRollbackRuleAttributeobjects (nevernull).booleanrollbackOn(Throwable ex) Winning rule is the shallowest rule (that is, the closest in the inheritance hierarchy to the exception).voidsetRollbackRules(List<RollbackRuleAttribute> rollbackRules) Set the list ofRollbackRuleAttributeobjects (and/orNoRollbackRuleAttributeobjects) to apply.toString()Return an identifying description for this transaction definition.Methods inherited from class org.springframework.transaction.interceptor.DefaultTransactionAttributegetAttributeDescription, getDescriptor, getLabels, getQualifier, getTimeoutString, resolveAttributeStrings, setDescriptor, setLabels, setQualifier, setTimeoutStringMethods inherited from class org.springframework.transaction.support.DefaultTransactionDefinitionequals, getDefinitionDescription, getIsolationLevel, getName, getPropagationBehavior, getTimeout, hashCode, isReadOnly, setIsolationLevel, setIsolationLevelName, setName, setPropagationBehavior, setPropagationBehaviorName, setReadOnly, setTimeoutMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.transaction.TransactionDefinitiongetIsolationLevel, getName, getPropagationBehavior, getTimeout, isReadOnly
- 
Field Details- 
PREFIX_ROLLBACK_RULEPrefix for rollback-on-exception rules in description strings.- See Also:
 
- 
PREFIX_COMMIT_RULEPrefix for commit-on-exception rules in description strings.- See Also:
 
 
- 
- 
Constructor Details- 
RuleBasedTransactionAttributepublic RuleBasedTransactionAttribute()Create a new RuleBasedTransactionAttribute, 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)
- setRollbackRules(java.util.List<org.springframework.transaction.interceptor.RollbackRuleAttribute>)
 
 
- 
RuleBasedTransactionAttributeCopy 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)
- setRollbackRules(java.util.List<org.springframework.transaction.interceptor.RollbackRuleAttribute>)
 
 
- 
RuleBasedTransactionAttributepublic RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules) 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
- rollbackRules- the list of RollbackRuleAttributes to apply
- See Also:
 
 
- 
- 
Method Details- 
setRollbackRulesSet the list ofRollbackRuleAttributeobjects (and/orNoRollbackRuleAttributeobjects) to apply.- See Also:
 
- 
getRollbackRulesReturn the list ofRollbackRuleAttributeobjects (nevernull).
- 
rollbackOnWinning rule is the shallowest rule (that is, the closest in the inheritance hierarchy to the exception). If no rule applies (-1), return false.- Specified by:
- rollbackOnin interface- TransactionAttribute
- Overrides:
- rollbackOnin class- DefaultTransactionAttribute
- Parameters:
- ex- the exception to evaluate
- Returns:
- whether to perform a rollback or not
- See Also:
 
- 
toStringDescription copied from class:DefaultTransactionDefinitionReturn an identifying description for this transaction definition.The format matches the one used by TransactionAttributeEditor, to be able to feedtoStringresults into bean properties of typeTransactionAttribute.Has to be overridden in subclasses for correct equalsandhashCodebehavior. Alternatively,DefaultTransactionDefinition.equals(java.lang.Object)andDefaultTransactionDefinition.hashCode()can be overridden themselves.- Overrides:
- toStringin class- DefaultTransactionDefinition
- See Also:
 
 
-