Introduce lazyTransactionalConnections flag on TransactionAwareDataSourceProxy
Includes revision of JDBC transaction tests. Closes gh-29423
This commit is contained in:
@@ -76,6 +76,8 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*/
|
||||
public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
|
||||
|
||||
private boolean lazyTransactionalConnections = true;
|
||||
|
||||
private boolean reobtainTransactionalConnections = false;
|
||||
|
||||
|
||||
@@ -94,6 +96,18 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
|
||||
super(targetDataSource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify whether to obtain the transactional target Connection lazily on
|
||||
* actual data access.
|
||||
* <p>The default is "true". Specify "false" to immediately obtain a target
|
||||
* Connection when a transaction-aware Connection handle is retrieved.
|
||||
* @since 6.1.2
|
||||
*/
|
||||
public void setLazyTransactionalConnections(boolean lazyTransactionalConnections) {
|
||||
this.lazyTransactionalConnections = lazyTransactionalConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to reobtain the target Connection for each operation
|
||||
* performed within a transaction.
|
||||
@@ -119,7 +133,12 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
|
||||
*/
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return getTransactionAwareConnectionProxy(obtainTargetDataSource());
|
||||
DataSource ds = obtainTargetDataSource();
|
||||
Connection con = getTransactionAwareConnectionProxy(ds);
|
||||
if (!this.lazyTransactionalConnections && shouldObtainFixedConnection(ds)) {
|
||||
((ConnectionProxy) con).getTargetConnection();
|
||||
}
|
||||
return con;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user