-
Notifications
You must be signed in to change notification settings - Fork 22
Spring Jdbc
Zsolt Herpai edited this page May 17, 2015
·
2 revisions
Spring provides a transaction-aware datasource proxy to wrap an existing DataSource, to participate seamlessly in Spring transactions: TransactionAwareDataSourceProxy
// wrap a DataSource for transaction management
DataSource dataSource = ...
DataSource transactionalDataSource = new TransactionAwareDataSourceProxy(dataSource);
// create a FluentJdbc ConnectionProvider based on it
ConnectionProvider cp = new DataSourceConnectionProvider(transactionalDataSource);
Alternatively transaction-managed connections can be acquired from JdbcTemplate's Connection callback:
ConnectionProvider provider = query -> jdbcTemplate.execute(query::receive);