Class CacheAbstractJdbcStore<K,V>
- java.lang.Object
- 
- org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore<K,V>
 
- 
- All Implemented Interfaces:
- javax.cache.integration.CacheLoader<K,V>,- javax.cache.integration.CacheWriter<K,V>,- CacheStore<K,V>,- LifecycleAware
 - Direct Known Subclasses:
- CacheJdbcPojoStore
 
 public abstract class CacheAbstractJdbcStore<K,V> extends Object implements CacheStore<K,V>, LifecycleAware Implementation ofCacheStorebacked by JDBC.Store works with database via SQL dialect. Ignite ships with dialects for most popular databases: - DB2Dialect- dialect for IBM DB2 database.
- OracleDialect- dialect for Oracle database.
- SQLServerDialect- dialect for Microsoft SQL Server database.
- MySQLDialect- dialect for Oracle MySQL database.
- H2Dialect- dialect for H2 database.
- BasicJdbcDialect- dialect for any database via plain JDBC.
 Configuration- Data source (see setDataSource(DataSource)
- Dialect (see setDialect(JdbcDialect)
- Maximum batch size for writeAll and deleteAll operations. (see setBatchSize(int))
- Max workers thread count. These threads are responsible for load cache. (see setMaximumPoolSize(int))
- Parallel load cache minimum threshold. (see setParallelLoadCacheMinimumThreshold(int))
 Java Example... // Create store factory. CacheJdbcPojoStoreFactory storeFactory = new CacheJdbcPojoStoreFactory(); storeFactory.setDataSourceBean("your_data_source_name"); storeFactory.setDialect(new H2Dialect()); storeFactory.setTypes(array_with_your_types); ... ccfg.setCacheStoreFactory(storeFactory); ccfg.setReadThrough(true); ccfg.setWriteThrough(true); cfg.setCacheConfiguration(ccfg); ...
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected static classCacheAbstractJdbcStore.EntryMappingEntry mapping description.protected static classCacheAbstractJdbcStore.TypeKindType kind.
 - 
Field SummaryFields Modifier and Type Field Description protected static StringATTR_CONN_PROPConnection attribute property name.protected static Collection<String>BUILT_IN_TYPESBuilt in Java types names.protected Map<String,Map<Object,CacheAbstractJdbcStore.EntryMapping>>cacheMappingsCache with entry mapping description.protected DataSourcedataSrcData source.protected JdbcDialectdialectDatabase dialect.protected JdbcTypeHasherhasherHash calculator.protected IgniteigniteAuto injected ignite instance.protected IgniteLoggerlogAuto-injected logger instance.protected JdbcTypesTransformertransformerTypes transformer.
 - 
Constructor SummaryConstructors Constructor Description CacheAbstractJdbcStore()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract <R> RbuildObject(@Nullable String cacheName, String typeName, CacheAbstractJdbcStore.TypeKind typeKind, JdbcTypeField[] flds, Map<String,Integer> loadColIdxs, ResultSet rs)Construct object from query result.protected voidcloseConnection(@Nullable Connection conn)Closes connection.protected IntegercolumnIndex(Map<String,Integer> loadColIdxs, String dbName)Find column index by database name.protected Connectionconnection()voiddelete(Object key)voiddeleteAll(Collection<?> keys)protected voidend(@Nullable Connection conn, @Nullable Statement st)Closes allocated resources depending on transaction status.protected abstract @Nullable ObjectextractParameter(@Nullable String cacheName, String typeName, CacheAbstractJdbcStore.TypeKind typeKind, String fieldName, Object obj)Get field value from object for use as query parameter.protected intfillKeyParameters(PreparedStatement stmt, int idx, CacheAbstractJdbcStore.EntryMapping em, Object key)protected intfillKeyParameters(PreparedStatement stmt, CacheAbstractJdbcStore.EntryMapping m, Object key)protected voidfillParameter(PreparedStatement stmt, int idx, JdbcTypeField field, @Nullable Object fieldVal)Sets the value of the designated parameter using the given object.protected intfillValueParameters(PreparedStatement stmt, int idx, CacheAbstractJdbcStore.EntryMapping em, Object val)intgetBatchSize()Get maximum batch size for delete and delete operations.DataSourcegetDataSource()JdbcDialectgetDialect()Get database dialect.JdbcTypeHashergetHasher()Gets hash code calculator.intgetMaximumPoolSize()Get Max workers thread count.intgetMaximumWriteAttempts()Gets maximum number of write attempts in case of database error.intgetParallelLoadCacheMinimumThreshold()Parallel load cache minimum row count threshold.JdbcTypesTransformergetTransformer()Gets types transformer.JdbcType[]getTypes()Gets types known by store.protected Igniteignite()booleanisSqlEscapeAll()Iftrueall the SQL table and field names will be escaped with double quotes like ("tableName"."fieldsName").protected CacheAbstractJdbcStore.TypeKindkindForName(String type)protected CacheAbstractJdbcStore.TypeKindkindForName(String type, boolean binarySupported)Vload(K key)Map<K,V>loadAll(Iterable<? extends K> keys)voidloadCache(IgniteBiInClosure<K,V> clo, @Nullable Object... args)Loads all values from underlying persistent storage.protected ConnectionopenConnection(boolean autocommit)Gets connection from a pool.protected abstract voidprepareBuilders(@Nullable String cacheName, Collection<JdbcType> types)Prepare internal store specific builders for provided types metadata.protected JdbcDialectresolveDialect()Perform dialect resolution.protected CacheStoreSessionsession()voidsessionEnd(boolean commit)Tells store to commit or rollback a transaction depending on the value of the'commit'parameter.voidsetBatchSize(int batchSize)Set maximum batch size for write and delete operations.voidsetDataSource(DataSource dataSrc)voidsetDialect(JdbcDialect dialect)Set database dialect.voidsetHasher(JdbcTypeHasher hasher)Sets hash code calculator.voidsetMaximumPoolSize(int maxPoolSize)Set Max workers thread count.voidsetMaximumWriteAttempts(int maxWrtAttempts)Sets maximum number of write attempts in case of database error.voidsetParallelLoadCacheMinimumThreshold(int parallelLoadCacheMinThreshold)Parallel load cache minimum row count threshold.voidsetSqlEscapeAll(boolean sqlEscapeAll)Iftrueall the SQL table and field names will be escaped with double quotes like ("tableName"."fieldsName").voidsetTransformer(JdbcTypesTransformer transformer)Sets types transformer.voidsetTypes(JdbcType... types)Sets store configurations.voidstart()Starts grid component, called on grid start.voidstop()Stops grid component, called on grid shutdown.protected abstract ObjecttypeIdForObject(Object obj)Calculate type ID for object.protected abstract ObjecttypeIdForTypeName(CacheAbstractJdbcStore.TypeKind kind, String typeName)Calculate type ID for given type name.voidwrite(javax.cache.Cache.Entry<? extends K,? extends V> entry)voidwriteAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries)
 
- 
- 
- 
Field Detail- 
ATTR_CONN_PROPprotected static final String ATTR_CONN_PROP Connection attribute property name.- See Also:
- Constant Field Values
 
 - 
BUILT_IN_TYPESprotected static final Collection<String> BUILT_IN_TYPES Built in Java types names.
 - 
ignite@IgniteInstanceResource protected Ignite ignite Auto injected ignite instance.
 - 
log@LoggerResource protected IgniteLogger log Auto-injected logger instance.
 - 
dataSrcprotected volatile DataSource dataSrc Data source.
 - 
cacheMappingsprotected volatile Map<String,Map<Object,CacheAbstractJdbcStore.EntryMapping>> cacheMappings Cache with entry mapping description. (cache name, (key id, mapping description)).
 - 
dialectprotected JdbcDialect dialect Database dialect.
 - 
hasherprotected JdbcTypeHasher hasher Hash calculator.
 - 
transformerprotected JdbcTypesTransformer transformer Types transformer.
 
- 
 - 
Method Detail- 
extractParameter@Nullable protected abstract @Nullable Object extractParameter(@Nullable @Nullable String cacheName, String typeName, CacheAbstractJdbcStore.TypeKind typeKind, String fieldName, Object obj) throws javax.cache.CacheException Get field value from object for use as query parameter.- Parameters:
- cacheName- Cache name.
- typeName- Type name.
- typeKind- Type kind.
- fieldName- Field name.
- obj- Cache object.
- Returns:
- Field value from object.
- Throws:
- javax.cache.CacheException- in case of error.
 
 - 
buildObjectprotected abstract <R> R buildObject(@Nullable @Nullable String cacheName, String typeName, CacheAbstractJdbcStore.TypeKind typeKind, JdbcTypeField[] flds, Map<String,Integer> loadColIdxs, ResultSet rs) throws javax.cache.integration.CacheLoaderExceptionConstruct object from query result.- Type Parameters:
- R- Type of result object.
- Parameters:
- cacheName- Cache name.
- typeName- Type name.
- typeKind- Type kind.
- flds- Fields descriptors.
- loadColIdxs- Select query columns index.
- rs- ResultSet.
- Returns:
- Constructed object.
- Throws:
- javax.cache.integration.CacheLoaderException- If failed to construct cache object.
 
 - 
typeIdForObjectprotected abstract Object typeIdForObject(Object obj) throws javax.cache.CacheException Calculate type ID for object.- Parameters:
- obj- Object to calculate type ID for.
- Returns:
- Type ID.
- Throws:
- javax.cache.CacheException- If failed to calculate type ID for given object.
 
 - 
typeIdForTypeNameprotected abstract Object typeIdForTypeName(CacheAbstractJdbcStore.TypeKind kind, String typeName) throws javax.cache.CacheException Calculate type ID for given type name.- Parameters:
- kind- If- truethen calculate type ID for POJO otherwise for binary object .
- typeName- String description of type name.
- Returns:
- Type ID.
- Throws:
- javax.cache.CacheException- If failed to get type ID for given type name.
 
 - 
prepareBuildersprotected abstract void prepareBuilders(@Nullable @Nullable String cacheName, Collection<JdbcType> types) throws javax.cache.CacheExceptionPrepare internal store specific builders for provided types metadata.- Parameters:
- cacheName- Cache name to prepare builders for.
- types- Collection of types.
- Throws:
- javax.cache.CacheException- If failed to prepare internal builders for types.
 
 - 
resolveDialectprotected JdbcDialect resolveDialect() throws javax.cache.CacheException Perform dialect resolution.- Returns:
- The resolved dialect.
- Throws:
- javax.cache.CacheException- Indicates problems accessing the metadata.
 
 - 
startpublic void start() throws IgniteExceptionStarts grid component, called on grid start.- Specified by:
- startin interface- LifecycleAware
- Throws:
- IgniteException- If failed.
 
 - 
stoppublic void stop() throws IgniteExceptionStops grid component, called on grid shutdown.- Specified by:
- stopin interface- LifecycleAware
- Throws:
- IgniteException- If failed.
 
 - 
openConnectionprotected Connection openConnection(boolean autocommit) throws SQLException Gets connection from a pool.- Parameters:
- autocommit-- trueIf connection should use autocommit mode.
- Returns:
- Pooled connection.
- Throws:
- SQLException- In case of error.
 
 - 
connectionprotected Connection connection() throws SQLException - Returns:
- Connection.
- Throws:
- SQLException- In case of error.
 
 - 
closeConnectionprotected void closeConnection(@Nullable @Nullable Connection conn)Closes connection.- Parameters:
- conn- Connection to close.
 
 - 
endprotected void end(@Nullable @Nullable Connection conn, @Nullable @Nullable Statement st)Closes allocated resources depending on transaction status.- Parameters:
- conn- Allocated connection.
- st- Created statement,
 
 - 
sessionEndpublic void sessionEnd(boolean commit) throws javax.cache.integration.CacheWriterExceptionTells store to commit or rollback a transaction depending on the value of the'commit'parameter.- Specified by:
- sessionEndin interface- CacheStore<K,V>
- Parameters:
- commit-- Trueif transaction should commit,- falsefor rollback.
- Throws:
- javax.cache.integration.CacheWriterException- If commit or rollback failed. Note that commit failure in some cases may bring cache transaction into- TransactionState.UNKNOWNwhich will consequently cause all transacted entries to be invalidated.
 
 - 
kindForNameprotected CacheAbstractJdbcStore.TypeKind kindForName(String type, boolean binarySupported) - Parameters:
- type- Type name to check.
- binarySupported- True if binary marshaller enable.
- Returns:
- Trueif class not found.
 
 - 
kindForNameprotected CacheAbstractJdbcStore.TypeKind kindForName(String type) - Parameters:
- type- Type name to check.
- Returns:
- Trueif class not found.
 
 - 
columnIndexprotected 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.
 
 - 
loadCachepublic void loadCache(IgniteBiInClosure<K,V> clo, @Nullable @Nullable Object... args) throws javax.cache.integration.CacheLoaderException Loads all values from underlying persistent storage. Note that keys are not passed, so it is up to implementation to figure out what to load. This method is called wheneverIgniteCache.loadCache(IgniteBiPredicate, Object...)method is invoked which is usually to preload the cache from persistent storage.This method is optional, and cache implementation does not depend on this method to do anything. Default implementation of this method in CacheStoreAdapterdoes nothing.For every loaded value method IgniteBiInClosure.apply(Object, Object)should be called on the passed in closure. The closure will then make sure that the loaded value is stored in cache.- Specified by:
- loadCachein interface- CacheStore<K,V>
- Parameters:
- clo- Closure for loaded values.
- args- Arguments passes into- IgniteCache.loadCache(IgniteBiPredicate, Object...)method.
- Throws:
- javax.cache.integration.CacheLoaderException- If loading failed.
 
 - 
loadAllpublic Map<K,V> loadAll(Iterable<? extends K> keys) throws javax.cache.integration.CacheLoaderException 
 - 
writepublic void write(javax.cache.Cache.Entry<? extends K,? extends V> entry) throws javax.cache.integration.CacheWriterException 
 - 
writeAllpublic void writeAll(Collection<javax.cache.Cache.Entry<? extends K,? extends V>> entries) throws javax.cache.integration.CacheWriterException 
 - 
deletepublic void delete(Object key) throws javax.cache.integration.CacheWriterException 
 - 
deleteAllpublic void deleteAll(Collection<?> keys) throws javax.cache.integration.CacheWriterException 
 - 
fillParameterprotected void fillParameter(PreparedStatement stmt, int idx, JdbcTypeField field, @Nullable @Nullable Object fieldVal) throws javax.cache.CacheException 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:
- javax.cache.CacheException- If failed to set statement parameter.
 
 - 
fillKeyParametersprotected int fillKeyParameters(PreparedStatement stmt, int idx, CacheAbstractJdbcStore.EntryMapping em, Object key) throws javax.cache.CacheException - Parameters:
- stmt- Prepare statement.
- idx- Start index for parameters.
- em- Entry mapping.
- key- Key object.
- Returns:
- Next index for parameters.
- Throws:
- javax.cache.CacheException- If failed to set statement parameters.
 
 - 
fillKeyParametersprotected int fillKeyParameters(PreparedStatement stmt, CacheAbstractJdbcStore.EntryMapping m, Object key) throws javax.cache.CacheException - Parameters:
- stmt- Prepare statement.
- m- Type mapping description.
- key- Key object.
- Returns:
- Next index for parameters.
- Throws:
- javax.cache.CacheException- If failed to set statement parameters.
 
 - 
fillValueParametersprotected int fillValueParameters(PreparedStatement stmt, int idx, CacheAbstractJdbcStore.EntryMapping em, Object val) throws javax.cache.integration.CacheWriterException - Parameters:
- stmt- Prepare statement.
- idx- Start index for parameters.
- em- Type mapping description.
- val- Value object.
- Returns:
- Next index for parameters.
- Throws:
- javax.cache.CacheException- If failed to set statement parameters.
- javax.cache.integration.CacheWriterException
 
 - 
getDataSourcepublic DataSource getDataSource() - Returns:
- Data source.
 
 - 
setDataSourcepublic void setDataSource(DataSource dataSrc) - Parameters:
- dataSrc- Data source.
 
 - 
getDialectpublic JdbcDialect getDialect() Get database dialect.- Returns:
- Database dialect.
 
 - 
setDialectpublic void setDialect(JdbcDialect dialect) Set database dialect.- Parameters:
- dialect- Database dialect.
 
 - 
getMaximumPoolSizepublic int getMaximumPoolSize() Get Max workers thread count. These threads are responsible for execute query.- Returns:
- Max workers thread count.
 
 - 
setMaximumPoolSizepublic void setMaximumPoolSize(int maxPoolSize) Set Max workers thread count. These threads are responsible for execute query.- Parameters:
- maxPoolSize- Max workers thread count.
 
 - 
getMaximumWriteAttemptspublic int getMaximumWriteAttempts() Gets maximum number of write attempts in case of database error.- Returns:
- Maximum number of write attempts.
 
 - 
setMaximumWriteAttemptspublic void setMaximumWriteAttempts(int maxWrtAttempts) Sets maximum number of write attempts in case of database error.- Parameters:
- maxWrtAttempts- Number of write attempts.
 
 - 
getTypespublic JdbcType[] getTypes() Gets types known by store.- Returns:
- Types known by store.
 
 - 
setTypespublic void setTypes(JdbcType... types) Sets store configurations.- Parameters:
- types- Store should process.
 
 - 
getHasherpublic JdbcTypeHasher getHasher() Gets hash code calculator.- Returns:
- Hash code calculator.
 
 - 
setHasherpublic void setHasher(JdbcTypeHasher hasher) Sets hash code calculator.- Parameters:
- hasher- Hash code calculator.
 
 - 
getTransformerpublic JdbcTypesTransformer getTransformer() Gets types transformer.- Returns:
- Types transformer.
 
 - 
setTransformerpublic void setTransformer(JdbcTypesTransformer transformer) Sets types transformer.- Parameters:
- transformer- Types transformer.
 
 - 
getBatchSizepublic int getBatchSize() Get maximum batch size for delete and delete operations.- Returns:
- Maximum batch size.
 
 - 
setBatchSizepublic void setBatchSize(int batchSize) Set maximum batch size for write and delete operations.- Parameters:
- batchSize- Maximum batch size.
 
 - 
getParallelLoadCacheMinimumThresholdpublic int getParallelLoadCacheMinimumThreshold() Parallel load cache minimum row count threshold.- Returns:
- If 0then load sequentially.
 
 - 
setParallelLoadCacheMinimumThresholdpublic void setParallelLoadCacheMinimumThreshold(int parallelLoadCacheMinThreshold) Parallel load cache minimum row count threshold.- Parameters:
- parallelLoadCacheMinThreshold- Minimum row count threshold. If- 0then load sequentially.
 
 - 
isSqlEscapeAllpublic boolean isSqlEscapeAll() Iftrueall 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.
 
 - 
setSqlEscapeAllpublic void setSqlEscapeAll(boolean sqlEscapeAll) Iftrueall 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.
 
 - 
igniteprotected Ignite ignite() - Returns:
- Ignite instance.
 
 - 
sessionprotected CacheStoreSession session() - Returns:
- Store session.
 
 
- 
 
-