org.springframework.transaction
Interface TransactionDefinition

All Known Subinterfaces:
TransactionAttribute
All Known Implementing Classes:
DefaultTransactionAttribute, DefaultTransactionDefinition, DelegatingTransactionAttribute, RuleBasedTransactionAttribute, TransactionTemplate

public interface TransactionDefinition

Interface for classes that define transaction properties. Base interface for TransactionAttribute.

Note that isolation level, timeout and read-only settings will not get applied unless a new transaction gets started. As only PROPAGATION_REQUIRED and PROPAGATION_REQUIRES_NEW can actually cause that, it usually doesn't make sense to specify those settings in all other cases. Furthermore, be aware that not all transaction managers will support those advanced features and thus might throw corresponding exceptions when given non-default values.

Since:
08.05.2003
Author:
Juergen Hoeller
See Also:
PlatformTransactionManager.getTransaction(TransactionDefinition), DefaultTransactionDefinition, TransactionAttribute

Field Summary
static String ISOLATION_CONSTANT_PREFIX
           
static int ISOLATION_DEFAULT
          Use the default isolation level of the underlying datastore.
static int ISOLATION_READ_COMMITTED
          A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur.
static int ISOLATION_READ_UNCOMMITTED
          A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur.
static int ISOLATION_REPEATABLE_READ
          A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
static int ISOLATION_SERIALIZABLE
          A constant indicating that dirty reads, non-repeatable reads and phantom reads are prevented.
static String PROPAGATION_CONSTANT_PREFIX
           
static int PROPAGATION_MANDATORY
          Support a current transaction, throw an exception if none exists.
static int PROPAGATION_NESTED
          Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.
static int PROPAGATION_NEVER
          Execute non-transactionally, throw an exception if a transaction exists.
static int PROPAGATION_NOT_SUPPORTED
          Execute non-transactionally, suspend the current transaction if one exists.
static int PROPAGATION_REQUIRED
          Support a current transaction, create a new one if none exists.
static int PROPAGATION_REQUIRES_NEW
          Create a new transaction, suspend the current transaction if one exists.
static int PROPAGATION_SUPPORTS
          Support a current transaction, execute non-transactionally if none exists.
static int TIMEOUT_DEFAULT
          Use the default timeout of the underlying transaction system, or none if timeouts are not supported.
 
Method Summary
 int getIsolationLevel()
          Return the isolation level.
 String getName()
          Return the name of this transaction.
 int getPropagationBehavior()
          Return the propagation behavior.
 int getTimeout()
          Return the transaction timeout.
 boolean isReadOnly()
          Return whether to optimize as read-only transaction.
 

Field Detail

PROPAGATION_CONSTANT_PREFIX

static final String PROPAGATION_CONSTANT_PREFIX
See Also:
Constant Field Values

ISOLATION_CONSTANT_PREFIX

static final String ISOLATION_CONSTANT_PREFIX
See Also:
Constant Field Values

PROPAGATION_REQUIRED

static final int PROPAGATION_REQUIRED
Support a current transaction, create a new one if none exists. Analogous to EJB transaction attribute of the same name.

This is typically the default setting of a transaction definition.

See Also:
Constant Field Values

PROPAGATION_SUPPORTS

static final int PROPAGATION_SUPPORTS
Support a current transaction, execute non-transactionally if none exists. Analogous to EJB transaction attribute of the same name.

Note: For transaction managers with transaction synchronization, PROPAGATION_SUPPORTS is slightly different from no transaction at all, as it defines a transaction scopp that synchronization will apply for. As a consequence, the same resources (JDBC Connection, Hibernate Session, etc) will be shared for the entire specified scope. Note that this depends on the actual synchronization configuration of the transaction manager.

See Also:
AbstractPlatformTransactionManager.setTransactionSynchronization(int), Constant Field Values

PROPAGATION_MANDATORY

static final int PROPAGATION_MANDATORY
Support a current transaction, throw an exception if none exists. Analogous to EJB transaction attribute of the same name.

See Also:
Constant Field Values

PROPAGATION_REQUIRES_NEW

static final int PROPAGATION_REQUIRES_NEW
Create a new transaction, suspend the current transaction if one exists. Analogous to EJB transaction attribute of the same name.

Note: Actual transaction suspension will not work on out-of-the-box on all transaction managers. This in particular applies to JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).

