Search in sources :

Example 1 with ManagedConnectionFactoryConfiguration

use of org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration in project infinispan by infinispan.

the class ConfigurationTest method testImplicitManagedConnectionFactory.

public void testImplicitManagedConnectionFactory() {
    ConfigurationBuilder b = new ConfigurationBuilder();
    JdbcStringBasedStoreConfigurationBuilder jdbc = b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
    UnitTestDatabaseManager.buildTableManipulation(jdbc.table());
    jdbc.dataSource().jndiUrl("java:jboss/datasources/ExampleDS");
    Configuration configuration = b.build();
    JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0);
    assert store.connectionFactory() instanceof ManagedConnectionFactoryConfiguration;
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ManagedConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration) ManagedConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)

Example 2 with ManagedConnectionFactoryConfiguration

use of org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration in project infinispan by infinispan.

the class ManagedConnectionFactory method start.

@Override
public void start(ConnectionFactoryConfiguration factoryConfiguration, ClassLoader classLoader) throws PersistenceException {
    InitialContext ctx = null;
    String datasourceName;
    if (factoryConfiguration instanceof ManagedConnectionFactoryConfiguration) {
        ManagedConnectionFactoryConfiguration managedConfiguration = (ManagedConnectionFactoryConfiguration) factoryConfiguration;
        datasourceName = managedConfiguration.jndiUrl();
    } else {
        throw new PersistenceException("FactoryConfiguration has to be an instance of " + "ManagedConnectionFactoryConfiguration");
    }
    try {
        ctx = new InitialContext();
        dataSource = (DataSource) ctx.lookup(datasourceName);
        if (log.isTraceEnabled()) {
            log.tracef("Datasource lookup for %s succeeded: %b", datasourceName, dataSource);
        }
        if (dataSource == null) {
            PERSISTENCE.connectionInJndiNotFound(datasourceName);
            throw new PersistenceException(String.format("Could not find a connection in jndi under the name '%s'", datasourceName));
        }
    } catch (NamingException e) {
        PERSISTENCE.namingExceptionLookingUpConnection(datasourceName, e);
        throw new PersistenceException(e);
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException e) {
                PERSISTENCE.failedClosingNamingCtx(e);
            }
        }
    }
}
Also used : PersistenceException(org.infinispan.persistence.spi.PersistenceException) NamingException(javax.naming.NamingException) ManagedConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration) InitialContext(javax.naming.InitialContext)

Aggregations

ManagedConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)2 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 Configuration (org.infinispan.configuration.cache.Configuration)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 PersistenceException (org.infinispan.persistence.spi.PersistenceException)1