Class JdbcCacheStore<K,V>

java.lang.Object
org.gridgain.cache.store.jdbc.JdbcCacheStore<K,V>
All Implemented Interfaces:
org.apache.ignite.cache.CacheStore<K,V>
Direct Known Subclasses:
JdbcPojoCacheStore, JdbcTupleCacheStore

public abstract class JdbcCacheStore<K,V> extends Object implements org.apache.ignite.cache.CacheStore<K,V>
JDBC based cache store.
  • Field Details

    • dialect

      protected JdbcDialect dialect
      Database dialect.
  • Constructor Details

    • JdbcCacheStore

      public JdbcCacheStore()
  • Method Details

    • beginSession

      public org.apache.ignite.cache.CacheStoreSession beginSession()
      Specified by:
      beginSession in interface org.apache.ignite.cache.CacheStore<K,V>
    • extractParameter

      @Nullable protected abstract @Nullable Object extractParameter(String typeName, JdbcCacheStore.TypeKind typeKind, String fieldName, Object obj) throws org.apache.ignite.lang.IgniteException
      Get field value from object for use as query parameter.
      Parameters:
      typeName - Type name.
      typeKind - Type kind.
      fieldName - Field name.
      obj - Cache object.
      Returns:
      Field value from object.
      Throws:
      org.apache.ignite.lang.IgniteException - in case of error.
    • buildObject

      protected abstract <R> R buildObject(String typeName, JdbcCacheStore.TypeKind typeKind, JdbcTypeField[] fields, Map<String,Integer> loadColIndexes, ResultSet rs) throws org.apache.ignite.lang.IgniteException
      Construct object from query result.
      Type Parameters:
      R - Type of result object.
      Parameters:
      typeName - Type name.
      typeKind - Type kind.
      fields - Fields descriptors.
      loadColIndexes - Select query columns index.
      rs - ResultSet.
      Returns:
      Constructed object.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to construct cache object.
    • prepareBuilders

      protected abstract void prepareBuilders(JdbcType type) throws org.apache.ignite.lang.IgniteException
      Prepare internal store specific builders for provided types metadata.
      Parameters:
      type - The type.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to prepare internal builders for types.
    • kindForName

      protected abstract JdbcCacheStore.TypeKind kindForName(String type)
      Get type kind.
      Parameters:
      type - Type name to check.
      Returns:
      True if class not found.
    • columnIndex

      protected static Integer columnIndex(Map<String,Integer> loadColIdxs, String dbName)
      Find column index by database name.
      Parameters:
      loadColIdxs - Select query columns indexes.
      dbName - Column name in database.
      Returns:
      Column index.
      Throws:
      IllegalStateException - if column not found.
    • loadCacheAsync

      public CompletableFuture<Void> loadCacheAsync(BiConsumer<K,V> clo, @Nullable @Nullable Object... args)
      Specified by:
      loadCacheAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • loadAsync

      public CompletableFuture<V> loadAsync(K key)
      Specified by:
      loadAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • loadAllAsync

      public CompletableFuture<Map<K,V>> loadAllAsync(Iterable<? extends K> keys)
      Specified by:
      loadAllAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • writeAsync

      public CompletableFuture<Void> writeAsync(org.apache.ignite.cache.CacheStoreSession session, Map.Entry<? extends K,? extends V> entry)
      Specified by:
      writeAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • writeAllAsync

      public CompletableFuture<Void> writeAllAsync(org.apache.ignite.cache.CacheStoreSession session, Collection<Map.Entry<? extends K,? extends V>> entries)
      Specified by:
      writeAllAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • deleteAsync

      public CompletableFuture<Void> deleteAsync(org.apache.ignite.cache.CacheStoreSession session, K key)
      Specified by:
      deleteAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • deleteAllAsync

      public CompletableFuture<Void> deleteAllAsync(org.apache.ignite.cache.CacheStoreSession session, Collection<? extends K> keys)
      Specified by:
      deleteAllAsync in interface org.apache.ignite.cache.CacheStore<K,V>
    • fillParameter

      protected static void fillParameter(PreparedStatement stmt, int idx, JdbcTypeField field, @Nullable @Nullable Object fieldVal)
      Sets the value of the designated parameter using the given object.
      Parameters:
      stmt - Prepare statement.
      idx - Index for parameters.
      field - Field descriptor.
      fieldVal - Field value.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to set statement parameter.
    • fillKeyParameters

      protected int fillKeyParameters(PreparedStatement stmt, int idx, JdbcCacheStore.EntryMapping em, Object key) throws org.apache.ignite.lang.IgniteException
      Fill key parameters.
      Parameters:
      stmt - Prepare statement.
      idx - Start index for parameters.
      em - Entry mapping.
      key - Key object.
      Returns:
      Next index for parameters.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to set statement parameters.
    • fillKeyParameters

      protected int fillKeyParameters(PreparedStatement stmt, JdbcCacheStore.EntryMapping m, Object key) throws org.apache.ignite.lang.IgniteException
      Fill key parameters.
      Parameters:
      stmt - Prepare statement.
      m - Type mapping description.
      key - Key object.
      Returns:
      Next index for parameters.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to set statement parameters.
    • fillValueParameters

      protected int fillValueParameters(PreparedStatement stmt, int idx, JdbcCacheStore.EntryMapping em, Object val) throws org.apache.ignite.lang.IgniteException
      Fill value parameters.
      Parameters:
      stmt - Prepare statement.
      idx - Start index for parameters.
      em - Type mapping description.
      val - Value object.
      Returns:
      Next index for parameters.
      Throws:
      org.apache.ignite.lang.IgniteException - If failed to set statement parameters.
    • getDataSource

      public DataSource getDataSource()
      Get data source.
      Returns:
      Data source.
    • setDataSource

      public void setDataSource(DataSource dataSrc)
      Set data source.
      Parameters:
      dataSrc - Data source.
    • getDialect

      public JdbcDialect getDialect()
      Get database dialect.
      Returns:
      Database dialect.
    • setDialect

      public void setDialect(JdbcDialect dialect)
      Set database dialect.
      Parameters:
      dialect - Database dialect.
    • getMaximumWriteAttempts

      public int getMaximumWriteAttempts()
      Gets maximum number of write attempts in case of database error.
      Returns:
      Maximum number of write attempts.
    • setMaximumWriteAttempts

      public void setMaximumWriteAttempts(int maxWrtAttempts)
      Sets maximum number of write attempts in case of database error.
      Parameters:
      maxWrtAttempts - Number of write attempts.
    • getType

      public JdbcType getType()
      Gets types known by store.
      Returns:
      Types known by store.
    • setType

      public void setType(JdbcType type)
      Sets store configurations.
      Parameters:
      type - The type.
    • getTransformer

      public JdbcTypesTransformer getTransformer()
      Gets types transformer.
      Returns:
      Types transformer.
    • setTransformer

      public void setTransformer(JdbcTypesTransformer transformer)
      Sets types transformer.
      Parameters:
      transformer - Types transformer.
    • getBatchSize

      public int getBatchSize()
      Get maximum batch size for delete and delete operations.
      Returns:
      Maximum batch size.
    • setBatchSize

      public void setBatchSize(int batchSize)
      Set maximum batch size for write and delete operations.
      Parameters:
      batchSize - Maximum batch size.
    • getParallelLoadCacheMinimumThreshold

      public int getParallelLoadCacheMinimumThreshold()
      Parallel load cache minimum row count threshold.
      Returns:
      If 0 then load sequentially.
    • setParallelLoadCacheMinimumThreshold

      public void setParallelLoadCacheMinimumThreshold(int parallelLoadCacheMinThreshold)
      Parallel load cache minimum row count threshold.
      Parameters:
      parallelLoadCacheMinThreshold - Minimum row count threshold. If 0 then load sequentially.
    • getExecutor

      public ExecutorService getExecutor()
      Get the executor for database access.
      Returns:
      The executor.
    • setExecutor

      public void setExecutor(ExecutorService executor)
      Set the executor for database access.
      Parameters:
      executor - The executor instance.
    • isSqlEscapeAll

      public boolean isSqlEscapeAll()
      If true all the SQL table and field names will be escaped with double quotes like ("tableName"."fieldsName"). This enforces case sensitivity for field names and also allows having special characters in table and field names.
      Returns:
      Flag value.
    • setSqlEscapeAll

      public void setSqlEscapeAll(boolean sqlEscapeAll)
      If true all the SQL table and field names will be escaped with double quotes like ("tableName"."fieldsName"). This enforces case sensitivity for field names and also allows having special characters in table and field names.
      Parameters:
      sqlEscapeAll - Flag value.