Search in sources :

Example 1 with SimpleConnectionFactoryConfiguration

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

the class SimpleConnectionFactory method start.

@Override
public void start(ConnectionFactoryConfiguration config, ClassLoader classLoader) throws PersistenceException {
    SimpleConnectionFactoryConfiguration factoryConfiguration;
    if (config instanceof SimpleConnectionFactoryConfiguration) {
        factoryConfiguration = (SimpleConnectionFactoryConfiguration) config;
    } else {
        throw new PersistenceException("ConnectionFactoryConfiguration has to be an instance of " + "SimpleConnectionFactoryConfiguration.");
    }
    loadDriver(factoryConfiguration.driverClass(), classLoader);
    this.connectionUrl = factoryConfiguration.connectionUrl();
    this.userName = factoryConfiguration.username();
    this.password = factoryConfiguration.password();
    if (log.isTraceEnabled()) {
        log.tracef("Starting connection %s", this);
    }
}
Also used : PersistenceException(org.infinispan.persistence.spi.PersistenceException) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)

Example 2 with SimpleConnectionFactoryConfiguration

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

the class TableManagerTest method createConnection.

@BeforeClass
public void createConnection() throws Exception {
    JdbcStringBasedStoreConfigurationBuilder storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
    UnitTestDatabaseManager.setDialect(storeBuilder);
    UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table());
    ConnectionFactoryConfiguration factoryConfiguration = UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
    if (factoryConfiguration instanceof SimpleConnectionFactoryConfiguration) {
        SimpleConnectionFactoryConfiguration simpleConfiguration = (SimpleConnectionFactoryConfiguration) factoryConfiguration;
        connectionFactory = ConnectionFactory.getConnectionFactory(SimpleConnectionFactory.class);
        connectionFactory.start(simpleConfiguration, connectionFactory.getClass().getClassLoader());
        connection = connectionFactory.getConnection();
    } else if (factoryConfiguration instanceof PooledConnectionFactoryConfiguration) {
        PooledConnectionFactoryConfiguration pooledConfiguration = (PooledConnectionFactoryConfiguration) factoryConfiguration;
        connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
        connectionFactory.start(pooledConfiguration, connectionFactory.getClass().getClassLoader());
        connection = connectionFactory.getConnection();
    }
    Cache<?, ?> cache = mock(Cache.class);
    when(cache.getCacheConfiguration()).thenReturn(new ConfigurationBuilder().build());
    JdbcStringBasedStoreConfiguration config = storeBuilder.create();
    GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class);
    when(globalConfiguration.classLoader()).thenReturn(getClass().getClassLoader());
    ctx = new DummyInitializationContext(config, cache, new TestObjectStreamMarshaller(), null, null, null, globalConfiguration, null, null, null);
    tableManager = TableManagerFactory.getManager(ctx, connectionFactory, config, "aName");
}
Also used : SimpleConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory) DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

SimpleConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)1 DummyInitializationContext (org.infinispan.persistence.DummyInitializationContext)1 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 SimpleConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory)1 JdbcStringBasedStoreConfiguration (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration)1 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)1 PersistenceException (org.infinispan.persistence.spi.PersistenceException)1 BeforeClass (org.testng.annotations.BeforeClass)1