Chapter 15. JDBC Based Cache Stores
JdbcBinaryStore.JdbcStringBasedStore.JdbcMixedStore.
15.1. JdbcBinaryStores Copy linkLink copied to clipboard!
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.
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.
15.1.1. JdbcBinaryStore Configuration (Remote Client-Server Mode) Copy linkLink copied to clipboard!
JdbcBinaryStore using Red Hat JBoss Data Grid's Remote Client-Server mode with Passivation enabled.
Procedure 15.1. Configure the JdbcBinaryStore for Remote Client-Server Mode
The binary-keyed-jdbc-store Element
Thebinary-keyed-jdbc-storeelement specifies the configuration for a binary keyed cache JDBC store.- The
datasourceparameter defines the name of a JNDI for the datasource. - The
passivationparameter determines whether entries in the cache are passivated (true) or if the cache store retains a copy of the contents in memory (false). - The
preloadparameter specifies whether to load entries into the cache during start up. Valid values for this parameter aretrueandfalse. - The
purgeparameter specifies whether or not the cache store is purged when it is started. Valid values for this parameter aretrueandfalse.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The binary-keyed-table Element
Thebinary-keyed-tableelement specifies information about the database table used to store binary cache entries.- The
prefixparameter specifies a prefix string for the database table name.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The id-column Element
Theid-columnelement specifies information about a database column that holds cache entry IDs.- The
nameparameter specifies the name of the database column. - The
typeparameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The data-column Element
Thedata-columnelement contains information about a database column that holds cache entry data.- The
nameparameter specifies the name of the database column. - The
typeparameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The timestamp-column Element
Thetimestamp-columnelement specifies information about the database column that holds cache entry timestamps.- The
nameparameter specifies the name of the database column. - The
typeparameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.1.2. JdbcBinaryStore Configuration (Library Mode) Copy linkLink copied to clipboard!
JdbcBinaryStore:
Procedure 15.2. Configure the JdbcBinaryStore for Library Mode
The binaryKeyedJdbcStore Element
ThebinaryKeyedJdbcStoreelement uses the following parameters to configure the cache store:- The
fetchPersistentStateparameter determines whether the persistent state is fetched when joining a cluster. Set this totrueif using a replication and invalidation in a clustered environment. Additionally, if multiple cache stores are chained, only one cache store can have this property enabled. If a shared cache store is used, the cache does not allow a persistent state transfer despite this property being set totrue. ThefetchPersistentStateparameter isfalseby default. - The
ignoreModificationsparameter determines whether operations that modify the cache (e.g. put, remove, clear, store, etc.) do not affect the cache store. As a result, the cache store can become out of sync with the cache. - The
purgeOnStartupparameter specifies whether the cache store is purged when initially started.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The connectionPool Element
TheconnectionPoolelement 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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The binaryKeyedTable Element
ThebinaryKeyedTableelement defines the table that stores cache entries. It uses the following parameters to configure the cache store:- The
dropOnExitparameter specifies whether the database tables are dropped upon shutdown. - The
createOnStartparameter specifies whether the database tables are created by the store on startup. - The
prefixparameter defines the string prepended to name of the target cache when composing the name of the cache bucket table.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The idColumn Element
TheidColumnelement defines the column where the cache key or bucket ID is stored. It uses the following parameters:- Use the
nameparameter to specify the name of the column used. - Use the
typeparameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The dataColumn Element
ThedataColumnelement specifies the column where the cache entry or bucket is stored.- Use the
nameparameter to specify the name of the column used. - Use the
typeparameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The timestampColumn Element
ThetimestampColumnelement specifies the column where the time stamp of the cache entry or bucket is stored.- Use the
nameparameter to specify the name of the column used. - Use the
typeparameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.1.3. JdbcBinaryStore Programmatic Configuration Copy linkLink copied to clipboard!
JdbcBinaryStore:
Procedure 15.3. JdbcBinaryStore Programmatic Configuration (Library Mode)
Create a New Configuration Builder
Use theConfigurationBuilderto create a new configuration object.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence()
ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence()Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
JdbcBinaryStoreConfigurationBuilderAdd theJdbcBinaryStoreconfiguration builder to build a specific configuration related to this store.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(JdbcBinaryStoreConfigurationBuilder.class)ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(JdbcBinaryStoreConfigurationBuilder.class)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set Up Persistence
fetchPersistentStatedetermines 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.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(JdbcBinaryStoreConfigurationBuilder.class) .fetchPersistentState(false)ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(JdbcBinaryStoreConfigurationBuilder.class) .fetchPersistentState(false)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set Modifications
ignoreModificationsdetermines 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.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure Purging
purgeOnStartupspecifies whether the cache is purged when initially started.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the Table
Set Drop Table On Exit Method
dropOnExitdetermines if the table will be created when the cache store is stopped. This is set tofalseby default.Set Create Table On Start Method
createOnStartcreates the table when starting the cache store if no table currently exists. This method istrueby default.Set the Table Name Prefix
tableNamePrefixsets the prefix for the name of the table in which the data will be stored.idColumnNameTheidColumnNameproperty defines the column where the cache key or bucket ID is stored.dataColumnNameThedataColumnNameproperty specifies the column where the cache entry or bucket is stored.timestampColumnNameThetimestampColumnNameelement specifies the column where the time stamp of the cache entry or bucket is stored.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The connectionPool Element
TheconnectionPoolelement 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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note