org.springframework.transaction.support
Class DefaultTransactionDefinition

java.lang.Object
  extended byorg.springframework.transaction.support.DefaultTransactionDefinition
All Implemented Interfaces:
Serializable, TransactionDefinition
Direct Known Subclasses:
DefaultTransactionAttribute, TransactionTemplate

public class DefaultTransactionDefinition
extends Object
implements TransactionDefinition, 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
Version:
$Id: DefaultTransactionDefinition.java,v 1.9 2004/11/07 16:45:54 jhoeller Exp $
Author:
Juergen Hoeller
See Also:
TransactionTemplate, DefaultTransactionAttribute, Serialized Form

Field Summary
static String READ_ONLY_MARKER
          Marker for read-only transactions in description strings
static String TIMEOUT_PREFIX
          Prefix for transaction timeout values in description strings
 
Fields inherited from interface org.springframework.transaction.TransactionDefinition
ISOLATION_CONSTANT_PREFIX, ISOLATION_DEFAULT, ISOLATION_READ_COMMITTED, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, PROPAGATION_CONSTANT_PREFIX, 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.
 
Method Summary
 boolean equals(Object other)
          This implementation of equals compares the toString results.
protected  StringBuffer getDefinitionDescription()
          Return an identifying description of this transaction definition.
 int getIsolationLevel()
          Return the isolation level.
 int getPropagationBehavior()
          Return the propagation behavior.
 int getTimeout()
          Return the transaction timeout.
 int hashCode()
          This implementation of hashCode returns toString's hash code.
 boolean isReadOnly()
          Return whether to optimize as read-only transaction.
 void setIsolationLevel(int isolationLevel)
          Set the isolation level.
 void setIsolationLevelName(String constantName)
          Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g.
 void setPropagationBehavior(int propagationBehavior)
          Set the propagation behavior.
 void setPropagationBehaviorName(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.
 String toString()
          Return an identifying description of this transaction definition.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TIMEOUT_PREFIX

public static final String TIMEOUT_PREFIX
Prefix for transaction timeout values in description strings

See Also:
Constant Field Values

READ_ONLY_MARKER

public static final 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)

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(String constantName)
                                      throws 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:
IllegalArgumentException - if an invalid constant was specified
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.

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

Specified by:
getPropagationBehavior in interface TransactionDefinition
See Also:
TransactionDefinition.PROPAGATION_REQUIRED

setIsolationLevelName

public final void setIsolationLevelName(String constantName)
                                 throws 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:
IllegalArgumentException - if an invalid constant was specified
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.

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

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.

Specified by:
getIsolationLevel in interface TransactionDefinition
See Also:
TransactionDefinition.ISOLATION_DEFAULT

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

Specified by:
getTimeout in interface TransactionDefinition
See Also:
TransactionDefinition.TIMEOUT_DEFAULT

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 read-only transaction. This just serves as hint for the actual transaction subsystem, it will not necessarily cause failure of write accesses.

Only makes sense in combination with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW.

A transaction manager that cannot interpret the read-only hint will not throw an exception when given readOnly=true.

Specified by:
isReadOnly in interface TransactionDefinition

equals

public boolean equals(Object other)
This implementation of equals compares the toString results.

See Also:
toString()

hashCode

public int hashCode()
This implementation of hashCode returns toString's hash code.

See Also:
toString()

toString

public String toString()
Return an identifying description of this transaction definition. The format matches the one used by TransactionAttributeEditor, to be able to feed toString results into TransactionAttribute properties.

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

See Also:
TransactionAttributeEditor

getDefinitionDescription

protected final StringBuffer getDefinitionDescription()
Return an identifying description of this transaction definition. Available for subclasses.



Copyright (C) 2003-2004 The Spring Framework Project.