See Also:
JtaTransactionManager.setTransactionManager(javax.transaction.TransactionManager), Constant Field Values

PROPAGATION_NOT_SUPPORTED

static final int PROPAGATION_NOT_SUPPORTED
Execute non-transactionally, suspend the current transaction if one exists. Analogous to EJB transaction attribute of the same name.

Note: Actual transaction suspension will not work on out-of-the-box on all transaction managers. This in particular applies to JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).

See Also:
JtaTransactionManager.setTransactionManager(javax.transaction.TransactionManager), Constant Field Values

PROPAGATION_NEVER

static final int PROPAGATION_NEVER
Execute non-transactionally, throw an exception if a transaction exists. Analogous to EJB transaction attribute of the same name.

See Also:
Constant Field Values

PROPAGATION_NESTED

static final int PROPAGATION_NESTED
Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB.

Note: Actual creation of a nested transaction will only work on specific transaction managers. Out of the box, this only applies to the JDBC DataSourceTransactionManager when working on a JDBC 3.0 driver. Some JTA providers might support nested transactions as well.

See Also:
DataSourceTransactionManager, Constant Field Values

ISOLATION_DEFAULT

static final int ISOLATION_DEFAULT
Use the default isolation level of the underlying datastore. All other levels correspond to the JDBC isolation levels.

See Also:
Connection, Constant Field Values

ISOLATION_READ_UNCOMMITTED

static final int ISOLATION_READ_UNCOMMITTED
A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur. This level allows a row changed by one transaction to be read by another transaction before any changes in that row have been committed (a "dirty read"). If any of the changes are rolled back, the second transaction will have retrieved an invalid row.

See Also:
Connection.TRANSACTION_READ_UNCOMMITTED, Constant Field Values

ISOLATION_READ_COMMITTED

static final int ISOLATION_READ_COMMITTED
A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur. This level only prohibits a transaction from reading a row with uncommitted changes in it.

See Also:
Connection.TRANSACTION_READ_COMMITTED, Constant Field Values

ISOLATION_REPEATABLE_READ

static final int ISOLATION_REPEATABLE_READ
A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur. This level prohibits a transaction from reading a row with uncommitted changes in it, and it also prohibits the situation where one transaction reads a row, a second transaction alters the row, and the first transaction rereads the row, getting different values the second time (a "non-repeatable read").

See Also:
Connection.TRANSACTION_REPEATABLE_READ, Constant Field Values

ISOLATION_SERIALIZABLE

static final int ISOLATION_SERIALIZABLE
A constant indicating that dirty reads, non-repeatable reads and phantom reads are prevented. This level includes the prohibitions in ISOLATION_REPEATABLE_READ and further prohibits the situation where one transaction reads all rows that satisfy a WHERE condition, a second transaction inserts a row that satisfies that WHERE condition, and the first transaction rereads for the same condition, retrieving the additional "phantom" row in the second read.

See Also:
Connection.TRANSACTION_SERIALIZABLE, Constant Field Values

TIMEOUT_DEFAULT

static final int TIMEOUT_DEFAULT
Use the default timeout of the underlying transaction system, or none if timeouts are not supported.

See Also:
Constant Field Values
Method Detail

getPropagationBehavior

int getPropagationBehavior()
Return the propagation behavior. Must return one of the PROPAGATION constants.

See Also:
PROPAGATION_REQUIRED, TransactionSynchronizationManager.isActualTransactionActive()

getIsolationLevel

int getIsolationLevel()
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.

See Also:
ISOLATION_DEFAULT

getTimeout

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.

See Also:
TIMEOUT_DEFAULT

isReadOnly

boolean isReadOnly()
Return whether to optimize as read-only transaction. This just serves as a hint for the actual transaction subsystem, it will not necessarily cause failure of write access attempts.

Intended to be used in combination with PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW. Beyond optimizing such actual transactions accordingly, a transaction manager might also pass the read-only flag to transaction synchronizations, even outside an actual transaction.

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

See Also:
TransactionSynchronization.beforeCommit(boolean), TransactionSynchronizationManager.isCurrentTransactionReadOnly()

getName

String getName()
Return the name of this transaction. Can be null. This will be used as 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).

See Also:
TransactionAspectSupport, TransactionSynchronizationManager.getCurrentTransactionName()


Copyright (c) 2002-2007 The Spring Framework Project.