I'm not quite sure how to formulate the question, so feel free to tell me that I am thinking completly wrong.
I want to use the JdbcTemplate
and the TransactionTemplate
. I start of by initilizing my connection pool as datasource and the create a transaction manager as a datasource aswell?
BoneCPConfig connectionPoolConfig = new BoneCPConfig();
connectionPoolConfig.setJdbcUrl(...);
connectionPoolConfig.setUsername(...);
connectionPoolConfig.setPassword(...);
connectionPoolConfig.setMinConnectionsPerPartition(...);
connectionPoolConfig.setMaxConnectionsPerPartition(...);
dataSource = new BoneCPDataSource(connectionPoolConfig);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(dataSource);
But now I want to create my TransactionTemplate and JdbcTemplate:
transactionTemplate = new TransactionTemplate(transactionManager);
JdbcTemplate jdbc = new JdbcTemplate(transactionManager.getDataSource());
Now mulitple threads access transactionTemplate
and jdbc
. Does this code guarantee that everything done in doInTransaction
uses the same connection for all jdbc calls?
Is the connection somehow linked internally, because it looks as if JdbcTemplate and TransactionTemplate could use what ever connection they wanted. Is my code correct/save?