Description
Backgroup: I have a large project with more than 500 nodes need to connection to one Database, so connection count is too high. In order to reduce db connections, I want to reuse one connection for all readonly transactions. So, I need to get the "TransactionSynchronizationManager.isCurrentTransactionReadOnly()" in Datasource.getConnection() method. While, in spring-jdbc-5.2.2, DataSourceTransactionManager.doBegin method, the connection is gotten at line 263, the readonly flag is setted at line 298.
Suggestion: Set the readonly flag before getting connection. e.g. in DataSourceTransactionManager.doBegin method
protected void doBegin(Object transaction, TransactionDefinition definition) {
TransactionSynchronizationManager.setCurrentTransactionReadOnly(definition.isReadOnly());
DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
...
Connection newCon = obtainDataSource().getConnection();
...
Then I will override a Datasource, that, return one shared connection to all readonly transactions.