public class JdbcStringBasedCacheStore extends LockSupportCacheStore<String>
CacheStore implementation that stores the entries in a database. In contrast to the
JdbcBinaryCacheStore, this cache store will store each entry within a row
in the table (rather than grouping multiple entries into an row). This assures a finer grained granularity for all
operation, and better performance. In order to be able to store non-string keys, it relies on an Key2StringMapper.
Note that only the keys are stored as strings, the values are still saved as binary data. Using a character
data type for the value column will result in unmarshalling errors.
The actual storage table is defined through configuration JdbcStringBasedCacheStoreConfig. The table can be
created/dropped on-the-fly, at deployment time. For more details consult javadoc for JdbcStringBasedCacheStoreConfig.
It is recommended to use JdbcStringBasedCacheStore} over
JdbcBinaryCacheStore} whenever it is possible, as is has a better performance.
One scenario in which this is not possible to use it though, is when you can't write an Key2StringMapper} to map the
keys to to string objects (e.g. when you don't have control over the types of the keys, for whatever reason).
Preload.In order to support preload functionality the store needs to read the string keys from the database and transform them
into the corresponding key objects. Key2StringMapper only supports
key to string transformation(one way); in order to be able to use preload one needs to specify an
TwoWayKey2StringMapper, which extends Key2StringMapper and
allows bidirectional transformation.
Rehashing. When a node leaves/joins, Infinispan moves around persistent state as part of rehashing process.
For this it needs access to the underlaying key objects, so if distribution is used, the mapper needs to be an
TwoWayKey2StringMapper otherwise the cache won't start (same constraint as with preloading).Key2StringMapper,
DefaultTwoWayKey2StringMappermultiThreadedPurge, purgerServicecache, marshaller| Constructor and Description |
|---|
JdbcStringBasedCacheStore() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearLockSafe() |
void |
doConnectionFactoryInitialization(ConnectionFactory connectionFactory)
Keeps a reference to the connection factory for further use.
|
void |
fromStreamLockSafe(ObjectInput objectInput) |
Class<? extends CacheLoaderConfig> |
getConfigurationClass()
This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding
CacheLoaderConfig type. |
ConnectionFactory |
getConnectionFactory() |
protected String |
getLockFromKey(Object key) |
TableManipulation |
getTableManipulation() |
void |
init(CacheLoaderConfig config,
Cache<?,?> cache,
StreamingMarshaller m)
Used to initialize a cache loader.
|
boolean |
isDistributed() |
boolean |
isUsingPreload() |
protected Set<Object> |
loadAllKeysLockSafe(Set<Object> keysToExclude) |
protected Set<InternalCacheEntry> |
loadAllLockSafe() |
protected Set<InternalCacheEntry> |
loadLockSafe(int maxEntries) |
protected InternalCacheEntry |
loadLockSafe(Object key,
String lockingKey) |
void |
purgeInternal() |
boolean |
removeLockSafe(Object key,
String keyStr) |
void |
start() |
void |
stop() |
void |
storeLockSafe(InternalCacheEntry ed,
String lockingKey) |
boolean |
supportsKey(Class<?> keyType) |
protected void |
toStreamLockSafe(ObjectOutput objectOutput) |
acquireGlobalLock, clear, downgradeLock, fromStream, getTotalLockCount, immediateLockForWriting, load, load, loadAll, loadAllKeys, lockForReading, lockForWriting, releaseGlobalLock, remove, store, toStream, unlock, upgradeLockapplyModifications, commit, getCacheStoreConfig, getConcurrencyLevel, getMarshaller, prepare, purgeExpired, removeAll, rollback, safeClose, safeClose, supportsMultiThreadedPurgecontainsKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainsKeypublic void init(CacheLoaderConfig config, Cache<?,?> cache, StreamingMarshaller m) throws CacheLoaderException
CacheLoaderCacheLoaderManager
when setting up cache loaders.init in interface CacheLoaderinit in class LockSupportCacheStore<String>config - the cache loader configuration beancache - cache associated with this cache loader. Implementations may use this to determine cache name when
selecting where refer to state in storage, for example, a different database table name.m - marshaller to use when loading state from a stream, if supported by the implementation.CacheLoaderExceptionpublic void start()
throws CacheLoaderException
start in interface CacheLoaderstart in class LockSupportCacheStore<String>CacheLoaderExceptionpublic void stop()
throws CacheLoaderException
stop in interface CacheLoaderstop in class AbstractCacheStoreCacheLoaderExceptionprotected String getLockFromKey(Object key) throws CacheLoaderException
getLockFromKey in class LockSupportCacheStore<String>CacheLoaderExceptionpublic void storeLockSafe(InternalCacheEntry ed, String lockingKey) throws CacheLoaderException
storeLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionpublic boolean removeLockSafe(Object key, String keyStr) throws CacheLoaderException
removeLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionpublic void fromStreamLockSafe(ObjectInput objectInput) throws CacheLoaderException
fromStreamLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionprotected void toStreamLockSafe(ObjectOutput objectOutput) throws CacheLoaderException
toStreamLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionprotected void clearLockSafe()
throws CacheLoaderException
clearLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionprotected Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException
loadAllLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionprotected Set<InternalCacheEntry> loadLockSafe(int maxEntries) throws CacheLoaderException
loadLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionprotected Set<Object> loadAllKeysLockSafe(Set<Object> keysToExclude) throws CacheLoaderException
loadAllKeysLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionpublic void purgeInternal()
throws CacheLoaderException
purgeInternal in class AbstractCacheStoreCacheLoaderExceptionprotected InternalCacheEntry loadLockSafe(Object key, String lockingKey) throws CacheLoaderException
loadLockSafe in class LockSupportCacheStore<String>CacheLoaderExceptionpublic Class<? extends CacheLoaderConfig> getConfigurationClass()
CacheLoaderCacheLoaderConfig type. This is usually done by instantiating the CacheLoader
and then calling this method. This may result in 2 instances being created, however, since the instance
created to get a hold of the configuration type is then discarded and another instance is created for actual
use as a CacheLoader when the cache starts.
Since Infinispan 4.1, you can also annotate your CacheLoader implementation with CacheLoaderMetadata
and provide this information via the annotation, which will prevent unnecessary instances being created.
CacheLoaderConfig bean used to configure this
implementation of CacheLoader.public boolean supportsKey(Class<?> keyType)
public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException
TableManipulation that needs connections. This method should be called when you don't
want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
JdbcMixedCacheStore for such an example of this.CacheLoaderExceptionpublic ConnectionFactory getConnectionFactory()
public TableManipulation getTableManipulation()
public boolean isUsingPreload()
public boolean isDistributed()
Copyright © 2017 JBoss, a division of Red Hat. All Rights Reserved.