public class

DefaultTransactionDefinition

extends Object
implements Serializable TransactionDefinition
java.lang.Object
   ↳ org.springframework.transaction.support.DefaultTransactionDefinition
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

Constants
String PREFIX_ISOLATION Prefix for the isolation constants defined in TransactionDefinition
String PREFIX_PROPAGATION Prefix for the propagation constants defined in TransactionDefinition
String PREFIX_TIMEOUT Prefix for transaction timeout values in description strings
String READ_ONLY_MARKER Marker for read-only transactions in description strings
[Expand]
Inherited Constants
From interface org.springframework.transaction.TransactionDefinition
Public Constructors
DefaultTransactionDefinition()
Create a new DefaultTransactionDefinition, with default settings.
DefaultTransactionDefinition(TransactionDefinition other)
Copy constructor.
DefaultTransactionDefinition(int propagationBehavior)
Create a new DefaultTransactionDefinition with the the given propagation behavior.
Public Methods
boolean equals(Object other)
This implementation compares the toString() results.
final int getIsolationLevel()
Return the isolation level.
final String getName()
Return the name of this transaction.
final int getPropagationBehavior()
Return the propagation behavior.
final int getTimeout()
Return the transaction timeout.
int hashCode()
This implementation returns toString()'s hash code.
final boolean isReadOnly()
Return whether to optimize as a read-only transaction.
final void setIsolationLevel(int isolationLevel)
Set the isolation level.
final void setIsolationLevelName(String constantName)
Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g.
final void setName(String name)
Set the name of this transaction.
final void setPropagationBehavior(int propagationBehavior)
Set the propagation behavior.
final void setPropagationBehaviorName(String constantName)
Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g.
final void setReadOnly(boolean readOnly)
Set whether to optimize as read-only transaction.
final void setTimeout(int timeout)
Set the timeout to apply, as number of seconds.
String toString()
Return an identifying description for this transaction definition.
Protected Methods
final StringBuilder getDefinitionDescription()
Return an identifying description for this transaction definition.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.transaction.TransactionDefinition

Constants

public static final String PREFIX_ISOLATION

Prefix for the isolation constants defined in TransactionDefinition

Constant Value: "ISOLATION_"

public static final String PREFIX_PROPAGATION

Prefix for the propagation constants defined in TransactionDefinition

Constant Value: "PROPAGATION_"

public static final String PREFIX_TIMEOUT

Prefix for transaction timeout values in description strings

Constant Value: "timeout_"

public static final String READ_ONLY_MARKER

Marker for read-only transactions in description strings

Constant Value: "readOnly"

Public Constructors

public DefaultTransactionDefinition ()

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

public DefaultTransactionDefinition (TransactionDefinition other)

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

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

Public Methods

public boolean equals (Object other)

This implementation compares the toString() results.

See Also

public final int getIsolationLevel ()

Return the isolation level.

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

Only makes sense in combination with PROPAGATION_REQUIRED or 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 ISOLATION_DEFAULT.

Returns
  • the isolation level

public final String getName ()

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

Returns
  • the name of this transaction

public final int getPropagationBehavior ()

Return the propagation behavior.

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

Returns
  • the propagation behavior

public final int getTimeout ()

Return the transaction timeout.

Must return a number of seconds, or TIMEOUT_DEFAULT.

Only makes sense in combination with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW.

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

Returns
  • the transaction timeout

public int hashCode ()

This implementation returns toString()'s hash code.

See Also

public final boolean isReadOnly ()

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 (PROPAGATION_REQUIRED/PROPAGATION_REQUIRES_NEW) or operating non-transactionally at the resource level (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.

Returns
  • true if the transaction is to be optimized as read-only

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
IllegalArgumentException if the supplied value is not one of the ISOLATION_ constants

public final void setIsolationLevelName (String constantName)

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

Parameters
constantName name of the constant
Throws
IllegalArgumentException if the supplied value is not resolvable to one of the ISOLATION_ constants or is null

public final void setName (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).

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
IllegalArgumentException if the supplied value is not one of the PROPAGATION_ constants

public final void setPropagationBehaviorName (String constantName)

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

Parameters
constantName name of the constant
Throws
IllegalArgumentException if the supplied value is not resolvable to one of the PROPAGATION_ constants or is null

public final void setReadOnly (boolean readOnly)

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

public final void setTimeout (int timeout)

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

See Also

public 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(Object) and hashCode() can be overridden themselves.

Protected Methods

protected final StringBuilder getDefinitionDescription ()

Return an identifying description for this transaction definition.

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