use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class XAJPATransactionTest method configuredEntityManager.
private EntityManager configuredEntityManager(String jdbcUrl, String unit) throws Exception {
Dictionary<String, Object> props = getBaseProperties();
props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver");
props.put(DataSourceFactory.JDBC_URL, jdbcUrl);
props.put(EntityManagerFactoryBuilder.JPA_UNIT_NAME, unit);
String filter = System.getProperty(ARIES_EMF_BUILDER_TARGET_FILTER);
if (filter != null) {
props.put(ARIES_EMF_BUILDER_TARGET_FILTER, "(&(osgi.unit.name=" + unit + ")" + filter + ")");
}
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
org.osgi.service.cm.Configuration config = cm.createFactoryConfiguration("org.apache.aries.tx.control.jpa.xa", null);
config.update(props);
return getService(JPAEntityManagerProvider.class, "(" + EntityManagerFactoryBuilder.JPA_UNIT_NAME + "=" + unit + ")", 5000).getResource(txControl);
}
use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class XAJPATransactionTest method clearConfiguration.
private void clearConfiguration() {
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
org.osgi.service.cm.Configuration[] cfgs = null;
try {
cfgs = cm.listConfigurations(null);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (cfgs != null) {
for (org.osgi.service.cm.Configuration cfg : cfgs) {
try {
cfg.delete();
} catch (Exception e) {
}
}
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class ConnectionLifecycleTest method testDeleteOfConfig.
@Test
public void testDeleteOfConfig() throws Exception {
Assume.assumeTrue("Not a configuration 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);
}));
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jdbc.*)");
assertNotNull(configurations);
assertEquals(1, configurations.length);
configurations[0].delete();
Thread.sleep(2000);
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.cm.ConfigurationAdmin in project aries by apache.
the class AbstractJPATransactionTest method configuredEntityManager.
private EntityManager configuredEntityManager(String jdbcUrl) throws IOException {
Dictionary<String, Object> props = getBaseProperties();
props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver");
props.put(DataSourceFactory.JDBC_URL, jdbcUrl);
props.put(EntityManagerFactoryBuilder.JPA_UNIT_NAME, "test-unit");
String filter = System.getProperty(ARIES_EMF_BUILDER_TARGET_FILTER);
if (filter != null) {
props.put(ARIES_EMF_BUILDER_TARGET_FILTER, filter);
}
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
String pid = getBoolean(IS_XA) ? "org.apache.aries.tx.control.jpa.xa" : "org.apache.aries.tx.control.jpa.local";
System.out.println("Configuring connection provider with pid " + pid);
org.osgi.service.cm.Configuration config = cm.createFactoryConfiguration(pid, null);
config.update(props);
return getService(JPAEntityManagerProvider.class, 5000).getResource(txControl);
}
use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class AbstractJPATransactionTest method clearConfiguration.
private void clearConfiguration() {
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
org.osgi.service.cm.Configuration[] cfgs = null;
try {
cfgs = cm.listConfigurations(null);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (cfgs != null) {
for (org.osgi.service.cm.Configuration cfg : cfgs) {
try {
cfg.delete();
} catch (Exception e) {
}
}
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Aggregations