org.infinispan.loaders.jdbc.binary
Class JdbcBinaryCacheStore

java.lang.Object
  extended by org.infinispan.loaders.AbstractCacheLoader
      extended by org.infinispan.loaders.AbstractCacheStore
          extended by org.infinispan.loaders.LockSupportCacheStore<Integer>
              extended by org.infinispan.loaders.bucket.BucketBasedCacheStore
                  extended by org.infinispan.loaders.jdbc.binary.JdbcBinaryCacheStore
All Implemented Interfaces:
CacheLoader, CacheStore

public class JdbcBinaryCacheStore
extends BucketBasedCacheStore

BucketBasedCacheStore implementation that will store all the buckets as rows in database, each row corresponding to a bucket. This is in contrast to JdbcStringBasedCacheStore which stores each StoredEntry as a row in the database.

It is generally recommended to use JdbcStringBasedCacheStore whenever possible as it performs better. Please read JdbcStringBasedCacheStore's javadoc for more details on this.

This class has the benefit of being able to store StoredEntries that do not have String keys, at the cost of coarser grained access granularity, and inherently performance.

All the DB related configurations are described in JdbcBinaryCacheStoreConfig.

Author:
Mircea.Markus@jboss.com
See Also:
JdbcBinaryCacheStoreConfig, JdbcStringBasedCacheStore

Nested Class Summary
 
Nested classes/interfaces inherited from class org.infinispan.loaders.bucket.BucketBasedCacheStore
BucketBasedCacheStore.BucketHandler, BucketBasedCacheStore.CollectionGeneratingBucketHandler<T>
 
Field Summary
 
Fields inherited from class org.infinispan.loaders.AbstractCacheStore
multiThreadedPurge, purgerService
 
Fields inherited from class org.infinispan.loaders.AbstractCacheLoader
cache, marshaller
 
Constructor Summary
JdbcBinaryCacheStore()
           
 
Method Summary
protected  void clearLockSafe()
           
 void doConnectionFactoryInitialization(ConnectionFactory connectionFactory)
          Keeps a reference to the connection factory for further use.
protected  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  StreamingMarshaller getMarshaller()
           
 TableManipulation getTableManipulation()
           
 void init(CacheLoaderConfig config, Cache<?,?> cache, StreamingMarshaller m)
          Used to initialize a cache loader.
protected  void insertBucket(Bucket bucket)
          Inserts a new Bucket in the storage system.
 Set<Object> loadAllKeys(Set<Object> keysToExclude)
          Loads a set of all keys, excluding a filter set.
 Set<InternalCacheEntry> loadAllLockSafe()
           
protected  Bucket loadBucket(Integer keyHashCode)
          Loads a Bucket from the store, based on the hash code of the bucket.
protected  Set<InternalCacheEntry> loadLockSafe(int maxEntries)
           
protected  void loopOverBuckets(BucketBasedCacheStore.BucketHandler handler)
          A mechanism to loop over all buckets in the cache store.
 void purgeInternal()
           
 void start()
           
 void stop()
           
protected  void toStreamLockSafe(ObjectOutput objectOutput)
           
protected  void updateBucket(Bucket bucket)
          Updates a bucket in the store with the Bucket passed in to the method.
 
Methods inherited from class org.infinispan.loaders.bucket.BucketBasedCacheStore
getLockFromKey, loadAllKeysLockSafe, loadLockSafe, removeLockSafe, storeLockSafe
 
Methods inherited from class org.infinispan.loaders.LockSupportCacheStore
acquireGlobalLock, clear, downgradeLock, fromStream, getTotalLockCount, immediateLockForWriting, load, load, loadAll, lockForReading, lockForWriting, releaseGlobalLock, remove, store, toStream, unlock, upgradeLock
 
Methods inherited from class org.infinispan.loaders.AbstractCacheStore
applyModifications, commit, getCacheStoreConfig, getConcurrencyLevel, prepare, purgeExpired, removeAll, rollback, safeClose, safeClose, supportsMultiThreadedPurge
 
Methods inherited from class org.infinispan.loaders.AbstractCacheLoader
containsKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.infinispan.loaders.CacheLoader
containsKey
 

Constructor Detail

JdbcBinaryCacheStore

public JdbcBinaryCacheStore()
Method Detail

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<Integer>
Parameters:
config - the cache loader configuration bean
cache - 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<Integer>
Throws:
CacheLoaderException

stop

public void stop()
          throws CacheLoaderException
