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());
}
}
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);
}
Aggregations