Class CacheJdbcBlobStore<K,V>
- java.lang.Object
-
- org.apache.ignite.cache.store.CacheStoreAdapter<K,V>
-
- org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore<K,V>
-
- All Implemented Interfaces:
javax.cache.integration.CacheLoader<K,V>,javax.cache.integration.CacheWriter<K,V>,CacheStore<K,V>
public class CacheJdbcBlobStore<K,V> extends CacheStoreAdapter<K,V>
CacheStoreimplementation backed by JDBC. This implementation stores objects in underlying database inBLOBformat.Store will create table
ENTRIESin the database to store data. Table will havekeyandvalfields.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.
Configuration
Sections below describe mandatory and optional configuration settings as well as providing example using Java and Spring XML.Mandatory
There are no mandatory configuration parameters.Optional
- Data source (see
setDataSource(DataSource) - Connection URL (see
setConnectionUrl(String)) - User name (see
setUser(String)) - Password (see
setPassword(String)) - Create table query (see
setConnectionUrl(String)) - Load entry query (see
setLoadQuery(String)) - Update entry query (see
setUpdateQuery(String)) - Insert entry query (see
setInsertQuery(String)) - Delete entry query (see
setDeleteQuery(String))
Use
CacheJdbcBlobStoreFactoryfactory to passCacheJdbcBlobStoretoCacheConfiguration.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDFLT_CONN_URLDefault connection URL (value is jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1).static StringDFLT_CREATE_TBL_QRYDefault create table query (value is create table if not exists ENTRIES (akey binary primary key, val binary)).static StringDFLT_DEL_QRYDefault delete entry query (value is delete from ENTRIES where akey=?static StringDFLT_INSERT_QRYDefault insert entry query (value is insert into ENTRIES (akey, val) values (?static StringDFLT_LOAD_QRYDefault load entry query (value is select * from ENTRIES where akey=?static StringDFLT_UPDATE_QRYDefault update entry query (value is select * from ENTRIES where akey=?
-
Constructor Summary
Constructors Constructor Description CacheJdbcBlobStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete(Object key)protected <X> XfromBytes(byte[] bytes)Deserialize object from byte array using marshaller.Vload(K key)protected CacheStoreSessionsession()voidsessionEnd(boolean commit)Default empty implementation for ending transactions.voidsetConnectionUrl(String connUrl)Sets connection URL.voidsetCreateTableQuery(String createTblQry)Sets create table query.voidsetDataSource(DataSource dataSrc)Sets data source.voidsetDeleteQuery(String delQry)Sets delete entry query.voidsetInitSchema(boolean initSchema)Flag indicating whether DB schema should be initialized by Ignite (default behaviour) or was explicitly created by user.voidsetInsertQuery(String insertQry)Sets insert entry query.voidsetLoadQuery(String loadQry)Sets load query.voidsetPassword(String passwd)Sets password for database access.voidsetUpdateQuery(String updateQry)Sets update entry query.voidsetUser(String user)Sets user name for database access.protected byte[]toBytes(Object obj)Serialize object to byte array using marshaller.StringtoString()voidwrite(javax.cache.Cache.Entry<? extends K,? extends V> entry)-
Methods inherited from class org.apache.ignite.cache.store.CacheStoreAdapter
deleteAll, loadAll, loadCache, writeAll
-
-
-
-
Field Detail
-
DFLT_CONN_URL
public static final String DFLT_CONN_URL
Default connection URL (value is jdbc:h2:mem:jdbcCacheStore;DB_CLOSE_DELAY=-1).- See Also:
- Constant Field Values
-
DFLT_CREATE_TBL_QRY
public static final String DFLT_CREATE_TBL_QRY
Default create table query (value is create table if not exists ENTRIES (akey binary primary key, val binary)).- See Also:
- Constant Field Values
-
DFLT_LOAD_QRY
public static final String DFLT_LOAD_QRY
Default load entry query (value is select * from ENTRIES where akey=?).- See Also:
- Constant Field Values
-
DFLT_UPDATE_QRY
public static final String DFLT_UPDATE_QRY
Default update entry query (value is select * from ENTRIES where akey=?).- See Also:
- Constant Field Values
-
DFLT_INSERT_QRY
public static final String DFLT_INSERT_QRY
Default insert entry query (value is insert into ENTRIES (akey, val) values (?, ?)).- See Also:
- Constant Field Values
-
DFLT_DEL_QRY
public static final String DFLT_DEL_QRY
Default delete entry query (value is delete from ENTRIES where akey=?).- See Also:
- Constant Field Values
-
-
Method Detail
-
sessionEnd
public void sessionEnd(boolean commit)
Default empty implementation for ending transactions. Note that if explicit cache transactions are not used, then transactions do not have to be explicitly ended - for all other cases this method should be overridden with custom commit/rollback logic.- Specified by:
sessionEndin interfaceCacheStore<K,V>- Overrides:
sessionEndin classCacheStoreAdapter<K,V>- Parameters:
commit-Trueif transaction should commit,falsefor rollback.
-
delete
public void delete(Object key)
-
setInitSchema
public void setInitSchema(boolean initSchema)
Flag indicating whether DB schema should be initialized by Ignite (default behaviour) or was explicitly created by user.- Parameters:
initSchema-Trueif DB schema should be initialized by Ignite (default behaviour), {code @false} if schema was explicitly created by user.
-
setConnectionUrl
public void setConnectionUrl(String connUrl)
Sets connection URL.- Parameters:
connUrl- Connection URL.
-
setCreateTableQuery
public void setCreateTableQuery(String createTblQry)
Sets create table query.- Parameters:
createTblQry- Create table query.
-
setLoadQuery
public void setLoadQuery(String loadQry)
Sets load query.- Parameters:
loadQry- Load query
-
setUpdateQuery
public void setUpdateQuery(String updateQry)
Sets update entry query.- Parameters:
updateQry- Update entry query.
-
setInsertQuery
public void setInsertQuery(String insertQry)
Sets insert entry query.- Parameters:
insertQry- Insert entry query.
-
setDeleteQuery
public void setDeleteQuery(String delQry)
Sets delete entry query.- Parameters:
delQry- Delete entry query.
-
setUser
public void setUser(String user)
Sets user name for database access.- Parameters:
user- User name.
-
setPassword
public void setPassword(String passwd)
Sets password for database access.- Parameters:
passwd- Password.
-
setDataSource
public void setDataSource(DataSource dataSrc)
Sets data source. Data source should be fully configured and ready-to-use.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,userandpasswordparameters will be used).- Parameters:
dataSrc- Data source.
-
toString
public String toString()
- Overrides:
toStringin classCacheStoreAdapter<K,V>
-
toBytes
protected byte[] toBytes(Object obj) throws IgniteCheckedException
Serialize object to byte array using marshaller.- Parameters:
obj- Object to convert to byte array.- Returns:
- Byte array.
- Throws:
IgniteCheckedException- If failed to convert.
-
fromBytes
protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedExceptionDeserialize object from byte array using marshaller.- Type Parameters:
X- Result object type.- Parameters:
bytes- Bytes to deserialize.- Returns:
- Deserialized object.
- Throws:
IgniteCheckedException- If failed.
-
session
protected CacheStoreSession session()
- Returns:
- Store session.
-
-