public class GridCacheJdbcBlobStore<K,V> extends GridCacheStoreAdapter<K,V>
GridCacheStore implementation backed by JDBC. This implementation
stores objects in underlying database in BLOB format.
Store will create table ENTRIES in the database to store data.
Table will have key and val fields.
If custom DDL and DML statements are provided, table and field names have to be consistent for all statements and sequence of parameters have to be preserved.
setDataSource(DataSource)setConnectionUrl(String))setUser(String))setPassword(String))setConnectionUrl(String))setLoadQuery(String))setUpdateQuery(String))setInsertQuery(String))setDeleteQuery(String))
...
GridCacheJdbcBlobStore<String, String> store = new GridCacheJdbcBlobStore<String, String>();
...
...
<bean id="cache.jdbc.store"
class="org.gridgain.grid.cache.store.jdbc.GridCacheJdbcBlobStore">
<property name="connectionUrl" value="jdbc:h2:mem:"/>
<property name="createTableQuery"
value="create table if not exists ENTRIES (key other, val other)"/>
</bean>
...
For information about Spring framework visit www.springframework.org
| Modifier and Type | Field and Description |
|---|---|
static String |
DFLT_CONN_URL
Default connection URL (value is jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1).
|
static String |
DFLT_CREATE_TBL_QRY
Default create table query
(value is create table if not exists ENTRIES (key other primary key, val other)).
|
static String |
DFLT_DEL_QRY
Default delete entry query (value is delete from ENTRIES where key=?).
|
static String |
DFLT_INSERT_QRY
Default insert entry query (value is insert into ENTRIES (key, val) values (?, ?)).
|
static String |
DFLT_LOAD_QRY
Default load entry query (value is select * from ENTRIES where key=?).
|
static String |
DFLT_UPDATE_QRY
Default update entry query (value is select * from ENTRIES where key=?).
|
| Constructor and Description |
|---|
GridCacheJdbcBlobStore() |
| Modifier and Type | Method and Description |
|---|---|
protected <X> X |
fromBytes(byte[] bytes)
Deserialize object from byte array using marshaller.
|
V |
load(GridCacheTx tx,
K key)
Loads value for the key from underlying persistent storage.
|
void |
put(GridCacheTx tx,
K key,
V val)
Stores a given value in persistent storage.
|
void |
remove(GridCacheTx tx,
K key)
Removes the value identified by given key from persistent storage.
|
void |
setConnectionUrl(String connUrl)
Sets connection URL.
|
void |
setCreateTableQuery(String createTblQry)
Sets create table query.
|
void |
setDataSource(DataSource dataSrc)
Sets data source.
|
void |
setDeleteQuery(String delQry)
Sets delete entry query.
|
void |
setInsertQuery(String insertQry)
Sets insert entry query.
|
void |
setLoadQuery(String loadQry)
Sets load query.
|
void |
setPassword(String passwd)
Sets password for database access.
|
void |
setUpdateQuery(String updateQry)
Sets update entry query.
|
void |
setUser(String user)
Sets user name for database access.
|
protected byte[] |
toBytes(Object obj)
Serialize object to byte array using marshaller.
|
String |
toString() |
void |
txEnd(GridCacheTx tx,
boolean commit)
Default empty implementation for ending transactions.
|
loadAll, loadCache, putAll, removeAllpublic static final String DFLT_CONN_URL
public static final String DFLT_CREATE_TBL_QRY
public static final String DFLT_LOAD_QRY
public static final String DFLT_UPDATE_QRY
public static final String DFLT_INSERT_QRY
public static final String DFLT_DEL_QRY
public void txEnd(GridCacheTx tx, boolean commit) throws GridException
txEnd in interface GridCacheStore<K,V>txEnd in class GridCacheStoreAdapter<K,V>tx - Cache transaction being ended.commit - True if transaction should commit, false for rollback.GridException - If commit or rollback failed. Note that commit failure in some cases
may bring cache transaction into GridCacheTxState.UNKNOWN which will
consequently cause all transacted entries to be invalidated.public V load(@Nullable GridCacheTx tx, K key) throws GridException
tx - Cache transaction.key - Key to load.null if value was not found.GridException - If load failed.public void put(@Nullable GridCacheTx tx, K key, V val) throws GridException
null.tx - Cache transaction, if write-behind is not enabled, null otherwise.key - Key to put.val - Value to put.GridException - If put failed.public void remove(@Nullable GridCacheTx tx, K key) throws GridException
null.tx - Cache transaction, if write-behind is not enabled, null otherwise.key - Key to remove.GridException - If remove failed.public void setConnectionUrl(String connUrl)
connUrl - Connection URL.public void setCreateTableQuery(String createTblQry)
createTblQry - Create table query.public void setLoadQuery(String loadQry)
loadQry - Load querypublic void setUpdateQuery(String updateQry)
updateQry - Update entry query.public void setInsertQuery(String insertQry)
insertQry - Insert entry query.public void setDeleteQuery(String delQry)
delQry - Delete entry query.public void setUser(String user)
user - User name.public void setPassword(String passwd)
passwd - Password.public void setDataSource(DataSource dataSrc)
Note that if data source is provided, all connections will be
acquired via this data source. If data source is not provided, a new connection
will be created for each store call (connectionUrl,
user and password parameters will be used).
dataSrc - Data source.protected byte[] toBytes(Object obj) throws GridException
obj - Object to convert to byte array.GridException - If failed to convert.protected <X> X fromBytes(byte[] bytes)
throws GridException
X - Result object type.bytes - Bytes to deserialize.GridException - If failed.Copyright © 2014. All rights reserved.