Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.transaction.support
Class DefaultTransactionDefinition

    java.lang.Object
      org.springframework.transaction.support.DefaultTransactionDefinition

All Implemented Interfaces:
  java.io.Serializable, TransactionDefinition

Direct Known Subclasses:
  DefaultTransactionAttribute, TransactionTemplate

    public class DefaultTransactionDefinition

extends java.lang.Object
implements TransactionDefinition, java.io.Serializable

Default implementation of the `TransactionDefinition` interface, offering bean-style configuration and sensible default values (PROPAGATION_REQUIRED, ISOLATION_DEFAULT, TIMEOUT_DEFAULT, readOnly=false).

Base class for both `TransactionTemplate` and `DefaultTransactionAttribute`.

Since:
  08.05.2003
Author:
  Juergen Hoeller
See Also:
  Serialized Form

Field Summary
`static java.lang.String` | `PREFIX_ISOLATION` Prefix for the isolation constants defined in TransactionDefinition
`static java.lang.String` | `PREFIX_PROPAGATION` Prefix for the propagation constants defined in TransactionDefinition
`static java.lang.String` | `PREFIX_TIMEOUT` Prefix for transaction timeout values in description strings
`static java.lang.String` | `READ_ONLY_MARKER` Marker for read-only transactions in description strings

Fields inherited from interface org.springframework.transaction.TransactionDefinition
`ISOLATION_DEFAULT, ISOLATION_READ_COMMITTED, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, PROPAGATION_MANDATORY, PROPAGATION_NESTED, PROPAGATION_NEVER, PROPAGATION_NOT_SUPPORTED, PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, PROPAGATION_SUPPORTS, TIMEOUT_DEFAULT`

Constructor Summary
`DefaultTransactionDefinition()` Create a new DefaultTransactionDefinition, with default settings.
`DefaultTransactionDefinition(int propagationBehavior)` Create a new DefaultTransactionDefinition with the the given propagation behavior.
`DefaultTransactionDefinition(TransactionDefinition other)` Copy constructor.

Method Summary
`boolean` | `equals(java.lang.Object other)` This implementation compares the `toString()` results.
`protected java.lang.StringBuilder` | `getDefinitionDescription()` Return an identifying description for this transaction definition.
`int` | `getIsolationLevel()` Return the isolation level.
`java.lang.String` | `getName()` Return the name of this transaction.
`int` | `getPropagationBehavior()` Return the propagation behavior.
`int` | `getTimeout()` Return the transaction timeout.
`int` | `hashCode()` This implementation returns `toString()`'s hash code.
`boolean` | `isReadOnly()` Return whether to optimize as a read-only transaction.
`void` | `setIsolationLevel(int isolationLevel)` Set the isolation level.
`void` | `setIsolationLevelName(java.lang.String constantName)` Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g.
`void` | `setName(java.lang.String name)` Set the name of this transaction.
`void` | `setPropagationBehavior(int propagationBehavior)` Set the propagation behavior.
`void` | `setPropagationBehaviorName(java.lang.String constantName)` Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g.
`void` | `setReadOnly(boolean readOnly)` Set whether to optimize as read-only transaction.
`void` | `setTimeout(int timeout)` Set the timeout to apply, as number of seconds.
`java.lang.String` | `toString()` Return an identifying description for this transaction definition.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### PREFIX_PROPAGATION

    public static final java.lang.String PREFIX_PROPAGATION

  Prefix for the propagation constants defined in TransactionDefinition

  See Also:
    Constant Field Values

### PREFIX_ISOLATION

    public static final java.lang.String PREFIX_ISOLATION

  Prefix for the isolation constants defined in TransactionDefinition

  See Also:
    Constant Field Values

### PREFIX_TIMEOUT

    public static final java.lang.String PREFIX_TIMEOUT

  Prefix for transaction timeout values in description strings

  See Also:
    Constant Field Values

