|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jdbc.datasource.DelegatingDataSource
org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
Proxy for a target DataSource that is aware of Spring-managed transactions. Similar to a transactional JNDI DataSource as provided by a J2EE server.
Delegates to DataSourceUtils for automatically participating in thread-bound transactions, for example managed by DataSourceTransactionManager. getConnection calls and close calls on returned Connections will behave properly within a transaction, i.e. always work on the transactional Connection. If not within a transaction, normal DataSource behavior applies.
This proxy allows data access code to work with the plain JDBC API and still participate in Spring-managed transactions, similar to JDBC code in a J2EE/JTA environment. However, if possible, use Spring's DataAccessUtils, JdbcTemplate or JDBC operation objects to get transaction participation even without a proxy for the target DataSource, avoiding the need to define such a proxy in the first place.
NOTE: This DataSource proxy needs to return wrapped Connections to handle close calls on them properly. Therefore, the returned Connections cannot be cast to a native JDBC Connection type like OracleConnection, respectively to a connection pool implementation type.
DataSourceUtils.doGetConnection(javax.sql.DataSource, boolean)
,
DataSourceUtils.doCloseConnectionIfNecessary(java.sql.Connection, javax.sql.DataSource)
Constructor Summary | |
TransactionAwareDataSourceProxy()
Create a new TransactionAwareDataSourceProxy. |
|
TransactionAwareDataSourceProxy(javax.sql.DataSource targetDataSource)
Create a new TransactionAwareDataSourceProxy. |
Method Summary | |
java.sql.Connection |
getConnection()
Delegate to DataSourceUtils for automatically participating in Spring-managed transactions. |
protected java.sql.Connection |
getTransactionAwareConnectionProxy(java.sql.Connection target,
javax.sql.DataSource ds)
Wrap the given Connection with a proxy that delegates every method call to it but delegates close calls to DataSourceUtils. |
Methods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource |
afterPropertiesSet, getConnection, getLoginTimeout, getLogWriter, getTargetDataSource, setLoginTimeout, setLogWriter, setTargetDataSource |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TransactionAwareDataSourceProxy()
DelegatingDataSource.setTargetDataSource(javax.sql.DataSource)
public TransactionAwareDataSourceProxy(javax.sql.DataSource targetDataSource)
targetDataSource
- the target DataSourceMethod Detail |
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
getConnection
in class DelegatingDataSource
java.sql.SQLException
DataSourceUtils.doGetConnection(javax.sql.DataSource, boolean)
protected java.sql.Connection getTransactionAwareConnectionProxy(java.sql.Connection target, javax.sql.DataSource ds)
target
- the original Connection to wrap
DataSourceUtils.doCloseConnectionIfNecessary(java.sql.Connection, javax.sql.DataSource)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |