Reputation: 165
Is there any way to persist cached objects in infinispan Cached store to a relational database Table?Iwas trying to do it as a Cacheloader.
<loader class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" fetchPersistentState="true" ignoreModifications="false" purgeOnStartup="false">
<properties>
<property name="stringsTableNamePrefix" value="ISPN_STRING_TABLE"/>
<property name="idColumnName" value="ID_COLUMN"/>
<property name="dataColumnName" value="DATA_COLUMN"/>
<property name="timestampColumnName" value="TIMESTAMP_COLUMN"/>
<property name="timestampColumnType" value="BIGINT"/>
<property name="connectionFactoryClass" value="org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory"/>
<property name="connectionUrl" value="jdbc:derby://localhost:1527/DB;create=true"/>
<property name="userName" value="user"/>
<property name="password" value="password"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="idColumnType" value="VARCHAR(255)"/>
<property name="dataColumnType" value="BLOB"/>
<property name="dropTableOnExit" value="false"/>
<property name="createTableOnStart" value="true"/>
</properties>
</loader>
From This keys and values are store in ISPN_STRING_TABLE_TEST_STORE where <
namedCache name="TEST_STORE">. it saves keys in ID column and Values in DATA_COLUMN as a Blob.I want to Put this Blob Contain data into a relational database(Not as Object).As a example when I put a Employee object in Cache it should put database table as a Employee table with emplyee properties as a fields in That table.(Emp Name,Age.. etc).Is there a way to Do this?
Upvotes: 2
Views: 4465
Reputation: 3402
Things seem to have changed. This seems to work with Infinispan 5.2 and 5.3.
<loaders [...]>
<stringKeyedJdbcStore
xmlns="urn:infinispan:config:jdbc:5.2"
fetchPersistentState="false"
ignoreModifications="false"
purgeOnStartup="false">
<dataSource jndiUrl="java:jboss/datasources/MySQLDS" />
<!--
<connectionPool connectionUrl="jdbc:mysql://[host][:port]/[database]"
username="xxxx"
password="xxxx"
driverClass="com.mysql.jdbc.Driver"/>
-->
<stringKeyedTable dropOnExit="true"
createOnStart="true"
prefix="ISPN_STRING_TABLE">
<idColumn name="ID_COLUMN" type="VARCHAR(255)" />
<dataColumn name="DATA_COLUMN" type="BINARY" />
<timestampColumn name="TIMESTAMP_COLUMN" type="BIGINT" />
</stringKeyedTable>
</stringKeyedJdbcStore>
</loaders>
Uses xmlns urn:infinispan:config:jdbc:5.2
(schemaLocation at link)
Upvotes: 2
Reputation: 4328
There's an example in Infinispan Data Grid Platform Book which describes how to configure a JdbcStringBasedCacheStore using MySQL as relational database. In this example a Data source is used in the Connection URL, however it shouldn't be difficult to adapt it to your needs.Hope it helps.
Regards
<loaders>
<loader
class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore"
fetchPersistentState="true" ignoreModifications="false"
purgeOnStartup="false">
<properties>
<property name="stringsTableNamePrefix" value="ISPN_STRING_TABLE" />
<property name="idColumnName" value="ID_COLUMN" />
<property name="idColumnType" value="VARCHAR(255)" />
<property name="dataColumnName" value="DATA_COLUMN" />
<property name="dataColumnType" value="TRUE" />
<property name="timestampColumnName" value="TIMESTAMP_COLUMN" />
<property name="timestampColumnType" value="BIGINT" />
<property name="connectionFactoryClass"
value="org.infinispan.loaders.jdbc.
connectionfactory.PooledConnectionFactory" />
<property name="connectionUrl" value="java:jboss/datasources/MySQLDS" />
<property name="userName" value="xxxx" />
<property name="password" value="xxxx" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="dropTableOnExit" value="true" />
<property name="createTableOnStart" value="true" />
</properties>
</loader>
</loaders>
Upvotes: 3