Search in sources :

Example 1 with PooledConnectionFactoryConfiguration

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

Example 2 with PooledConnectionFactoryConfiguration

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());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ManagedConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)

Example 3 with PooledConnectionFactoryConfiguration

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());
}
Also used : PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 4 with PooledConnectionFactoryConfiguration

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;
}
Also used : PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) PooledConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)

Example 5 with PooledConnectionFactoryConfiguration

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;
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ManagedConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)

Aggregations

PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Configuration (org.infinispan.configuration.cache.Configuration)2 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)2 ManagedConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)2 PooledConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)2 AgroalDataSource (io.agroal.api.AgroalDataSource)1 AgroalConnectionFactoryConfiguration (io.agroal.api.configuration.AgroalConnectionFactoryConfiguration)1 AgroalDataSourceConfigurationSupplier (io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier)1 AgroalPropertiesReader (io.agroal.api.configuration.supplier.AgroalPropertiesReader)1 NamePrincipal (io.agroal.api.security.NamePrincipal)1 SimplePassword (io.agroal.api.security.SimplePassword)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Duration (java.time.Duration)1 Util (org.infinispan.commons.util.Util)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)1