com.gigaspaces.hibernate
Class HibernateCacheStoreImpl

java.lang.Object
  extended by com.gigaspaces.hibernate.HibernateCacheLoaderImpl
      extended by com.gigaspaces.hibernate.HibernateCacheStoreImpl
All Implemented Interfaces:
CacheBulk, CacheIteratorFactory, CacheLifeCycleManager, CacheLoader, CacheStore

public class HibernateCacheStoreImpl
extends HibernateCacheLoaderImpl
implements CacheStore, CacheBulk

The HibernateCacheStoreImpl used to delgate changes done within GigaSpaces into external database via Hibernate 3.0 ORM.
When a matching entry is not found in the space the HibernateCacheStoreImpl is called to load the data from the database.
When data is written/put/taken/removed/updated HibernateCacheStoreImpl is responsible to perform the relevant changes at the external database.
See the CacheLoader , CacheIteratorFactory , CacheStore and CacheBulk for full description of the methods mapping between the Map/Space API and the HibernateCacheStoreImpl methods.

Configuration
To use the HibernateCacheStoreImpl the space schema XML configuration file should include the following. 
<space-config> <persistent> <enabled>true</enabled> <StorageAdapterClass>com.j_spaces.sadapter.cache.CacheAdapter</StorageAdapterClass> <CacheLoaderClass>com.gigaspaces.hibernate.HibernateCacheStoreImpl</CacheLoaderClass> <StorageAdapterURL>/config/</StorageAdapterURL> </persistent> <engine> <cache_policy>0</cache_policy> </engine> </space-config>


You may also use the following space properties: space-config.persistent.enabled=true space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.cache.CacheAdapter space-config.persistent.CacheLoaderClass=com.gigaspaces.hibernate.HibernateCacheStoreImpl space-config.engine.cache_policy=0 space-config.persistent.StorageAdapterURL= hibernate.cfg.xml location
When using the HibernateCacheLoaderImpl or HibernateCacheStoreImpl the space-config.persistent.StorageAdapterURL will be used to locate Hibernate hibernate.cfg.xml configuration mapping file. You must use space-config.engine.cache_policy=0 (LRU policy) to activate the CacheStore and CacheLoader implementation.
It is recommended to configure also the following to control the space memory usage and the eviction behavior:
space-config.engine.memory_usage.enabled=true
space-config.engine.memory_usage.high_watermark_percentage=95
space-config.engine.memory_usage.write_only_block_percentage=85
space-config.engine.memory_usage.write_only_check_percentage=76
space-config.engine.memory_usage.low_watermark_percentage=75
space-config.engine.memory_usage.eviction_batch_size=500

Note that only one, CacheLoader or CacheStore, but not both, is allowed to be used since CacheStore extends CacheLoader interface.

Since:
5.1

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.j_spaces.javax.cache.CacheBulk
CacheBulk.BulkEntry
 
Nested classes/interfaces inherited from interface com.j_spaces.javax.cache.CacheLifeCycleManager
CacheLifeCycleManager.LifeCycleProperty
 
Field Summary
 
Fields inherited from interface com.j_spaces.javax.cache.CacheBulk
ERASE, STORE
 
Constructor Summary
HibernateCacheStoreImpl()
           
 
Method Summary
 void erase(Object key)
          Remove the specified key from the underlying store if present.
 void eraseAll()
          called when space is cleaned - this might clean all secondary data storage.
 void eraseAll(Collection keys)
          Remove the specified keys from the underlying store if present
 void store(List<CacheBulk.BulkEntry> bulk)
          This method is called in the following scenarios: 1.
 void store(Object key, Object value)
          Store the specified values under the specified keys in the store.
 void storeAll(Map map)
          Store the specified values under the specified keys in the underlying store.
 
Methods inherited from class com.gigaspaces.hibernate.HibernateCacheLoaderImpl
dropTable, init, iterator, load, loadAll, shutdown
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.j_spaces.javax.cache.CacheLoader
load, loadAll
 

Constructor Detail

HibernateCacheStoreImpl

public HibernateCacheStoreImpl()
Method Detail

store

public void store(Object key,
                  Object value)
Store the specified values under the specified keys in the store. This method should support both create and update for the specified key.

Specified by:
store in interface CacheStore
Parameters:
key - key to store the value under
value - value to be stored

storeAll

public void storeAll(Map map)
Store the specified values under the specified keys in the underlying store. This method is intended to support both key/value creation and value update for the specified keys.

Specified by:
storeAll in interface CacheStore
Parameters:
map - a Map of any number of keys and values to store

erase

public void erase(Object key)
Remove the specified key from the underlying store if present.

Specified by:
erase in interface CacheStore
Parameters:
key - key whose mapping is being removed from the cache

eraseAll

public void eraseAll(Collection keys)
Remove the specified keys from the underlying store if present

Specified by:
eraseAll in interface CacheStore
Parameters:
keys - keys whose mappings are being removed from the cache

eraseAll

public void eraseAll()
called when space is cleaned - this might clean all secondary data storage.


store

public void store(List<CacheBulk.BulkEntry> bulk)
This method is called in the following scenarios:

1. Transaction commit
2. Asynchronize persistency mode This method can throw RuntimeException. This exception will be delivered to the client application wrapped by com.j_spaces.javax.cache.CacheException

Specified by:
store in interface CacheBulk
Parameters:
bulk - This bulkSet contains set of BulkEntry