Specified by:
stop in interface CacheLoader
Overrides:
stop in class AbstractCacheStore
Throws:
CacheLoaderException

insertBucket

protected void insertBucket(Bucket bucket)
                     throws CacheLoaderException
Description copied from class: BucketBasedCacheStore
Inserts a new Bucket in the storage system. If the bucket already exists, this method should simply update the store with the contents of the bucket - i.e., behave the same as BucketBasedCacheStore.updateBucket(Bucket).

Overrides:
insertBucket in class BucketBasedCacheStore
Parameters:
bucket - bucket to insert
Throws:
CacheLoaderException - in case of problems with the store.

updateBucket

protected void updateBucket(Bucket bucket)
                     throws CacheLoaderException
Description copied from class: BucketBasedCacheStore
Updates a bucket in the store with the Bucket passed in to the method. This method assumes that the bucket already exists in the store, however some implementations may choose to simply create a new bucket if the bucket does not exist.

The default behavior is that non-existent buckets are created on the fly. If this is not the case in your implementation, then you would have to override BucketBasedCacheStore.insertBucket(Bucket) as well so that it doesn't blindly forward calls to BucketBasedCacheStore.updateBucket(Bucket).

Specified by:
updateBucket in class BucketBasedCacheStore
Parameters:
bucket - bucket to update.
Throws:
CacheLoaderException - in case of problems with the store.

loadBucket

protected Bucket loadBucket(Integer keyHashCode)
                     throws CacheLoaderException
Description copied from class: BucketBasedCacheStore
Loads a Bucket from the store, based on the hash code of the bucket.

Specified by:
loadBucket in class BucketBasedCacheStore
Parameters:
keyHashCode - the Bucket's hash
Returns:
a Bucket if one exists, null otherwise.
Throws:
CacheLoaderException - in case of problems with the store.

loadAllLockSafe

public Set<InternalCacheEntry> loadAllLockSafe()
                                        throws CacheLoaderException
Overrides:
loadAllLockSafe in class BucketBasedCacheStore
Throws:
CacheLoaderException

loadAllKeys

public Set<Object> loadAllKeys(Set<Object> keysToExclude)
                        throws CacheLoaderException
Description copied from interface: CacheLoader
Loads a set of all keys, excluding a filter set.

Specified by:
loadAllKeys in interface CacheLoader
Overrides:
loadAllKeys in class LockSupportCacheStore<Integer>
Parameters:
keysToExclude - a set of keys to exclude. An empty set or null will indicate that all keys should be returned.
Returns:
A set containing keys of entries stored. An empty set is returned if the loader is empty.
Throws:
CacheLoaderException

loadLockSafe

protected Set<InternalCacheEntry> loadLockSafe(int maxEntries)
                                        throws CacheLoaderException
Overrides:
loadLockSafe in class BucketBasedCacheStore
Throws:
CacheLoaderException

loopOverBuckets

protected void loopOverBuckets(BucketBasedCacheStore.BucketHandler handler)
                        throws CacheLoaderException
Description copied from class: BucketBasedCacheStore
A mechanism to loop over all buckets in the cache store. Implementations should, very simply, loop over all available buckets, and for each deserialized bucket, pass it to the handler.

The implementation is expected to loop over all available buckets (in any order), until BucketBasedCacheStore.BucketHandler.handle(Bucket) returns true or there are no more buckets available.

Specified by:
loopOverBuckets in class BucketBasedCacheStore
Throws:
CacheLoaderException

fromStreamLockSafe

protected void fromStreamLockSafe(ObjectInput objectInput)
                           throws CacheLoaderException
Specified by:
fromStreamLockSafe in class LockSupportCacheStore<Integer>
Throws:
CacheLoaderException

toStreamLockSafe

protected void toStreamLockSafe(ObjectOutput objectOutput)
                         throws CacheLoaderException
Specified by:
toStreamLockSafe in class LockSupportCacheStore<Integer>
Throws:
CacheLoaderException

clearLockSafe

protected void clearLockSafe()
                      throws CacheLoaderException
Specified by:
clearLockSafe in class LockSupportCacheStore<Integer>
Throws:
CacheLoaderException

purgeInternal

public void purgeInternal()
                   throws CacheLoaderException
Specified by:
purgeInternal in class AbstractCacheStore
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.

getConnectionFactory

public ConnectionFactory getConnectionFactory()

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

getTableManipulation

public TableManipulation getTableManipulation()

getMarshaller

protected StreamingMarshaller getMarshaller()
Overrides:
getMarshaller in class AbstractCacheStore

-->

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.