Top Description Fields Constructors Methods
org.springframework.transaction.interceptor

public Class RollbackRuleAttribute

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.springframework.transaction.interceptor.NoRollbackRuleAttribute
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, org.springframework.lang.Nullable, org.springframework.util.Assert

Rule determining whether a given exception 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.

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.

Authors
Rod Johnson, Sam Brannen
Since
09.04.2003
See Also
NoRollbackRuleAttribute

Field Summary

Modifier and TypeField and Description
private final String
exceptionPattern

Exception pattern: used when searching for matches in a thrown exception's class hierarchy based on names of exceptions, with zero type safety and potentially resulting in unintentional matches for similarly named exception types and nested exception types.

private final Class<? extends Throwable>
exceptionType

Exception type: used to ensure type safety when searching for matches in a thrown exception's class hierarchy.

public static final RollbackRuleAttribute

Constructor Summary

AccessConstructor and Description
public
RollbackRuleAttribute(Class<?>
exception type; must be Throwable or a subclass of Throwable
exceptionType
)

Create a new instance of the RollbackRuleAttribute class for the given exceptionType.

public
RollbackRuleAttribute(String
the exception name pattern; can also be a fully package-qualified class name
exceptionPattern
)

Create a new instance of the RollbackRuleAttribute class for the given exceptionPattern.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
getDepth(Throwable exception)

Return the depth of the superclass matching, with the following semantics.

private int
getDepth(Class<?> exceptionType, int depth)

public String
getExceptionName()

Get the configured exception name pattern that this rule uses for matching.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

exceptionPatternback to summary
private final String exceptionPattern

Exception pattern: used when searching for matches in a thrown exception's class hierarchy based on names of exceptions, with zero type safety and potentially resulting in unintentional matches for similarly named exception types and nested exception types.

exceptionTypeback to summary
private final Class<? extends Throwable> exceptionType

Exception type: used to ensure type safety when searching for matches in a thrown exception's class hierarchy.

Annotations
@Nullable
Since
6.0
ROLLBACK_ON_RUNTIME_EXCEPTIONSback to summary
public static final RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS

The rollback rule for RuntimeExceptions.

Constructor Detail

RollbackRuleAttributeback to summary
public RollbackRuleAttribute(Class<?> exceptionType)

Create a new instance of the RollbackRuleAttribute class for the given exceptionType.

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:Class<?>

exception type; must be Throwable or a subclass of Throwable

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if the supplied exceptionType is not a Throwable type or is null
RollbackRuleAttributeback to summary
public RollbackRuleAttribute(String exceptionPattern)

Create a new instance of the 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.

For improved type safety and to avoid unintentional matches, use RollbackRuleAttribute(Class) instead.

Parameters
exceptionPattern:String

the exception name pattern; can also be a fully package-qualified class name

Exceptions
IllegalArgumentException:
if the supplied exceptionPattern is null or empty

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDepthback to summary
public int getDepth(Throwable exception)

Return the depth of the superclass matching, with the following semantics.

  • -1 means this rule does not match the supplied exception.
  • 0 means this rule matches the supplied exception 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 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).

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.

getDepthback to summary
private int getDepth(Class<?> exceptionType, int depth)
getExceptionNameback to summary
public String getExceptionName()

Get the configured exception name pattern that this rule uses for matching.

See Also
getDepth(Throwable)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override