public class

RuleBasedTransactionAttribute

extends DefaultTransactionAttribute
implements Serializable
java.lang.Object
   ↳ org.springframework.transaction.support.DefaultTransactionDefinition
     ↳ org.springframework.transaction.interceptor.DefaultTransactionAttribute
       ↳ org.springframework.transaction.interceptor.RuleBasedTransactionAttribute

Class Overview

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 rules are relevant to the exception, it behaves like DefaultTransactionAttribute (rolling back on runtime exceptions).

TransactionAttributeEditor creates objects of this class.

Summary

Constants
String PREFIX_COMMIT_RULE Prefix for commit-on-exception rules in description strings
String PREFIX_ROLLBACK_RULE Prefix for rollback-on-exception rules in description strings
[Expand]
Inherited Constants
From class org.springframework.transaction.support.DefaultTransactionDefinition
From interface org.springframework.transaction.TransactionDefinition
Public Constructors
RuleBasedTransactionAttribute()
Create a new RuleBasedTransactionAttribute, with default settings.
RuleBasedTransactionAttribute(RuleBasedTransactionAttribute other)
Copy constructor.
RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules)
Create a new DefaultTransactionAttribute with the the given propagation behavior.
Public Methods
List<RollbackRuleAttribute> getRollbackRules()
Return the list of RollbackRuleAttribute objects (never null).
boolean rollbackOn(Throwable ex)
Winning rule is the shallowest rule (that is, the closest in the inheritance hierarchy to the exception).
void setRollbackRules(List<RollbackRuleAttribute> rollbackRules)
Set the list of RollbackRuleAttribute objects (and/or NoRollbackRuleAttribute objects) to apply.
String toString()
Return an identifying description for this transaction definition.
[Expand]
Inherited Methods
From class org.springframework.transaction.interceptor.DefaultTransactionAttribute
From class org.springframework.transaction.support.DefaultTransactionDefinition
From class java.lang.Object
From interface org.springframework.transaction.TransactionDefinition
From interface org.springframework.transaction.interceptor.TransactionAttribute

Constants

public static final String PREFIX_COMMIT_RULE

Prefix for commit-on-exception rules in description strings

Constant Value: "+"

public static final String PREFIX_ROLLBACK_RULE

Prefix for rollback-on-exception rules in description strings

Constant Value: "-"

Public Constructors

public RuleBasedTransactionAttribute ()

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

public RuleBasedTransactionAttribute (RuleBasedTransactionAttribute other)

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

public RuleBasedTransactionAttribute (int propagationBehavior, List<RollbackRuleAttribute> rollbackRules)

Create a new DefaultTransactionAttribute with the 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

Public Methods

public List<RollbackRuleAttribute> getRollbackRules ()

Return the list of RollbackRuleAttribute objects (never null).

public boolean rollbackOn (Throwable ex)

Winning rule is the shallowest rule (that is, the closest in the inheritance hierarchy to the exception). If no rule applies (-1), return false.

Parameters
ex the exception to evaluate
Returns
  • whether to perform a rollback or not

public void setRollbackRules (List<RollbackRuleAttribute> rollbackRules)

Set the list of RollbackRuleAttribute objects (and/or NoRollbackRuleAttribute objects) to apply.

public String toString ()

Return an identifying description for this transaction definition.

The format matches the one used by TransactionAttributeEditor, to be able to feed toString results into bean properties of type TransactionAttribute.

Has to be overridden in subclasses for correct equals and hashCode behavior. Alternatively, equals(Object) and hashCode() can be overridden themselves.