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

public Class DefaultTransactionDefinition

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

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 org.springframework.transaction.interceptor.DefaultTransactionAttribute.

Authors
Juergen Hoeller, Sam Brannen
Since
08.05.2003

Field Summary

Modifier and TypeField and Description
pack-priv static final Map<String, Integer>
isolationConstants

Map of constant names to constant values for the isolation constants defined in TransactionDefinition.

private int
private String
public static final String
PREFIX_ISOLATION

Prefix for the isolation constants defined in TransactionDefinition.

public static final String
PREFIX_PROPAGATION

Prefix for the propagation constants defined in TransactionDefinition.

public static final String
PREFIX_TIMEOUT

Prefix for transaction timeout values in description strings.

private int
pack-priv static final Map<String, Integer>
propagationConstants

Map of constant names to constant values for the propagation constants defined in TransactionDefinition.

public static final String
READ_ONLY_MARKER

Marker for read-only transactions in description strings.

private boolean
private int

Constructor Summary

AccessConstructor and Description
public
DefaultTransactionDefinition()

Create a new DefaultTransactionDefinition, with default settings.

public
public
DefaultTransactionDefinition(int
one of the propagation constants in the TransactionDefinition interface
propagationBehavior
)

Create a new DefaultTransactionDefinition with the given propagation behavior.

Method Summary

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

Overrides java.lang.Object.equals.

This implementation compares the toString() results.
protected final StringBuilder
getDefinitionDescription()

Return an identifying description for this transaction definition.

public final int
pack-priv static String
getIsolationLevelName(int isolationLevel)

public final String
getName()

Overrides default org.springframework.transaction.TransactionDefinition.getName.

Return the name of this transaction.
public final int
private static String
getPropagationBehaviorName(int propagationBehavior)

public final int
getTimeout()

Overrides default org.springframework.transaction.TransactionDefinition.getTimeout.

Return the transaction timeout.
public int
hashCode()

Overrides java.lang.Object.hashCode.

This implementation returns toString()'s hash code.
public final boolean
isReadOnly()

Overrides default org.springframework.transaction.TransactionDefinition.isReadOnly.

Return whether to optimize as a read-only transaction.
public final void
setIsolationLevel(int isolationLevel)

Set the isolation level.

public final void
setIsolationLevelName(String
name of the constant
constantName
)

Set the isolation level by the name of the corresponding constant in TransactionDefinition — for example, "ISOLATION_DEFAULT".

public final void
setName(String name)

Set the name of this transaction.

public final void
setPropagationBehavior(int propagationBehavior)

Set the propagation behavior.

public final void
setPropagationBehaviorName(String
name of the constant
constantName
)

Set the propagation behavior by the name of the corresponding constant in TransactionDefinition — for example, "PROPAGATION_REQUIRED".

public final void
setReadOnly(boolean readOnly)

Set whether to optimize as read-only transaction.

public final void
setTimeout(int timeout)

Set the timeout to apply, as number of seconds.

public String
toString()

Overrides java.lang.Object.toString.

Return an identifying description for this transaction definition.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

isolationConstantsback to summary
pack-priv static final Map<String, Integer> isolationConstants

Map of constant names to constant values for the isolation constants defined in TransactionDefinition.

isolationLevelback to summary
private int isolationLevel
nameback to summary
private String name
Annotations
@Nullable
PREFIX_ISOLATIONback to summary
public static final String PREFIX_ISOLATION

Prefix for the isolation constants defined in TransactionDefinition.

PREFIX_PROPAGATIONback to summary
public static final String PREFIX_PROPAGATION

Prefix for the propagation constants defined in TransactionDefinition.

PREFIX_TIMEOUTback to summary
public static final String PREFIX_TIMEOUT

Prefix for transaction timeout values in description strings.

propagationBehaviorback to summary
private int propagationBehavior
propagationConstantsback to summary
pack-priv static final Map<String, Integer> propagationConstants

Map of constant names to constant values for the propagation constants defined in TransactionDefinition.

READ_ONLY_MARKERback to summary
public static final String READ_ONLY_MARKER

Marker for read-only transactions in description strings.

readOnlyback to summary
private boolean readOnly
timeoutback to summary
private int timeout

Constructor Detail

DefaultTransactionDefinitionback to summary
public DefaultTransactionDefinition()

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

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName
DefaultTransactionDefinitionback to summary
public DefaultTransactionDefinition(TransactionDefinition other)

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

See Also
setPropagationBehavior, setIsolationLevel, setTimeout, setReadOnly, setName
DefaultTransactionDefinitionback to summary
public DefaultTransactionDefinition(int propagationBehavior)

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

Parameters
propagationBehavior:int

one of the propagation constants in the TransactionDefinition interface

See Also
setIsolationLevel, setTimeout, setReadOnly

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

This implementation compares the toString() results.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

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

