此内容没有您所选择的语言版本。
18.6. JDBC Based Cache Stores
Red Hat JBoss Data Grid offers several cache stores for use with common data storage formats. JDBC based cache stores are used with any cache store that exposes a JDBC driver. JBoss Data Grid offers the following JDBC based cache stores depending on the key to be persisted:
JdbcBinaryStore.JdbcStringBasedStore.JdbcMixedStore.
18.6.1. JdbcBinaryStores 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The
JdbcBinaryStore supports all key types. It stores all keys with the same hash value (hashCode method on the key) in the same table row/blob. The hash value common to the included keys is set as the primary key for the table row/blob. As a result of this hash value, JdbcBinaryStore offers excellent flexibility but at the cost of concurrency and throughput.
As an example, if three keys (
k1, k2 and k3) have the same hash code, they are stored in the same table row. If three different threads attempt to concurrently update k1, k2 and k3, they must do it sequentially because all three keys share the same row and therefore cannot be simultaneously updated.
The following is a configuration for
JdbcBinaryStore using Red Hat JBoss Data Grid's Remote Client-Server mode with Passivation enabled:
For details about the elements and parameters used in this sample configuration, see Section 18.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
18.6.1.2. JdbcBinaryStore Configuration (Library Mode) 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following is a sample configuration for the
JdbcBinaryStore:
For details about the elements and parameters used in this sample configuration, see Section 18.2, “Cache Store Configuration Details (Library Mode)”.
18.6.1.3. JdbcBinaryStore Programmatic Configuration 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following is a sample configuration for the
JdbcBinaryStore:
Procedure 18.4. JdbcBinaryStore Programmatic Configuration (Library Mode)
- Use the
ConfigurationBuilderto create a new configuration object. - Add the
JdbcBinaryStoreconfiguration builder to build a specific configuration related to this store. - The
fetchPersistentStateelement determines whether or not to fetch the persistent state of a cache and apply it to the local cache store when joining the cluster. If the cache store is shared the fetch persistent state is ignored, as caches access the same cache store. A configuration exception will be thrown when starting the cache service if more than one cache loader has this property set totrue. ThefetchPersistentStateproperty isfalseby default. - The
ignoreModificationselement determines whether write methods are pushed to the specific cache loader by allowing write operations to the local file cache loader, but not the shared cache loader. In some cases, transient application data should only reside in a file-based cache loader on the same server as the in-memory cache. For example, this would apply with a further JDBC based cache loader used by all servers in the network.ignoreModificationsisfalseby default. - The
purgeOnStartupelement specifies whether the cache is purged when initially started. - Configure the table as follows:
dropOnExitdetermines if the table will be dropped when the cache store is stopped. This is set tofalseby default.createOnStartcreates the table when starting the cache store if no table currently exists. This method istrueby default.tableNamePrefixsets the prefix for the name of the table in which the data will be stored.- The
idColumnNameproperty defines the column where the cache key or bucket ID is stored. - The
dataColumnNameproperty specifies the column where the cache entry or bucket is stored. - The
timestampColumnNameelement specifies the column where the time stamp of the cache entry or bucket is stored.
- The
connectionPoolelement specifies a connection pool for the JDBC driver using the following parameters:- The
connectionUrlparameter specifies the JDBC driver-specific connection URL. - The
usernameparameter contains the user name used to connect via theconnectionUrl. - The
driverClassparameter specifies the class name of the driver used to connect to the database.
Note
Programmatic configurations can only be used with Red Hat JBoss Data Grid Library mode.
18.6.2. JdbcStringBasedStores 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The
JdbcStringBasedStore stores each entry in its own row in the table, instead of grouping multiple entries into each row, resulting in increased throughput under a concurrent load. It also uses a (pluggable) bijection that maps each key to a String object. The Key2StringMapper interface defines the bijection.
Red Hat JBoss Data Grid includes a default implementation called
DefaultTwoWayKey2StringMapper that handles primitive types.
The following is a sample
JdbcStringBasedStore for Red Hat JBoss Data Grid's Remote Client-Server mode:
For details about the elements and parameters used in this sample configuration, see Section 18.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
The following is a sample configuration for the
JdbcStringBasedStore:
For details about the elements and parameters used in this sample configuration, see Section 18.2, “Cache Store Configuration Details (Library Mode)”.
The following is a configuration for the
JdbcStringBasedStore in Red Hat JBoss Data Grid's Remote Client-Server mode. This configuration is used when multiple nodes must be used.
For details about the elements and parameters used in this sample configuration, see Section 18.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
The following is a sample configuration for the
JdbcStringBasedStore:
Procedure 18.5. Configure the JdbcStringBasedStore Programmatically
- Use the
ConfigurationBuilderto create a new configuration object. - Add the
JdbcStringBasedStoreconfiguration builder to build a specific configuration related to this store. - The
fetchPersistentStateparameter determines whether or not to fetch the persistent state of a cache and apply it to the local cache store when joining the cluster. If the cache store is shared the fetch persistent state is ignored, as caches access the same cache store. A configuration exception will be thrown when starting the cache service if more than one cache loader has this property set totrue. ThefetchPersistentStateproperty isfalseby default. - The
ignoreModificationsparameter determines whether write methods are pushed to the specific cache loader by allowing write operations to the local file cache loader, but not the shared cache loader. In some cases, transient application data should only reside in a file-based cache loader on the same server as the in-memory cache. For example, this would apply with a further JDBC based cache loader used by all servers in the network.ignoreModificationsisfalseby default. - The
purgeOnStartupparameter specifies whether the cache is purged when initially started. - Configure the Table
dropOnExitdetermines if the table will be dropped when the cache store is stopped. This is set tofalseby default.createOnStartcreates the table when starting the cache store if no table currently exists. This method istrueby default.tableNamePrefixsets the prefix for the name of the table in which the data will be stored.- The
idColumnNameproperty defines the column where the cache key or bucket ID is stored. - The
dataColumnNameproperty specifies the column where the cache entry or bucket is stored. - The
timestampColumnNameelement specifies the column where the time stamp of the cache entry or bucket is stored.
- The
connectionPoolelement specifies a connection pool for the JDBC driver using the following parameters:- The
connectionUrlparameter specifies the JDBC driver-specific connection URL. - The
usernameparameter contains the username used to connect via theconnectionUrl. - The
driverClassparameter specifies the class name of the driver used to connect to the database.
Note
Programmatic configurations can only be used with Red Hat JBoss Data Grid Library mode.
18.6.3. JdbcMixedStores 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The
JdbcMixedStore is a hybrid implementation that delegates keys based on their type to either the JdbcBinaryStore or JdbcStringBasedStore.
The following is a configuration for a
JdbcMixedStore for Red Hat JBoss Data Grid's Remote Client-Server mode:
For details about the elements and parameters used in this sample configuration, see Section 18.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
18.6.3.2. JdbcMixedStore Configuration (Library Mode) 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following is a sample configuration for the
mixedKeyedJdbcStore:
For details about the elements and parameters used in this sample configuration, see Section 18.2, “Cache Store Configuration Details (Library Mode)”.
18.6.3.3. JdbcMixedStore Programmatic Configuration 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following is a sample configuration for the
JdbcMixedStore:
Procedure 18.6. Configure JdbcMixedStore Programmatically
- Use the
ConfigurationBuilderto create a new configuration object. - Add the
JdbcMixedStoreconfiguration builder to build a specific configuration related to this store. - The
fetchPersistentStateparameter determines whether or not to fetch the persistent state of a cache and apply it to the local cache store when joining the cluster. If the cache store is shared the fetch persistent state is ignored, as caches access the same cache store. A configuration exception will be thrown when starting the cache service if more than one cache loader has this property set totrue. ThefetchPersistentStateproperty isfalseby default. - The
ignoreModificationsparameter determines whether write methods are pushed to the specific cache loader by allowing write operations to the local file cache loader, but not the shared cache loader. In some cases, transient application data should only reside in a file-based cache loader on the same server as the in-memory cache. For example, this would apply with a further JDBC based cache loader used by all servers in the network.ignoreModificationsisfalseby default. - The
purgeOnStartupparameter specifies whether the cache is purged when initially started. - Configure the table as follows:
dropOnExitdetermines if the table will be dropped when the cache store is stopped. This is set tofalseby default.createOnStartcreates the table when starting the cache store if no table currently exists. This method istrueby default.tableNamePrefixsets the prefix for the name of the table in which the data will be stored.- The
idColumnNameproperty defines the column where the cache key or bucket ID is stored. - The
dataColumnNameproperty specifies the column where the cache entry or bucket is stored. - The
timestampColumnNameelement specifies the column where the time stamp of the cache entry or bucket is stored.
- The
connectionPoolelement specifies a connection pool for the JDBC driver using the following parameters:- The
connectionUrlparameter specifies the JDBC driver-specific connection URL. - The
usernameparameter contains the username used to connect via theconnectionUrl. - The
driverClassparameter specifies the class name of the driver used to connect to the database.
Note
Programmatic configurations can only be used with Red Hat JBoss Data Grid Library mode.
18.6.4. Cache Store Troubleshooting 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
18.6.4.1. IOExceptions with JdbcStringBasedStore 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
An IOException Unsupported protocol version 48 error when using
JdbcStringBasedStore indicates that your data column type is set to VARCHAR, CLOB or something similar instead of the correct type, BLOB or VARBINARY. Despite its name, JdbcStringBasedStore only requires that the keys are strings while the values can be any data type, so that they can be stored in a binary column.