org.infinispan.loaders.jdbc.stringbased
Class JdbcStringBasedCacheStore
java.lang.Object
org.infinispan.loaders.AbstractCacheLoader
org.infinispan.loaders.AbstractCacheStore
org.infinispan.loaders.LockSupportCacheStore<String>
org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore
- All Implemented Interfaces:
- CacheLoader, CacheStore
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).
- Author:
- Mircea.Markus@jboss.com
- See Also:
Key2StringMapper
,
DefaultTwoWayKey2StringMapper
Methods inherited from class org.infinispan.loaders.LockSupportCacheStore |
acquireGlobalLock, clear, downgradeLock, fromStream, getTotalLockCount, immediateLockForWriting, load, load, loadAll, loadAllKeys, lockForReading, lockForWriting, releaseGlobalLock, remove, store, toStream, unlock, upgradeLock |
Methods inherited from class org.infinispan.loaders.AbstractCacheStore |
applyModifications, commit, getCacheStoreConfig, getConcurrencyLevel, getMarshaller, prepare, purgeExpired, removeAll, rollback, safeClose, safeClose, supportsMultiThreadedPurge |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JdbcStringBasedCacheStore
public JdbcStringBasedCacheStore()
init
public void init(CacheLoaderConfig config,
Cache<?,?> cache,
StreamingMarshaller m)
throws CacheLoaderException
- Description copied from interface:
CacheLoader
- Used to initialize a cache loader. Typically invoked by the
CacheLoaderManager
when setting up cache loaders.
- Specified by:
init
in interface CacheLoader
- Overrides:
init
in class LockSupportCacheStore<String>
- Parameters:
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.
- Throws:
CacheLoaderException
start
public void start()
throws CacheLoaderException
- Specified by:
start
in interface CacheLoader
- Overrides:
start
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
stop
public void stop()
throws CacheLoaderException
- Specified by:
stop
in interface CacheLoader
- Overrides:
stop
in class AbstractCacheStore
- Throws:
CacheLoaderException
getLockFromKey
protected String getLockFromKey(Object key)
throws CacheLoaderException
- Specified by:
getLockFromKey
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
storeLockSafe
public void storeLockSafe(InternalCacheEntry ed,
String lockingKey)
throws CacheLoaderException
- Specified by:
storeLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
removeLockSafe
public boolean removeLockSafe(Object key,
String keyStr)
throws CacheLoaderException
- Specified by:
removeLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
fromStreamLockSafe
public void fromStreamLockSafe(ObjectInput objectInput)
throws CacheLoaderException
- Specified by:
fromStreamLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
toStreamLockSafe
protected void toStreamLockSafe(ObjectOutput objectOutput)
throws CacheLoaderException
- Specified by:
toStreamLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
clearLockSafe
protected void clearLockSafe()
throws CacheLoaderException
- Specified by:
clearLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
loadAllLockSafe
protected Set<InternalCacheEntry> loadAllLockSafe()
throws CacheLoaderException
- Specified by:
loadAllLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
loadLockSafe
protected Set<InternalCacheEntry> loadLockSafe(int maxEntries)
throws CacheLoaderException
- Specified by:
loadLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
loadAllKeysLockSafe
protected Set<Object> loadAllKeysLockSafe(Set<Object> keysToExclude)
throws CacheLoaderException
- Specified by:
loadAllKeysLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
purgeInternal
public void purgeInternal()
throws CacheLoaderException
- Specified by:
purgeInternal
in class AbstractCacheStore
- Throws:
CacheLoaderException
loadLockSafe
protected InternalCacheEntry loadLockSafe(Object key,
String lockingKey)
throws CacheLoaderException
- Specified by:
loadLockSafe
in class LockSupportCacheStore<String>
- Throws:
CacheLoaderException
getConfigurationClass
public Class<? extends CacheLoaderConfig> getConfigurationClass()
- Description copied from interface:
CacheLoader
- This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding
CacheLoaderConfig
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.
- Returns:
- the type of the
CacheLoaderConfig
bean used to configure this
implementation of CacheLoader
.
supportsKey
public boolean supportsKey(Class<?> keyType)
doConnectionFactoryInitialization
public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory)
throws CacheLoaderException
- Keeps a reference to the connection factory for further use. Also initializes the
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.
- Throws:
CacheLoaderException
getConnectionFactory
public ConnectionFactory getConnectionFactory()
getTableManipulation
public TableManipulation getTableManipulation()
isUsingPreload
public boolean isUsingPreload()
isDistributed
public boolean isDistributed()
Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.