此内容没有您所选择的语言版本。
15.3.3. JdbcMixedStore Programmatic Configuration
The following is a sample configuration for the
JdbcMixedStore:
Procedure 15.10. Configure JdbcMixedStore Programmatically
Create a New Configuration Builder
Use theConfigurationBuilderto create a new configuration object.ConfigurationBuilder builder = new ConfigurationBuilder();Add
JdbcMixedStoreConfigurationBuilderAdd theJdbcMixedStoreconfiguration builder to build a specific configuration related to this store.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().addStore(JdbcMixedStoreConfigurationBuilder.class)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 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(JdbcMixedStoreConfigurationBuilder.class) .fetchPersistentState(false)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.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().addStore(JdbcMixedStoreConfigurationBuilder.class) .fetchPersistentState(false) .ignoreModifications(false)Configure Purging
purgeOnStartupspecifies whether the cache is purged when initially started.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().addStore(JdbcMixedStoreConfigurationBuilder.class) .fetchPersistentState(false) .ignoreModifications(false) .purgeOnStartup(false)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.
ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().addStore(JdbcMixedStoreConfigurationBuilder.class) .fetchPersistentState(false) .ignoreModifications(false) .purgeOnStartup(false) .stringTable() .dropOnExit(true) .createOnStart(true) .tableNamePrefix("ISPN_MIXED_STR_TABLE") .idColumnName("ID_COLUMN").idColumnType("VARCHAR(255)") .dataColumnName("DATA_COLUMN").dataColumnType("BINARY") .timestampColumnName("TIMESTAMP_COLUMN").timestampColumnType("BIGINT")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.
ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().addStore(JdbcMixedStoreConfigurationBuilder.class) .fetchPersistentState(false) .ignoreModifications(false) .purgeOnStartup(false) .stringTable() .dropOnExit(true) .createOnStart(true) .tableNamePrefix("ISPN_MIXED_STR_TABLE") .idColumnName("ID_COLUMN").idColumnType("VARCHAR(255)") .dataColumnName("DATA_COLUMN").dataColumnType("BINARY") .timestampColumnName("TIMESTAMP_COLUMN").timestampColumnType("BIGINT") .binaryTable() .dropOnExit(true) .createOnStart(true) .tableNamePrefix("ISPN_MIXED_BINARY_TABLE") .idColumnName("ID_COLUMN").idColumnType("VARCHAR(255)") .dataColumnName("DATA_COLUMN").dataColumnType("BINARY") .timestampColumnName("TIMESTAMP_COLUMN").timestampColumnType("BIGINT") .connectionPool() .connectionUrl("jdbc:h2:mem:infinispan_binary_based;DB_CLOSE_DELAY=-1") .username("sa") .driverClass("org.h2.Driver");
Note
Programmatic configurations can only be used with Red Hat JBoss Data Grid Library mode.