org.apache.ignite.cache.store.jdbc

## 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>

  `CacheStore` 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.

  ## 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 `CacheJdbcBlobStoreFactory` factory to pass `CacheJdbcBlobStore` to `CacheConfiguration`.

- - ### Field Summary

    Fields
    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 (akey binary primary key, val binary)`).
    `static String` | `DFLT_DEL_QRY` Default delete entry query (value is `delete from ENTRIES where akey=?`
    `static String` | `DFLT_INSERT_QRY` Default insert entry query (value is `insert into ENTRIES (akey, val) values (?`
    `static String` | `DFLT_LOAD_QRY` Default load entry query (value is `select * from ENTRIES where akey=?`
    `static String` | `DFLT_UPDATE_QRY` Default update entry query (value is `select * from ENTRIES where akey=?`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CacheJdbcBlobStore()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `delete(Object key)`
    `protected <X> X` | `fromBytes(byte[] bytes)` Deserialize object from byte array using marshaller.
    `V` | `load(K key)`
    `protected CacheStoreSession` | `session()`
    `void` | `sessionEnd(boolean commit)` Default empty implementation for ending transactions.
    `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` | `setInitSchema(boolean initSchema)` Flag indicating whether DB schema should be initialized by Ignite (default behaviour) or was explicitly created by user.
    `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` | `write(javax.cache.Cache.Entry<? extends K,? extends V> entry)`

    - ### Methods inherited from class org.apache.ignite.cache.store.CacheStoreAdapter

      `deleteAll, loadAll, loadCache, writeAll`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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

  - ### Constructor Detail

    - #### CacheJdbcBlobStore

          public CacheJdbcBlobStore()

  - ### 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:
        `sessionEnd` in interface `CacheStore<K,V>`
      Overrides:
        `sessionEnd` in class `CacheStoreAdapter<K,V>`
      Parameters:
        `commit` - `True` if transaction should commit, `false` for rollback.

    - #### load

          public V load(K key)

    - #### write

          public void write(javax.cache.Cache.Entry<? extends K,? extends V> entry)

    - #### 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` - `True` if 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`, `user` and `password` parameters will be used).

      Parameters:
        `dataSrc` - Data source.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `CacheStoreAdapter<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 IgniteCheckedException

      Deserialize 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.

2022 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022