Class RollbackRuleAttribute
- java.lang.Object
- org.springframework.transaction.interceptor.RollbackRuleAttribute
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
NoRollbackRuleAttribute
public class RollbackRuleAttribute extends Object implements Serializable
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.
- Since:
- 09.04.2003
- Author:
- Rod Johnson
- See Also:
NoRollbackRuleAttribute
, Serialized Form
Field Summary
Fields Modifier and Type Field Description static RollbackRuleAttribute
ROLLBACK_ON_RUNTIME_EXCEPTIONS
Therollback rule
forRuntimeExceptions
.
Constructor Summary
Constructors Constructor Description RollbackRuleAttribute(Class<?> clazz)
Create a new instance of theRollbackRuleAttribute
class.RollbackRuleAttribute(String exceptionName)
Create a new instance of theRollbackRuleAttribute
class for the givenexceptionName
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
int
getDepth(Throwable ex)
Return the depth of the superclass matching.String
getExceptionName()
Return the pattern for the exception name.int
hashCode()
String
toString()
Field Detail
ROLLBACK_ON_RUNTIME_EXCEPTIONS
public static final RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS
Therollback rule
forRuntimeExceptions
.
Constructor Detail
RollbackRuleAttribute
public RollbackRuleAttribute(Class<?> clazz)
Create a new instance of theRollbackRuleAttribute
class.This is the preferred way to construct a rollback rule that matches the supplied
Exception
class (and subclasses).- Parameters:
clazz
- throwable class; must beThrowable
or a subclass ofThrowable
- Throws:
IllegalArgumentException
- if the suppliedclazz
is not aThrowable
type or isnull
RollbackRuleAttribute
public RollbackRuleAttribute(String exceptionName)
Create a new instance of theRollbackRuleAttribute
class for the givenexceptionName
.This can be a substring, with no wildcard support at present. A value of "ServletException" would match
javax.servlet.ServletException
and subclasses, for example.NB: Consider carefully how specific the pattern is, and whether to include package information (which is not 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 fully package-qualified name.
- Parameters:
exceptionName
- the exception name pattern; can also be a fully package-qualified class name- Throws:
IllegalArgumentException
- if the suppliedexceptionName
isnull
or empty
Method Detail
getExceptionName
public String getExceptionName()
Return the pattern for the exception name.
getDepth
public int getDepth(Throwable ex)
Return the depth of the superclass matching.0
meansex
matches exactly. Returns-1
if there is no match. Otherwise, returns depth with the lowest depth winning.