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

public Class RuleBasedTransactionAttribute

extends DefaultTransactionAttribute
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.util.ArrayList, .List, org.springframework.lang.Nullable

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.

Authors
Rod Johnson, Juergen Hoeller
Since
09.04.2003
See Also
TransactionAttributeEditor

Field Summary

Modifier and TypeField and Description
public static final String
PREFIX_COMMIT_RULE

Prefix for commit-on-exception rules in description strings.

public static final String
PREFIX_ROLLBACK_RULE

Prefix for rollback-on-exception rules in description strings.

private List<RollbackRuleAttribute>

Constructor Summary

AccessConstructor and Description
public
RuleBasedTransactionAttribute()

Create a new RuleBasedTransactionAttribute, with default settings.

public
public
RuleBasedTransactionAttribute(int
one of the propagation constants in the TransactionDefinition interface
propagationBehavior
,
List<RollbackRuleAttribute>
the list of RollbackRuleAttributes to apply
rollbackRules
)

Create a new DefaultTransactionAttribute with the given propagation behavior.

Method Summary

Modifier and TypeMethod and Description
public List<RollbackRuleAttribute>
getRollbackRules()

Return the list of RollbackRuleAttribute objects (never null).

public boolean
rollbackOn(Throwable
the exception to evaluate
ex
)

Overrides org.springframework.transaction.interceptor.DefaultTransactionAttribute.rollbackOn.

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

Winning rule is the shallowest rule (that is, the closest in the inheritance hierarchy to the exception).
public void
setRollbackRules(List<RollbackRuleAttribute> rollbackRules)

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

public String
toString()

Overrides org.springframework.transaction.support.DefaultTransactionDefinition.toString.

Return an identifying description for this transaction definition.
Inherited from org.springframework.transaction.interceptor.DefaultTransactionAttribute:
getAttributeDescriptiongetDescriptorgetLabelsgetQualifiergetTimeoutStringresolveAttributeStringssetDescriptorsetLabelssetQualifiersetTimeoutString

Field Detail

PREFIX_COMMIT_RULEback to summary
public static final String PREFIX_COMMIT_RULE

Prefix for commit-on-exception rules in description strings.

PREFIX_ROLLBACK_RULEback to summary
public static final String PREFIX_ROLLBACK_RULE

Prefix for rollback-on-exception rules in description strings.

rollbackRulesback to summary
private List<RollbackRuleAttribute> rollbackRules
Annotations
@Nullable

Constructor Detail

RuleBasedTransactionAttributeback to summary
public RuleBasedTransactionAttribute()

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

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName, setRollbackRules
RuleBasedTransactionAttributeback to summary
public RuleBasedTransactionAttribute(RuleBasedTransactionAttribute other)

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

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName, setRollbackRules
RuleBasedTransactionAttributeback to summary
public RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules)

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

rollbackRules:List<RollbackRuleAttribute>

the list of RollbackRuleAttributes to apply

See Also
setIsolationLevel, setTimeout, setReadOnly

Method Detail

getRollbackRulesback to summary
public List<RollbackRuleAttribute> getRollbackRules()

Return the list of RollbackRuleAttribute objects (never null).

rollbackOnback to summary
public boolean rollbackOn(Throwable ex)

Overrides org.springframework.transaction.interceptor.DefaultTransactionAttribute.rollbackOn.

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

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: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
TransactionAttribute#rollbackOn(java.lang.Throwable)
setRollbackRulesback to summary
public void setRollbackRules(List<RollbackRuleAttribute> rollbackRules)

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

See Also
RollbackRuleAttribute, NoRollbackRuleAttribute
toStringback to summary
public String toString()

Overrides org.springframework.transaction.support.DefaultTransactionDefinition.toString.

Doc from org.springframework.transaction.support.DefaultTransactionDefinition.toString.

Return an identifying description for this transaction definition.

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

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

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override