Search in sources :

Example 1 with ConfigurationAdmin

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);
}
Also used : JPAEntityManagerProvider(org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 2 with ConfigurationAdmin

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();
        }
    }
}
Also used : Configuration(org.ops4j.pax.exam.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) XAException(javax.transaction.xa.XAException) TransactionRolledBackException(org.osgi.service.transaction.control.TransactionRolledBackException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with ConfigurationAdmin

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());
    }
}
Also used : ScopedWorkException(org.osgi.service.transaction.control.ScopedWorkException) TransactionException(org.osgi.service.transaction.control.TransactionException) Configuration(org.osgi.service.cm.Configuration) ResultSet(java.sql.ResultSet) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 4 with ConfigurationAdmin

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);
}
Also used : JPAEntityManagerProvider(org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 5 with ConfigurationAdmin

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();
        }
    }
}
Also used : Configuration(org.ops4j.pax.exam.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) NoSuchElementException(java.util.NoSuchElementException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Aggregations

ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)211 Configuration (org.osgi.service.cm.Configuration)114 Test (org.junit.Test)65 Hashtable (java.util.Hashtable)57 ServiceReference (org.osgi.framework.ServiceReference)52 IOException (java.io.IOException)44 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 BundleContext (org.osgi.framework.BundleContext)25 Subject (javax.security.auth.Subject)24 Dictionary (java.util.Dictionary)23 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)21 Bundle (org.osgi.framework.Bundle)16 Properties (java.util.Properties)15 File (java.io.File)8 HashSet (java.util.HashSet)7 BundleException (org.osgi.framework.BundleException)7 Method (java.lang.reflect.Method)6 ObjectName (javax.management.ObjectName)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4