此内容没有您所选择的语言版本。
Chapter 15. JDBC Based Cache Stores
JdbcBinaryStore
.JdbcStringBasedStore
.JdbcMixedStore
.
15.1. JdbcBinaryStores 复制链接链接已复制到粘贴板!
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.
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-store
element specifies the configuration for a binary keyed cache JDBC store.- The
datasource
parameter defines the name of a JNDI for the datasource. - The
passivation
parameter determines whether entries in the cache are passivated (true
) or if the cache store retains a copy of the contents in memory (false
). - The
preload
parameter specifies whether to load entries into the cache during start up. Valid values for this parameter aretrue
andfalse
. - The
purge
parameter specifies whether or not the cache store is purged when it is started. Valid values for this parameter aretrue
andfalse
.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The binary-keyed-table Element
Thebinary-keyed-table
element specifies information about the database table used to store binary cache entries.- The
prefix
parameter specifies a prefix string for the database table name.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The id-column Element
Theid-column
element specifies information about a database column that holds cache entry IDs.- The
name
parameter specifies the name of the database column. - The
type
parameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The data-column Element
Thedata-column
element contains information about a database column that holds cache entry data.- The
name
parameter specifies the name of the database column. - The
type
parameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The timestamp-column Element
Thetimestamp-column
element specifies information about the database column that holds cache entry timestamps.- The
name
parameter specifies the name of the database column. - The
type
parameter specifies the type of the database column.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.1.2. JdbcBinaryStore Configuration (Library Mode) 复制链接链接已复制到粘贴板!
JdbcBinaryStore
:
Procedure 15.2. Configure the JdbcBinaryStore for Library Mode
The binaryKeyedJdbcStore Element
ThebinaryKeyedJdbcStore
element uses the following parameters to configure the cache store:- The
fetchPersistentState
parameter determines whether the persistent state is fetched when joining a cluster. Set this totrue
if 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
. ThefetchPersistentState
parameter isfalse
by default. - The
ignoreModifications
parameter 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
purgeOnStartup
parameter specifies whether the cache store is purged when initially started.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The connectionPool Element
TheconnectionPool
element specifies a connection pool for the JDBC driver using the following parameters:- The
connectionUrl
parameter specifies the JDBC driver-specific connection URL. - The
username
parameter contains the username used to connect via theconnectionUrl
. - The
driverClass
parameter 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
ThebinaryKeyedTable
element defines the table that stores cache entries. It uses the following parameters to configure the cache store:- The
dropOnExit
parameter specifies whether the database tables are dropped upon shutdown. - The
createOnStart
parameter specifies whether the database tables are created by the store on startup. - The
prefix
parameter 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
TheidColumn
element defines the column where the cache key or bucket ID is stored. It uses the following parameters:- Use the
name
parameter to specify the name of the column used. - Use the
type
parameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The dataColumn Element
ThedataColumn
element specifies the column where the cache entry or bucket is stored.- Use the
name
parameter to specify the name of the column used. - Use the
type
parameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The timestampColumn Element
ThetimestampColumn
element specifies the column where the time stamp of the cache entry or bucket is stored.- Use the
name
parameter to specify the name of the column used. - Use the
type
parameter to specify the type of the column used.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.1.3. JdbcBinaryStore Programmatic Configuration 复制链接链接已复制到粘贴板!
JdbcBinaryStore
:
Procedure 15.3. JdbcBinaryStore Programmatic Configuration (Library Mode)
Create a New Configuration Builder
Use theConfigurationBuilder
to 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
JdbcBinaryStoreConfigurationBuilder
Add theJdbcBinaryStore
configuration 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
fetchPersistentState
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
. ThefetchPersistentState
property isfalse
by 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
ignoreModifications
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.ignoreModifications
isfalse
by default.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure Purging
purgeOnStartup
specifies 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
dropOnExit
determines if the table will be created when the cache store is stopped. This is set tofalse
by default.Set Create Table On Start Method
createOnStart
creates the table when starting the cache store if no table currently exists. This method istrue
by default.Set the Table Name Prefix
tableNamePrefix
sets the prefix for the name of the table in which the data will be stored.idColumnName
TheidColumnName
property defines the column where the cache key or bucket ID is stored.dataColumnName
ThedataColumnName
property specifies the column where the cache entry or bucket is stored.timestampColumnName
ThetimestampColumnName
element 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
TheconnectionPool
element specifies a connection pool for the JDBC driver using the following parameters:- The
connectionUrl
parameter specifies the JDBC driver-specific connection URL. - The
username
parameter contains the user name used to connect via theconnectionUrl
. - The
driverClass
parameter specifies the class name of the driver used to connect to the database.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note