Search in sources :

Example 1 with JDBCConnectionProviderFactory

use of org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory in project aries by apache.

the class ConnectionLifecycleTest method testReleaseOfFactoryCreatedService.

@Test
public void testReleaseOfFactoryCreatedService() {
    Assume.assumeFalse("Not a factory test", isConfigured());
    txControl.required(() -> connection.createStatement().execute("Insert into TEST_TABLE values ( 'Hello World!' )"));
    assertEquals("Hello World!", txControl.notSupported(() -> {
        ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
        rs.next();
        return rs.getString(1);
    }));
    JDBCConnectionProviderFactory factory = (JDBCConnectionProviderFactory) trackers.stream().filter(t -> t.getService() instanceof JDBCConnectionProviderFactory).findFirst().get().getService();
    factory.releaseProvider(provider);
    try {
        assertEquals("Hello World!", txControl.notSupported(() -> {
            ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
            rs.next();
            return rs.getString(1);
        }));
        fail("Should not be accessible");
    } catch (ScopedWorkException swe) {
        assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
        assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
    }
}
Also used : ScopedWorkException(org.osgi.service.transaction.control.ScopedWorkException) TransactionException(org.osgi.service.transaction.control.TransactionException) JDBCConnectionProviderFactory(org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 2 with JDBCConnectionProviderFactory

use of org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory in project aries by apache.

the class AbstractTransactionTest method programaticConnection.

private Connection programaticConnection(Properties jdbc) {
    JDBCConnectionProviderFactory resourceProviderFactory = getService(JDBCConnectionProviderFactory.class, 5000);
    DataSourceFactory dsf = getService(DataSourceFactory.class, 5000);
    provider = resourceProviderFactory.getProviderFor(dsf, jdbc, resourceProviderConfig());
    return provider.getResource(txControl);
}
Also used : DataSourceFactory(org.osgi.service.jdbc.DataSourceFactory) JDBCConnectionProviderFactory(org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory)

Aggregations

JDBCConnectionProviderFactory (org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory)2 ResultSet (java.sql.ResultSet)1 Test (org.junit.Test)1 DataSourceFactory (org.osgi.service.jdbc.DataSourceFactory)1 ScopedWorkException (org.osgi.service.transaction.control.ScopedWorkException)1 TransactionException (org.osgi.service.transaction.control.TransactionException)1