Konstantin J. Chernov created ARIES-1920:
--------------------------------------------

             Summary: Do not close the datasource if it wasn't created by 
JDBCConnectionProviderFactory
                 Key: ARIES-1920
                 URL: https://issues.apache.org/jira/browse/ARIES-1920
             Project: Aries
          Issue Type: Bug
          Components: tx-control
    Affects Versions: 1.0
         Environment: Apache Karaf 4.2.6 + pax-jdbc + pax-jdbc-config + 
pax-jdbc-pool-dbcp2 + tx-control-service-xa + tx-control-provider-jdbc-xa

 
            Reporter: Konstantin J. Chernov


h4. Use case

Shared datasource between bundles. Some of them are using plain 
javax.sql.DataSource (camel-jdbc), some are using TransactionControl.

h4. 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

h4. Expected behaviour
Possible to use connection

h4. Observed behaviour
{code:java}
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
{code}

h4. Possible solution
Do not close the underlying datasource if it wasn't created by 
JDBCConnectionProviderFactory

h4. Code sample

{code:java}
@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;
    });
}
{code}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to