Datasource
Spring
Section titled “Spring”This integration works only if you use the DatasourceConnectionProvider for TX management.
With the tool DataSourceUtils.getConnection we can get the current
connection for the current transaction.
First we create a implementation of JdbcConnectionProvider and add it to the
Spring config.
public class DatasourceConnectionProvider implements JdbcConnectionProvider { private final DataSource dataSource;
public DatasourceConnectionProvider(DataSource dataSource) { this.dataSource = requireNonNull(dataSource); }
@Override public Connection getConnection() { return DataSourceUtils.getConnection(this.dataSource); }
}Later we can use it in the dependency injection to be injected in our generated classes. Please find below the common code.
@BeanPlatformTransactionManager transactionManager(DataSource dataSource) { return new DataSourceTransactionManager(dataSource);}
@BeanJdbcConnectionProvider datasourceConnectionProvider(DataSource dataSource) { return new DatasourceConnectionProvider(dataSource);}
@BeanNamesService namesServiceKaumei(JdbcConnectionProvider provider) { return new NamesServiceKaumeiJdbc(provider);}References
Section titled “References”Other frameworks
Section titled “Other frameworks”Not yet tested. Expected to behave similarly to Spring.