Search in sources :

Example 1 with JdbcStringBasedStoreConfiguration

use of org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration in project infinispan by infinispan.

the class MigratorConfigurationTest method testDbPropertiesLoaded.

public void testDbPropertiesLoaded() {
    Properties properties = createBaseProperties();
    properties.putAll(createBaseProperties(TARGET));
    Element[] storeTypes = new Element[] { SOURCE, TARGET };
    for (Element storeType : storeTypes) {
        properties.put(propKey(storeType, DB, MAJOR_VERSION), "1");
        properties.put(propKey(storeType, DB, MINOR_VERSION), "1");
        properties.put(propKey(storeType, DB, DISABLE_INDEXING), "true");
        properties.put(propKey(storeType, DB, DISABLE_UPSERT), "true");
        for (Element store : Arrays.asList(STRING, BINARY)) {
            properties.put(propKey(storeType, TABLE, store, TABLE_NAME_PREFIX), "mock_table_name");
            properties.put(propKey(storeType, TABLE, store, ID, NAME), "mock_id_column_name");
            properties.put(propKey(storeType, TABLE, store, ID, TYPE), "mock_id_column_type");
            properties.put(propKey(storeType, TABLE, store, DATA, NAME), "mock_data_column_name");
            properties.put(propKey(storeType, TABLE, store, DATA, TYPE), "mock_data_column_type");
            properties.put(propKey(storeType, TABLE, store, TIMESTAMP, NAME), "mock_timestamp_column_name");
            properties.put(propKey(storeType, TABLE, store, TIMESTAMP, TYPE), "mock_timestamp_column_type");
            properties.put(propKey(storeType, TABLE, store, SEGMENT, NAME), "mock_segment_column_name");
            properties.put(propKey(storeType, TABLE, store, SEGMENT, TYPE), "mock_segment_column_type");
        }
    }
    for (Element storeType : storeTypes) {
        StoreProperties props = new StoreProperties(storeType, properties);
        JdbcStringBasedStoreConfigurationBuilder builder = new ConfigurationBuilder().persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
        Configuration cacheConfig = JdbcConfigurationUtil.configureStore(props, builder).build();
        JdbcStringBasedStoreConfiguration config = (JdbcStringBasedStoreConfiguration) cacheConfig.persistence().stores().get(0);
        assertEquals((Integer) 1, config.dbMajorVersion());
        assertEquals((Integer) 1, config.dbMinorVersion());
        assertTrue(Boolean.parseBoolean(config.properties().getProperty(TableManagerFactory.INDEXING_DISABLED)));
        assertTrue(Boolean.parseBoolean(config.properties().getProperty(TableManagerFactory.UPSERT_DISABLED)));
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) Properties(java.util.Properties)

Example 2 with JdbcStringBasedStoreConfiguration

use of org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration 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 3 with JdbcStringBasedStoreConfiguration

use of org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration in project infinispan by infinispan.

the class OracleTableManagerTest method testShortIndexNamesOverlap.

public void testShortIndexNamesOverlap() {
    DbMetaData dbMetaData = new DbMetaData(DatabaseType.ORACLE, 12, 0, false, false, false);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class).table().tableNamePrefix("TBL").dataColumnName("DTC").dataColumnType("BINARY").idColumnName("IDC").idColumnType("VARCHAR(255)").timestampColumnName("TSC").timestampColumnType("BIGINT").segmentColumnName("SGC").segmentColumnType("INT").dataSource().jndiUrl("a_fake_jdni_url");
    Configuration configuration = builder.build();
    JdbcStringBasedStoreConfiguration storeConfiguration = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0);
    InitializationContextImpl context = new InitializationContextImpl(null, null, null, Mockito.mock(PersistenceMarshaller.class), null, null, null, null, null, null, null);
    OracleTableManager tableManager = new OracleTableManager(context, null, storeConfiguration, dbMetaData, "ALongishCacheName");
    String segmentIndexName = tableManager.getIndexName(true, "segment_index");
    String timestampIndexName = tableManager.getIndexName(true, "timestamp_index");
    assertFalse(segmentIndexName.equals(timestampIndexName));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Configuration(org.infinispan.configuration.cache.Configuration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller)

Example 4 with JdbcStringBasedStoreConfiguration

use of org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration in project infinispan by infinispan.

the class AbstractTableManager method start.

@Override
public void start() throws PersistenceException {
    if (config.createOnStart()) {
        Connection conn = null;
        try {
            conn = connectionFactory.getConnection();
            if (!tableExists(conn, metaTableName)) {
                createMetaTable(conn);
            }
            if (!tableExists(conn, dataTableName)) {
                createDataTable(conn);
            }
            createIndex(conn, timestampIndexExt, config.timestampColumnName());
            if (!dbMetadata.isSegmentedDisabled()) {
                createIndex(conn, segmentIndexExt, config.segmentColumnName());
            }
        } finally {
            connectionFactory.releaseConnection(conn);
        }
    }
    JdbcStringBasedStoreConfiguration configuration = ctx.getConfiguration();
    try {
        Object mapper = Util.loadClassStrict(configuration.key2StringMapper(), ctx.getGlobalConfiguration().classLoader()).newInstance();
        if (mapper instanceof Key2StringMapper)
            key2StringMapper = (Key2StringMapper) mapper;
    } catch (Exception e) {
        log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(), e.getClass().getName());
        throw new IllegalStateException("This should not happen.", e);
    }
}
Also used : Connection(java.sql.Connection) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) Key2StringMapper(org.infinispan.persistence.keymappers.Key2StringMapper) TwoWayKey2StringMapper(org.infinispan.persistence.keymappers.TwoWayKey2StringMapper) UnsupportedKeyTypeException(org.infinispan.persistence.keymappers.UnsupportedKeyTypeException) SQLException(java.sql.SQLException) PersistenceException(org.infinispan.persistence.spi.PersistenceException)

Aggregations

JdbcStringBasedStoreConfiguration (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)3 Configuration (org.infinispan.configuration.cache.Configuration)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)1 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)1 DummyInitializationContext (org.infinispan.persistence.DummyInitializationContext)1 InitializationContextImpl (org.infinispan.persistence.InitializationContextImpl)1 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 SimpleConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)1 SimpleConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory)1 Key2StringMapper (org.infinispan.persistence.keymappers.Key2StringMapper)1 TwoWayKey2StringMapper (org.infinispan.persistence.keymappers.TwoWayKey2StringMapper)1 UnsupportedKeyTypeException (org.infinispan.persistence.keymappers.UnsupportedKeyTypeException)1 PersistenceException (org.infinispan.persistence.spi.PersistenceException)1