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