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 JdbcStringBasedCacheStoreConfiguration
. The table can
be
created/dropped on-the-fly, at deployment time. For more details consult javadoc for JdbcStringBasedCacheStoreConfiguration
.
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
,
DefaultTwoWayKey2StringMapper
multiThreadedPurge, purgerService
cache, marshaller, timeService
Constructor and Description |
---|
JdbcStringBasedCacheStore() |
acquireGlobalLock, clear, downgradeLock, fromStream, getTotalLockCount, immediateLockForWriting, load, load, loadAll, loadAllKeys, lockForReading, lockForWriting, releaseGlobalLock, remove, store, toStream, unlock, upgradeLock
applyModifications, commit, getConcurrencyLevel, getConfiguration, getMarshaller, prepare, purgeExpired, removeAll, rollback, safeClose, safeClose, supportsMultiThreadedPurge
containsKey, validateConfigurationClass
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
containsKey
public void init(CacheLoaderConfiguration configuration, Cache<?,?> cache, StreamingMarshaller m) throws CacheLoaderException
CacheLoader
CacheLoaderManager
when setting up cache loaders.init
in interface CacheLoader
init
in class LockSupportCacheStore<String>
configuration
- 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.CacheLoaderException
public void start() throws CacheLoaderException
start
in interface CacheLoader
start
in class LockSupportCacheStore<String>
CacheLoaderException
public void stop() throws CacheLoaderException
stop
in interface CacheLoader
stop
in class AbstractCacheStore
CacheLoaderException
protected String getLockFromKey(Object key) throws CacheLoaderException
getLockFromKey
in class LockSupportCacheStore<String>
CacheLoaderException
public void storeLockSafe(InternalCacheEntry ed, String lockingKey) throws CacheLoaderException
storeLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
public boolean removeLockSafe(Object key, String keyStr) throws CacheLoaderException
removeLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
public void fromStreamLockSafe(ObjectInput objectInput) throws CacheLoaderException
fromStreamLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
protected void toStreamLockSafe(ObjectOutput objectOutput) throws CacheLoaderException
toStreamLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
protected void clearLockSafe() throws CacheLoaderException
clearLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
protected Set<InternalCacheEntry> loadAllLockSafe() throws CacheLoaderException
loadAllLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
protected Set<InternalCacheEntry> loadLockSafe(int maxEntries) throws CacheLoaderException
loadLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
protected Set<Object> loadAllKeysLockSafe(Set<Object> keysToExclude) throws CacheLoaderException
loadAllKeysLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
public void purgeInternal() throws CacheLoaderException
purgeInternal
in class AbstractCacheStore
CacheLoaderException
protected InternalCacheEntry loadLockSafe(Object key, String lockingKey) throws CacheLoaderException
loadLockSafe
in class LockSupportCacheStore<String>
CacheLoaderException
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.CacheLoaderException
public ConnectionFactory getConnectionFactory()
public TableManipulation getTableManipulation()
public boolean isUsingPreload()
public boolean isDistributed()
Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.