### READ_ONLY_MARKER

    public static final java.lang.String READ_ONLY_MARKER

  Marker for read-only transactions in description strings

  See Also:
    Constant Field Values

Constructor Detail

### DefaultTransactionDefinition

    public DefaultTransactionDefinition()

  Create a new DefaultTransactionDefinition, with default settings. Can be modified through bean property setters.

  See Also:
    `setPropagationBehavior(int)`, `setIsolationLevel(int)`, `setTimeout(int)`, `setReadOnly(boolean)`, `setName(java.lang.String)`

### DefaultTransactionDefinition

    public DefaultTransactionDefinition(TransactionDefinition other)

  Copy constructor. Definition can be modified through bean property setters.

  See Also:
    `setPropagationBehavior(int)`, `setIsolationLevel(int)`, `setTimeout(int)`, `setReadOnly(boolean)`, `setName(java.lang.String)`

### DefaultTransactionDefinition

    public DefaultTransactionDefinition(int propagationBehavior)

  Create a new DefaultTransactionDefinition with the the given propagation behavior. Can be modified through bean property setters.

  Parameters:
    `propagationBehavior` - one of the propagation constants in the TransactionDefinition interface
  See Also:
    `setIsolationLevel(int)`, `setTimeout(int)`, `setReadOnly(boolean)`

Method Detail

### setPropagationBehaviorName

    public final void setPropagationBehaviorName(java.lang.String constantName)
                                          throws java.lang.IllegalArgumentException

  Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g. "PROPAGATION_REQUIRED".

  Parameters:
    `constantName` - name of the constant
  Throws:
    `java.lang.IllegalArgumentException` - if the supplied value is not resolvable to one of the `PROPAGATION_` constants or is `null`
  See Also:
    `setPropagationBehavior(int)`, `TransactionDefinition.PROPAGATION_REQUIRED`

### setPropagationBehavior

    public final void setPropagationBehavior(int propagationBehavior)

  Set the propagation behavior. Must be one of the propagation constants in the TransactionDefinition interface. Default is PROPAGATION_REQUIRED.

  Throws:
    `java.lang.IllegalArgumentException` - if the supplied value is not one of the `PROPAGATION_` constants
  See Also:
    `TransactionDefinition.PROPAGATION_REQUIRED`

### getPropagationBehavior

    public final int getPropagationBehavior()

  Description copied from interface: `TransactionDefinition`
  Return the propagation behavior.

  Must return one of the `PROPAGATION_XXX` constants defined on `this interface`.

  Specified by:
    `getPropagationBehavior` in interface `TransactionDefinition`
  Returns:
    the propagation behavior
  See Also:
    `TransactionDefinition.PROPAGATION_REQUIRED`, `TransactionSynchronizationManager.isActualTransactionActive()`

### setIsolationLevelName

    public final void setIsolationLevelName(java.lang.String constantName)
                                     throws java.lang.IllegalArgumentException

  Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g. "ISOLATION_DEFAULT".

  Parameters:
    `constantName` - name of the constant
  Throws:
    `java.lang.IllegalArgumentException` - if the supplied value is not resolvable to one of the `ISOLATION_` constants or is `null`
  See Also:
    `setIsolationLevel(int)`, `TransactionDefinition.ISOLATION_DEFAULT`

### setIsolationLevel

    public final void setIsolationLevel(int isolationLevel)

  Set the isolation level. Must be one of the isolation constants in the TransactionDefinition interface. Default is ISOLATION_DEFAULT.

  Throws:
    `java.lang.IllegalArgumentException` - if the supplied value is not one of the `ISOLATION_` constants
  See Also:
    `TransactionDefinition.ISOLATION_DEFAULT`

### getIsolationLevel

    public final int getIsolationLevel()

  Description copied from interface: `TransactionDefinition`
  Return the isolation level.

  Must return one of the `ISOLATION_XXX` constants defined on `this interface`.

  Only makes sense in combination with `TransactionDefinition.PROPAGATION_REQUIRED` or `TransactionDefinition.PROPAGATION_REQUIRES_NEW`.

  Note that a transaction manager that does not support custom isolation levels will throw an exception when given any other level than `TransactionDefinition.ISOLATION_DEFAULT`.

  Specified by:
    `getIsolationLevel` in interface `TransactionDefinition`
  Returns:
    the isolation level

