org.springframework.transaction.interceptor

## 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 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 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.

  Since:
    09.04.2003
  Author:
    Rod Johnson, Sam Brannen
  See Also:
    `NoRollbackRuleAttribute`, Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static RollbackRuleAttribute` | `ROLLBACK_ON_RUNTIME_EXCEPTIONS` The rollback rule for `RuntimeExceptions`.

  - ### Constructor Summary

    Constructors
    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`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ROLLBACK_ON_RUNTIME_EXCEPTIONS

          public static final RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS

      The rollback rule for `RuntimeExceptions`.

  - ### Constructor Detail

    - #### RollbackRuleAttribute

          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, 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.

      Parameters:
        `exceptionType` - exception type; must be `Throwable` or a subclass of `Throwable`
      Throws:
        `IllegalArgumentException` - if the supplied `exceptionType` is not a `Throwable` type or is `null`

    - #### RollbackRuleAttribute

          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.

      Parameters:
        `exceptionPattern` - the exception name pattern; can also be a fully package-qualified class name
      Throws:
        `IllegalArgumentException` - if the supplied `exceptionPattern` is `null` or empty

  - ### Method Detail

    - #### getExceptionName

          public String getExceptionName()

      Get the configured exception name pattern that this rule uses for matching.
      See Also:
        `getDepth(Throwable)`

    - #### getDepth

          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`).

      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

          public boolean equals(@Nullable
                                Object other)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`