public class RollbackRuleAttribute extends Object implements Serializable
Multiple such rules can be applied to determine whether a transaction should commit or rollback after an exception has been thrown.
Each rule is based on an exception pattern which can be a fully qualified
class name or a substring of a fully qualified class name for an exception
type (which must be a subclass of Throwable
), with no wildcard support
at present. For example, a value of "javax.servlet.ServletException"
or "ServletException"
would match javax.servlet.ServletException
and its subclasses.
An exception pattern can be specified as a Class
reference or a
String
in RollbackRuleAttribute(Class)
and
RollbackRuleAttribute(String)
, respectively. When an exception type
is specified as a class reference its fully qualified name will be used as the
pattern. See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding
possible unintentional matches.
NoRollbackRuleAttribute
,
Serialized FormModifier and Type | Field and Description |
---|---|
static RollbackRuleAttribute |
ROLLBACK_ON_RUNTIME_EXCEPTIONS
The rollback rule for
RuntimeExceptions . |
Constructor and Description |
---|
RollbackRuleAttribute(Class<?> exceptionType)
Create a new instance of the
RollbackRuleAttribute class
for the given exceptionType . |
RollbackRuleAttribute(String exceptionPattern)
Create a new instance of the
RollbackRuleAttribute class
for the given exceptionPattern . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
int |
getDepth(Throwable exception)
Return the depth of the superclass matching, with the following semantics.
|
String |
getExceptionName()
Get the configured exception name pattern that this rule uses for matching.
|
int |
hashCode() |
String |
toString() |
public static final RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS
RuntimeExceptions
.public RollbackRuleAttribute(Class<?> exceptionType)
RollbackRuleAttribute
class
for the given exceptionType
.
This is the preferred way to construct a rollback rule that matches the supplied exception type, its subclasses, and its nested classes.
See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding
possible unintentional matches.
exceptionType
- exception type; must be Throwable
or a subclass
of Throwable
IllegalArgumentException
- if the supplied exceptionType
is
not a Throwable
type or is null
public RollbackRuleAttribute(String exceptionPattern)
RollbackRuleAttribute
class
for the given exceptionPattern
.
See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding
possible unintentional matches.
exceptionPattern
- the exception name pattern; can also be a fully
package-qualified class nameIllegalArgumentException
- if the supplied exceptionPattern
is null
or emptypublic String getExceptionName()
getDepth(Throwable)
public int getDepth(Throwable exception)
-1
means this rule does not match the supplied exception
.0
means this rule matches the supplied exception
directly.exception
within the superclass hierarchy, where the value is the number of levels in the
class hierarchy between the supplied exception
and the exception against
which this rule matches directly.When comparing roll back rules that match against a given exception, a rule
with a lower matching depth wins. For example, a direct match (depth == 0
)
wins over a match in the superclass hierarchy (depth > 0
).
A match against a nested exception type or similarly named exception type will return a depth signifying a match at the corresponding level in the class hierarchy as if there had been a direct match.