Annotations
@Override
See Also
toString()
getDefinitionDescriptionback to summary
protected final StringBuilder getDefinitionDescription()

Return an identifying description for this transaction definition.

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

getIsolationLevelback to summary
public final int getIsolationLevel()

Overrides default org.springframework.transaction.TransactionDefinition.getIsolationLevel.

Doc from org.springframework.transaction.TransactionDefinition.getIsolationLevel.

Return the isolation level.

Must return one of the ISOLATION_XXX constants defined on this interface. Those constants are designed to match the values of the same constants on java.sql.Connection.

Exclusively designed for use with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW since it only applies to newly started transactions. Consider switching the "validateExistingTransactions" flag to "true" on your transaction manager if you'd like isolation level declarations to get rejected when participating in an existing transaction with a different isolation level.

The default is ISOLATION_DEFAULT. 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:int

the isolation level

Annotations
@Override
getIsolationLevelNameback to summary
pack-priv static String getIsolationLevelName(int isolationLevel)
getNameback to summary
public final String getName()

Overrides default org.springframework.transaction.TransactionDefinition.getName.

Doc from org.springframework.transaction.TransactionDefinition.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.

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

Returns:String

the name of this transaction (null by default}

Annotations
@Override
@Nullable
getPropagationBehaviorback to summary
public final int getPropagationBehavior()

Overrides default org.springframework.transaction.TransactionDefinition.getPropagationBehavior.

Doc from org.springframework.transaction.TransactionDefinition.getPropagationBehavior.

Return the propagation behavior.

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

The default is PROPAGATION_REQUIRED.

Returns:int

the propagation behavior

Annotations
@Override
getPropagationBehaviorNameback to summary
private static String getPropagationBehaviorName(int propagationBehavior)
getTimeoutback to summary
public final int getTimeout()

Overrides default org.springframework.transaction.TransactionDefinition.getTimeout.

Doc from org.springframework.transaction.TransactionDefinition.getTimeout.

Return the transaction timeout.

Must return a number of seconds, or TIMEOUT_DEFAULT.

Exclusively designed for use with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW since it only applies to newly started transactions.

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

The default is TIMEOUT_DEFAULT.

Returns:int

the transaction timeout

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

This implementation returns toString()'s hash code.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
See Also
toString()
isReadOnlyback to summary
public final boolean isReadOnly()

Overrides default org.springframework.transaction.TransactionDefinition.isReadOnly.

Doc from org.springframework.transaction.TransactionDefinition.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:boolean

true if the transaction is to be optimized as read-only (false by default)

Annotations
@Override
setIsolationLevelback to summary
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.

Exclusively designed for use with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW since it only applies to newly started transactions. Consider switching the "validateExistingTransactions" flag to "true" on your transaction manager if you'd like isolation level declarations to get rejected when participating in an existing transaction with a different isolation level.

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

Exceptions
IllegalArgumentException:
if the supplied value is not one of the ISOLATION_ constants
See Also
ISOLATION_DEFAULT
setIsolationLevelNameback to summary
public final void setIsolationLevelName(String constantName) throws IllegalArgumentException

Set the isolation level by the name of the corresponding constant in TransactionDefinition — for example, "ISOLATION_DEFAULT".

Parameters
constantName:String

name of the constant

Exceptions
IllegalArgumentException:
if the supplied value is not resolvable to one of the ISOLATION_ constants or is null
See Also
setIsolationLevel, ISOLATION_DEFAULT
setNameback to summary
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).

setPropagationBehaviorback to summary
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.

Exclusively designed for use with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW since it only applies to newly started transactions. Consider switching the "validateExistingTransactions" flag to "true" on your transaction manager if you'd like isolation level declarations to get rejected when participating in an existing transaction with a different isolation level.

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

Exceptions
IllegalArgumentException:
if the supplied value is not one of the PROPAGATION_ constants
See Also
PROPAGATION_REQUIRED
setPropagationBehaviorNameback to summary
public final void setPropagationBehaviorName(String constantName) throws IllegalArgumentException

Set the propagation behavior by the name of the corresponding constant in TransactionDefinition — for example, "PROPAGATION_REQUIRED".

Parameters
constantName:String

name of the constant

Exceptions
IllegalArgumentException:
if the supplied value is not resolvable to one of the PROPAGATION_ constants or is null
See Also
setPropagationBehavior, PROPAGATION_REQUIRED
setReadOnlyback to summary
public final void setReadOnly(boolean readOnly)

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

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.

setTimeoutback to summary
public final void setTimeout(int timeout)

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

Exclusively designed for use with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW since it only applies to newly started transactions.

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

See Also
TIMEOUT_DEFAULT
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return an identifying description for this transaction definition.

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

Has to be overridden in subclasses for correct equals and hashCode behavior. Alternatively, equals and hashCode can be overridden themselves.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
See Also
getDefinitionDescription(), org.springframework.transaction.interceptor.TransactionAttributeEditor