Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.0
-
None
-
None
-
Apache Karaf 4.2.6 + pax-jdbc + pax-jdbc-config + pax-jdbc-pool-dbcp2 + tx-control-service-xa + tx-control-provider-jdbc-xa
Description
Use case
Shared datasource between bundles. Some of them are using plain javax.sql.DataSource (camel-jdbc), some are using TransactionControl.
Steps to reproduce
- Register DataSource service using some pool (pax-jdbc-pool-dbcp2)
- Install bundle that
- Acquires Connection through JDBCConnectionProvider using previously registered datasource
- Uses the Connection through TransactionControl
- Restart the bundle
Expected behaviour
Possible to use connection
Observed behaviour
org.osgi.service.transaction.control.ScopedWorkException: The scoped work threw an exception ... Caused by: org.osgi.service.transaction.control.TransactionException: There was a problem getting hold of a database connection ... Caused by: java.lang.IllegalStateException: Pool not open
Possible solution
Do not close the underlying datasource if it wasn't created by JDBCConnectionProviderFactory
Code sample
@Reference TransactionControl transactionControl; @Reference JDBCConnectionProviderFactory jdbcConnectionProviderFactory; @Reference DataSource dataSource; private Connection connection; @Activate public void activate() throws Exception { Map<String, Object> props = new HashMap<>(); props.put("osgi.connection.pooling.enabled", "false"); props.put("osgi.xa.enabled", "false"); JDBCConnectionProvider provider = jdbcConnectionProviderFactory.getProviderFor(dataSource, props); Connection = provider.getResource(transactionControl); transactionControl.notSupported(() -> { PreparedStatement stmt = connection.prepareStatement("SELECT 1 FROM dual"); stmt.execute(); return null; }); }