Class RollbackRuleAttribute
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
NoRollbackRuleAttribute
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 type or exception pattern, supplied via
RollbackRuleAttribute(Class)
or RollbackRuleAttribute(String)
,
respectively.
When a rollback rule is defined with an exception type, that type will be
used to match against the type of a thrown exception and its super types,
providing type safety and avoiding any unintentional matches that may occur
when using a pattern. For example, a value of
jakarta.servlet.ServletException.class
will only match thrown exceptions
of type jakarta.servlet.ServletException
and its subclasses.
When a rollback rule is defined with an exception pattern, the pattern 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
"jakarta.servlet.ServletException"
or "ServletException"
will
match jakarta.servlet.ServletException
and its subclasses.
See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding
possible unintentional matches with pattern-based rules.
- Since:
- 09.04.2003
- Author:
- Rod Johnson, Sam Brannen
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final RollbackRuleAttribute
The rollback rule forRuntimeExceptions
. -
Constructor Summary
ConstructorDescriptionRollbackRuleAttribute
(Class<?> exceptionType) Create a new instance of theRollbackRuleAttribute
class for the givenexceptionType
.RollbackRuleAttribute
(String exceptionPattern) Create a new instance of theRollbackRuleAttribute
class for the givenexceptionPattern
. -
Method Summary
-
Field Details
-
ROLLBACK_ON_RUNTIME_EXCEPTIONS
The rollback rule forRuntimeExceptions
.
-
-
Constructor Details
-
RollbackRuleAttribute
Create a new instance of theRollbackRuleAttribute
class for the givenexceptionType
.This is the preferred way to construct a rollback rule that matches the supplied exception type and its subclasses with type safety.
See the javadocs for
@Transactional
for further details on rollback rule semantics.- Parameters:
exceptionType
- exception type; must beThrowable
or a subclass ofThrowable
- Throws:
IllegalArgumentException
- if the suppliedexceptionType
is not aThrowable
type or isnull
-
RollbackRuleAttribute
Create a new instance of theRollbackRuleAttribute
class for the givenexceptionPattern
.See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding possible unintentional matches.For improved type safety and to avoid unintentional matches, use
RollbackRuleAttribute(Class)
instead.- Parameters:
exceptionPattern
- the exception name pattern; can also be a fully package-qualified class name- Throws:
IllegalArgumentException
- if the suppliedexceptionPattern
isnull
or empty
-
-
Method Details
-
getExceptionName
Get the configured exception name pattern that this rule uses for matching.- See Also:
-
getDepth
Return the depth of the superclass matching, with the following semantics.-1
means this rule does not match the suppliedexception
.0
means this rule matches the suppliedexception
directly.- Any other positive value means this rule matches the supplied
exception
within the superclass hierarchy, where the value is the number of levels in the class hierarchy between the suppliedexception
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
).When constructed with an exception pattern via
RollbackRuleAttribute(String)
, 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. -
equals
-
hashCode
public int hashCode() -
toString
-