org.springframework.transaction.interceptor
Class RollbackRuleAttribute

Direct Known Subclasses:
NoRollbackRuleAttribute

public class RollbackRuleAttribute

Rule determining whether or not a given exception (and any subclasses) should cause a rollback. Multiple such rules can be applied to determine whether a transaction should commit or rollback after an exception has been thrown.

Author:
Rod Johnson
Version: $Id: RollbackRuleAttribute.java,v 1.5 2003/12/23 08:44:53 johnsonr Exp $
Since: 09-Apr-2003
See Also: NoRollbackRuleAttribute

Field Summary
 final static RollbackRuleAttributeROLLBACK_ON_RUNTIME_EXCEPTIONS
           

Constructor Summary
RollbackRuleAttribute(Class clazz)
          Preferred way to construct a RollbackRule, matching the exception class and subclasses.
RollbackRuleAttribute(String exceptionName)
          Construct a new RollbackRule for the given exception name.

Method Summary
 intgetDepth(Throwable t)
          Return the depth to the superclass matching.
 StringgetExceptionName()
          Return the pattern for the exception name.
 StringtoString()
           

Field Detail

ROLLBACK_ON_RUNTIME_EXCEPTIONS

public final static RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS
Constructor Detail

RollbackRuleAttribute

public RollbackRuleAttribute(Class clazz)
Preferred way to construct a RollbackRule, matching the exception class and subclasses. The exception class must be Throwable or a subclass of Throwable.
Parameters:
clazz - throwable class

RollbackRuleAttribute

public RollbackRuleAttribute(String exceptionName)
Construct a new RollbackRule for the given exception name. This can be a substring, with no wildcard support at present. A value of "ServletException" would match ServletException and subclasses, for example.

NB: Consider carefully how specific the pattern is, and whether to include package information (which isn't mandatory). For example, "Exception" will match nearly anything, and will probably hide other rules. "java.lang.Exception" would be correct if "Exception" was meant to define a rule for all checked exceptions. With more unusual Exception names such as "BaseBusinessException" there's no need to use a FQN.

Parameters:
exceptionName - the exception pattern
Method Detail

getDepth

public int getDepth(Throwable t)
Return the depth to the superclass matching. 0 means t matches. Return -1 if there's no match. Otherwise, return depth. Lowest depth wins.

getExceptionName

public String getExceptionName()
Return the pattern for the exception name.

toString

public String toString()

Association Links

to Class org.springframework.transaction.interceptor.RollbackRuleAttribute

to Class java.lang.String

Could hold exception, resolving classname but would always require FQN. This way does multiple string comparisons, but how often do we decide whether to roll back a transaction following an exception?