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
FieldsModifier and TypeFieldDescriptionstatic final RollbackRuleAttributeThe rollback rule for allExceptions, including checked exceptions.static final RollbackRuleAttributeThe rollback rule forRuntimeExceptions. -
Constructor Summary
ConstructorsConstructorDescriptionRollbackRuleAttribute(Class<?> exceptionType) Create a new instance of theRollbackRuleAttributeclass for the givenexceptionType.RollbackRuleAttribute(String exceptionPattern) Create a new instance of theRollbackRuleAttributeclass for the givenexceptionPattern. -
Method Summary
-
Field Details
-
ROLLBACK_ON_RUNTIME_EXCEPTIONS
The rollback rule forRuntimeExceptions. -
ROLLBACK_ON_ALL_EXCEPTIONS
The rollback rule for allExceptions, including checked exceptions.- Since:
- 6.2
-
-
Constructor Details
-
RollbackRuleAttribute
Create a new instance of theRollbackRuleAttributeclass 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
@Transactionalfor further details on rollback rule semantics.- Parameters:
exceptionType- exception type; must beThrowableor a subclass ofThrowable- Throws:
IllegalArgumentException- if the suppliedexceptionTypeis not aThrowabletype or isnull
-
RollbackRuleAttribute
Create a new instance of theRollbackRuleAttributeclass for the givenexceptionPattern.See the javadocs for
@Transactionalfor 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 suppliedexceptionPatternisnullor 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.-1means this rule does not match the suppliedexception.0means this rule matches the suppliedexceptiondirectly.- Any other positive value means this rule matches the supplied
exceptionwithin the superclass hierarchy, where the value is the number of levels in the class hierarchy between the suppliedexceptionand 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
-
toString
-