org.springframework.jdbc.datasource
Class DataSourceTransactionManager
org.springframework.transaction.support.AbstractPlatformTransactionManager
|
+--org.springframework.jdbc.datasource.DataSourceTransactionManager
- public class DataSourceTransactionManager
- extends AbstractPlatformTransactionManager
- implements InitializingBean
PlatformTransactionManager implementation for single JDBC data sources.
Binds a JDBC connection from the specified data source to the thread,
potentially allowing for one thread connection per data source.
Application code is required to retrieve the JDBC connection via
DataSourceUtils.getConnection(DataSource) instead of J2EE's standard
DataSource.getConnection. This is recommended anyway, as it throws
unchecked org.springframework.dao exceptions instead of checked SQLException.
All framework classes like JdbcTemplate use this strategy implicitly.
If not used with this transaction manager, the lookup strategy
behaves exactly like the common one - it can thus be used in any case.
Supports custom isolation levels, and timeouts that get applied as
appropriate JDBC statement query timeouts. To support the latter,
application code must either use JdbcTemplate or call DataSourceUtils'
applyTransactionTimeout method for each created statement.
This implementation can be used instead of JtaTransactionManager
in the single resource case, as it does not require the container to
support JTA. Switching between both is just a matter of configuration,
if you stick to the required connection lookup pattern. Note that JTA
does not support custom isolation levels!
- Author:
- Juergen Hoeller
- Version: $Id: DataSourceTransactionManager.java,v 1.13 2004/01/26 18:03:42 jhoeller Exp $
- Since: 02.05.2003
- See Also: DataSourceUtils.getConnection(javax.sql.DataSource), DataSourceUtils.applyTransactionTimeout(java.sql.Statement,javax.sql.DataSource), DataSourceUtils.closeConnectionIfNecessary(java.sql.Connection,javax.sql.DataSource), JdbcTemplate
| Method Summary |
void | afterPropertiesSet() |
DataSource | getDataSource() Return the J2EE DataSource that this instance manages transactions for. |
void | setDataSource(DataSource dataSource) Set the J2EE DataSource that this instance should manage transactions for. |
DataSourceTransactionManager
public DataSourceTransactionManager()
- Create a new DataSourceTransactionManager instance.
A DataSource has to be set to be able to use it.
- See Also:
- setDataSource(javax.sql.DataSource)
DataSourceTransactionManager
public DataSourceTransactionManager(DataSource dataSource)
- Create a new DataSourceTransactionManager instance.
- Parameters:
- dataSource - DataSource to manage transactions for
afterPropertiesSet
public void afterPropertiesSet()
getDataSource
public DataSource getDataSource()
- Return the J2EE DataSource that this instance manages transactions for.
setDataSource
public void setDataSource(DataSource dataSource)
- Set the J2EE DataSource that this instance should manage transactions for.
to Class javax.sql.DataSource