org.infinispan.loaders.jdbc.stringbased
Class JdbcStringBasedCacheStore
java.lang.Object
org.infinispan.loaders.AbstractCacheLoader
org.infinispan.loaders.AbstractCacheStore
org.infinispan.loaders.LockSupportCacheStore
org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore
- All Implemented Interfaces:
- CacheLoader, CacheStore
public class JdbcStringBasedCacheStore
- extends LockSupportCacheStore
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
.
The actual storage table is defined through configuration JdbcStringBasedCacheStore
. The table can be
created/dropped on-the-fly, at deployment time. For more details consult javadoc for JdbcStringBasedCacheStore
.
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).
- Author:
- Mircea.Markus@jboss.com
- See Also:
Key2StringMapper
,
DefaultKey2StringMapper
Methods inherited from class org.infinispan.loaders.LockSupportCacheStore |
acquireGlobalLock, clear, fromStream, getTotalLockCount, immediateLockForWriting, load, loadAll, lockForReading, lockForWriting, releaseGlobalLock, remove, store, toStream, unlock |
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,
Marshaller 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
- 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
- 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
- Throws:
CacheLoaderException
storeLockSafe
public void storeLockSafe(InternalCacheEntry ed,
String lockingKey)
throws CacheLoaderException
- Specified by:
storeLockSafe
in class LockSupportCacheStore
- Throws:
CacheLoaderException
removeLockSafe
public boolean removeLockSafe(Object key,
String keyStr)
throws CacheLoaderException
- Specified by:
removeLockSafe
in class LockSupportCacheStore
- Throws:
CacheLoaderException
fromStreamLockSafe
public void fromStreamLockSafe(ObjectInput objectInput)
throws CacheLoaderException
- Specified by:
fromStreamLockSafe
in class LockSupportCacheStore
- Throws:
CacheLoaderException
toStreamLockSafe
protected void toStreamLockSafe(ObjectOutput objectOutput)
throws CacheLoaderException
- Specified by:
toStreamLockSafe
in class LockSupportCacheStore
- Throws:
CacheLoaderException
clearLockSafe
protected void clearLockSafe()
throws CacheLoaderException
- Specified by:
clearLockSafe
in class LockSupportCacheStore
- Throws:
CacheLoaderException
loadAllLockSafe
protected Set<InternalCacheEntry> loadAllLockSafe()
throws CacheLoaderException
- Specified by:
loadAllLockSafe
in class LockSupportCacheStore
- 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
- Throws:
CacheLoaderException
getConfigurationClass
public Class<? extends CacheLoaderConfig> getConfigurationClass()
- Returns:
- the type of the
CacheLoaderConfig
bean used to configure this
implementation of CacheLoader
logAndThrow
protected void logAndThrow(Exception e,
String message)
throws CacheLoaderException
- Throws:
CacheLoaderException
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()
Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.