### setTimeout

    public final void setTimeout(int timeout)

  Set the timeout to apply, as number of seconds. Default is TIMEOUT_DEFAULT (-1).

  See Also:
    `TransactionDefinition.TIMEOUT_DEFAULT`

### getTimeout

    public final int getTimeout()

  Description copied from interface: `TransactionDefinition`
  Return the transaction timeout.

  Must return a number of seconds, or `TransactionDefinition.TIMEOUT_DEFAULT`.

  Only makes sense in combination with `TransactionDefinition.PROPAGATION_REQUIRED` or `TransactionDefinition.PROPAGATION_REQUIRES_NEW`.

  Note that a transaction manager that does not support timeouts will throw an exception when given any other timeout than `TransactionDefinition.TIMEOUT_DEFAULT`.

  Specified by:
    `getTimeout` in interface `TransactionDefinition`
  Returns:
    the transaction timeout

### setReadOnly

    public final void setReadOnly(boolean readOnly)

  Set whether to optimize as read-only transaction. Default is "false".

### isReadOnly

    public final boolean isReadOnly()

  Description copied from interface: `TransactionDefinition`
  Return whether to optimize as a read-only transaction.

  The read-only flag applies to any transaction context, whether backed by an actual resource transaction (`TransactionDefinition.PROPAGATION_REQUIRED`/`TransactionDefinition.PROPAGATION_REQUIRES_NEW`) or operating non-transactionally at the resource level (`TransactionDefinition.PROPAGATION_SUPPORTS`). In the latter case, the flag will only apply to managed resources within the application, such as a Hibernate `Session`. << *

  This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction.

  Specified by:
    `isReadOnly` in interface `TransactionDefinition`
  Returns:
    `true` if the transaction is to be optimized as read-only
  See Also:
    `TransactionSynchronization.beforeCommit(boolean)`, `TransactionSynchronizationManager.isCurrentTransactionReadOnly()`

### setName

    public final void setName(java.lang.String name)

  Set the name of this transaction. Default is none.

  This will be used as transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's).

### getName

    public final java.lang.String getName()

  Description copied from interface: `TransactionDefinition`
  Return the name of this transaction. Can be `null`.

  This will be used as the transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's).

  In case of Spring's declarative transactions, the exposed name will be the `fully-qualified class name + "." + method name` (by default).

  Specified by:
    `getName` in interface `TransactionDefinition`
  Returns:
    the name of this transaction
  See Also:
    `TransactionAspectSupport`, `TransactionSynchronizationManager.getCurrentTransactionName()`

### equals

    public boolean equals(java.lang.Object other)

  This implementation compares the `toString()` results.

  Overrides:
    `equals` in class `java.lang.Object`
  See Also:
    `toString()`

### hashCode

    public int hashCode()

  This implementation returns `toString()`'s hash code.

  Overrides:
    `hashCode` in class `java.lang.Object`
  See Also:
    `toString()`

### toString

    public java.lang.String toString()

  Return an identifying description for this transaction definition.

  The format matches the one used by `TransactionAttributeEditor`, to be able to feed `toString` results into bean properties of type `TransactionAttribute`.

  Has to be overridden in subclasses for correct `equals` and `hashCode` behavior. Alternatively, `equals(java.lang.Object)` and `hashCode()` can be overridden themselves.

  Overrides:
    `toString` in class `java.lang.Object`
  See Also:
    `getDefinitionDescription()`, `TransactionAttributeEditor`

### getDefinitionDescription

    protected final java.lang.StringBuilder getDefinitionDescription()

  Return an identifying description for this transaction definition.

  Available to subclasses, for inclusion in their `toString()` result.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD