Class DataSourceTransactionManager

All Implemented Interfaces:
ResourceTransactionManager<DataSource,Connection>, TransactionStateOperations<Connection,SynchronousTransactionState>, SynchronousTransactionManager<Connection>, TransactionManager, TransactionOperations<Connection>, Serializable

NOTICE: This is a fork of Spring's PlatformTransactionManager modernizing it to use enums, Slf4j and decoupling from Spring. SynchronousTransactionManager implementation for a single JDBC DataSource. This class is capable of working in any environment with any JDBC driver, as long as the setup uses a javax.sql.DataSource as its Connection factory mechanism. Binds a JDBC Connection from the specified DataSource to the current thread, potentially allowing for one thread-bound Connection per DataSource.

Note: The DataSource that this transaction manager operates on needs to return independent Connections. The Connections may come from a pool (the typical case), but the DataSource must not return thread-scoped / request-scoped Connections or the like. This transaction manager will associate Connections with thread-bound transactions itself, according to the specified propagation behavior. It assumes that a separate, independent Connection can be obtained even during an ongoing transaction.

Application code is required to retrieve the JDBC Connection via DataSourceUtils.getConnection(DataSource) instead of a standard Java EE-style DataSource.getConnection() call. If not used in combination with this transaction manager, the DataSourceUtils lookup strategy behaves exactly like the native DataSource lookup; it can thus be used in a portable fashion.

Alternatively, you can allow application code to work with the standard Java EE-style lookup pattern DataSource.getConnection().

This transaction manager supports nested transactions via the JDBC 3.0 Savepoint mechanism. The "nestedTransactionAllowed" flag defaults to "true", since nested transactions will work without restrictions on JDBC drivers that support savepoints (such as the Oracle JDBC driver).

As of 4.3.4, this transaction manager triggers flush callbacks on registered transaction synchronizations (if synchronization is generally active), assuming resources operating on the underlying JDBC Connection. This allows for setup analogous to JtaTransactionManager, in particular with respect to lazily registered ORM resources (e.g. a Hibernate Session).

Since:
02.05.2003
Author:
Juergen Hoeller, graemerocher
See Also: