Infinispan jdbc CacheLoader programmatic configuration issues
jeetu Mar 1, 2013 12:40 PMHi,
I am trying to configure the JdbcStringBasedCacheStore for my project. I am using Infinispan 5.2.0.ALPHA2 version, as it works well on my Jboss EAP 6 server with infinispan-cdi and infinispan-query modules.
I am trying to configure the cache loader programmatically taking reference to the sample configurations provided at https://docs.jboss.org/author/display/ISPN/Cache+Loaders+and+Stores#CacheLoadersandStores-JDBCbasedcacheloaders
The documentation sample configuration does not work on this infinispan-cachestore-jdbc version.
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.loaders().addLoader(JdbcStringBasedCacheStoreConfigurationBuilder.class)
.fetchPersistentState(false).ignoreModifications(false).purgeOnStartup(false)
.table()
.dropOnExit(true)
.createOnStart(true)
.tableNamePrefix("ISPN_STRING_TABLE")
.idColumnName("ID_COLUMN").idColumnType("VARCHAR(255)")
.dataColumnName("DATA_COLUMN").dataColumnType("BINARY")
.timestampColumnName("TIMESTAMP_COLUMN").timestampColumnType("BIGINT")
.connectionPool()
.connectionUrl("jdbc:h2:mem:infinispan_binary_based;DB_CLOSE_DELAY=-1")
.username("sa")
.driverClass("org.h2.Driver");
The highlighted addLoader method does not accept any class param and i am trying to work my way through the available methods and it's going no where.
My configuration looks like this and it does not work.
JdbcStringBasedCacheStore cacheStore = new JdbcStringBasedCacheStore();
JdbcStringBasedCacheStoreConfig cacheStoreConfig = (JdbcStringBasedCacheStoreConfig)cacheStore.getCacheStoreConfig();
cacheStoreConfig = new JdbcStringBasedCacheStoreConfig();
cacheStoreConfig.fetchPersistentState(false);
cacheStoreConfig.purgeOnStartup(true);
cacheStoreConfig.ignoreModifications(false);
cacheStoreConfig.setTableNamePrefix("ISPN_STRING_TABLE");
cacheStoreConfig.setIdColumnName("ID_COLUMN");
cacheStoreConfig.setIdColumnType("VARCHAR(500)");
cacheStoreConfig.setDataColumnName("DATA_COLUMN");
cacheStoreConfig.setDataColumnType("BINARY");
cacheStoreConfig.setTimestampColumnName("TIMESTAMP_COLUMN");
cacheStoreConfig.setTimestampColumnType("BIGINT");
cacheStoreConfig.setConnectionFactoryClass("org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory");
cacheStoreConfig.setDatasourceJndiLocation("java:jboss/datasources/ExampleDS");
cacheStoreConfig.setDropTableOnExit(false);
cacheStoreConfig.setCreateTableOnStart(true);
ConnectionFactoryConfig connFactoryConfig = cacheStoreConfig.getConnectionFactoryConfig();
connFactoryConfig.setConnectionFactoryClass("org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory");
connFactoryConfig.setDatasourceJndiLocation("java:jboss/datasources/ExampleDS");
connFactoryConfig.setDriverClass("org.h2.Driver");
connFactoryConfig.setUserName("sa");
connFactoryConfig.setPassword("sa");
new ConfigurationBuilder()
.loaders().addCacheLoader().cacheLoader(cacheStore)
.eviction()
.strategy(EvictionStrategy.LRU).maxEntries(5000000)
.eviction().expiration().lifespan(120000l)
.indexing().enable().indexLocalOnly(true)
.withProperties(properties).build();
Looks the the jdbcStringBasedCacheStore looks into its property called "config" for the configuration and i see no way of setting it. The above configuration throws a IllegalArgumentException with connectionFactoryClass being null in the configuration property.
Let me know, what is the right way of doing this and why is that documentation not correct?
Jithendra