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