use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration 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");
}
use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class ConfigurationTest method testJdbcStringCacheStoreConfigurationAdaptor.
public void testJdbcStringCacheStoreConfigurationAdaptor() {
ConfigurationBuilder b = new ConfigurationBuilder();
b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class).connectionPool().connectionUrl(JDBC_URL).fetchPersistentState(true).table().tableNamePrefix("STRINGS_").idColumnName("id").idColumnType("VARCHAR").dataColumnName("datum").dataColumnType("BINARY").timestampColumnName("version").timestampColumnType("BIGINT").segmentColumnName("segfault").segmentColumnType("BIGINT").async().enable();
Configuration configuration = b.build();
JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0);
assertTrue(store.connectionFactory() instanceof PooledConnectionFactoryConfiguration);
assertEquals(JDBC_URL, ((PooledConnectionFactoryConfiguration) store.connectionFactory()).connectionUrl());
assertEquals("STRINGS_", store.table().tableNamePrefix());
assertEquals("id", store.table().idColumnName());
assertEquals("VARCHAR", store.table().idColumnType());
assertEquals("datum", store.table().dataColumnName());
assertEquals("BINARY", store.table().dataColumnType());
assertEquals("version", store.table().timestampColumnName());
assertEquals("BIGINT", store.table().timestampColumnType());
assertEquals("segfault", store.table().segmentColumnName());
assertEquals("BIGINT", store.table().segmentColumnType());
assertTrue(store.fetchPersistentState());
assertTrue(store.async().enabled());
b = new ConfigurationBuilder();
b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class).read(store);
Configuration configuration2 = b.build();
JdbcStringBasedStoreConfiguration store2 = (JdbcStringBasedStoreConfiguration) configuration2.persistence().stores().get(0);
assertTrue(store2.connectionFactory() instanceof PooledConnectionFactoryConfiguration);
assertEquals(JDBC_URL, ((PooledConnectionFactoryConfiguration) store2.connectionFactory()).connectionUrl());
assertEquals("STRINGS_", store2.table().tableNamePrefix());
assertEquals("id", store2.table().idColumnName());
assertEquals("VARCHAR", store2.table().idColumnType());
assertEquals("datum", store2.table().dataColumnName());
assertEquals("BINARY", store2.table().dataColumnType());
assertEquals("version", store2.table().timestampColumnName());
assertEquals("BIGINT", store2.table().timestampColumnType());
assertEquals("segfault", store2.table().segmentColumnName());
assertEquals("BIGINT", store2.table().segmentColumnType());
assertTrue(store2.fetchPersistentState());
assertTrue(store2.async().enabled());
}
use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class XmlFileParsingTest method testStringKeyedJdbcStore.
public void testStringKeyedJdbcStore() throws Exception {
String config = TestingUtil.wrapXMLWithSchema(" <cache-container default-cache=\"default\">\n" + " <transport/>\n" + " <distributed-cache name=\"default\">\n" + " <persistence>\n" + " <string-keyed-jdbc-store xmlns=\"urn:infinispan:config:store:jdbc:" + Version.getSchemaVersion() + "\" key-to-string-mapper=\"DummyKey2StringMapper\" shared=\"true\" " + " preload=\"true\" read-only=\"false\" fetch-state=\"true\" dialect=\"H2\">\n" + " <connection-pool connection-url=\"jdbc:h2:mem:infinispan;DB_CLOSE_DELAY=-1\" username=\"dbuser\" password=\"dbpass\" driver=\"org.h2.Driver\"/>\n" + " <string-keyed-table prefix=\"entry\" fetch-size=\"34\" batch-size=\"128\" >\n" + " <id-column name=\"id\" type=\"VARCHAR\" />\n" + " <data-column name=\"datum\" type=\"BINARY\" />\n" + " <timestamp-column name=\"version\" type=\"BIGINT\" />\n" + " <segment-column name=\"segfault\" type=\"BIGINT\" />\n" + " </string-keyed-table>\n" + " <write-behind />\n" + " </string-keyed-jdbc-store>\n" + " </persistence>\n" + " </distributed-cache></cache-container>\n");
InputStream is = new ByteArrayInputStream(config.getBytes());
cacheManager = TestCacheManagerFactory.fromStream(is, true, false);
assertEquals(1, cacheManager.getDefaultCacheConfiguration().persistence().stores().size());
JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) cacheManager.getDefaultCacheConfiguration().persistence().stores().get(0);
assertEquals(128, store.table().batchSize());
assertEquals(34, store.table().fetchSize());
assertEquals("BINARY", store.table().dataColumnType());
assertEquals("version", store.table().timestampColumnName());
assertEquals("segfault", store.table().segmentColumnName());
assertTrue(store.async().enabled());
assertEquals("DummyKey2StringMapper", store.key2StringMapper());
assertTrue(store.shared());
assertTrue(store.preload());
assertEquals(DatabaseType.H2, store.dialect());
PooledConnectionFactoryConfiguration connectionFactory = (PooledConnectionFactoryConfiguration) store.connectionFactory();
assertEquals("jdbc:h2:mem:infinispan;DB_CLOSE_DELAY=-1", connectionFactory.connectionUrl());
assertEquals("org.h2.Driver", connectionFactory.driverClass());
assertEquals("dbuser", connectionFactory.username());
assertEquals("dbpass", connectionFactory.password());
assertFalse(store.ignoreModifications());
assertTrue(store.fetchPersistentState());
assertFalse(store.purgeOnStartup());
}
use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class TableManipulation method getConnectionFactory.
private ConnectionFactory getConnectionFactory() {
PooledConnectionFactoryConfiguration pooledConnectionFactoryConfiguration = persistenceConfiguration.create();
connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
connectionFactory.start(pooledConnectionFactoryConfiguration, connectionFactory.getClass().getClassLoader());
return connectionFactory;
}
use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class ConfigurationTest method testImplicitPooledConnectionFactory.
public void testImplicitPooledConnectionFactory() {
ConfigurationBuilder b = new ConfigurationBuilder();
JdbcStringBasedStoreConfigurationBuilder jdbc = b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
UnitTestDatabaseManager.buildTableManipulation(jdbc.table());
jdbc.connectionPool().connectionUrl(JDBC_URL);
Configuration configuration = b.build();
JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0);
assert store.connectionFactory() instanceof PooledConnectionFactoryConfiguration;
}
Aggregations