ehcache

net.sf.ehcache.hibernate.strategy
Class ReadWriteEhcacheEntityRegionAccessStrategy

java.lang.Object
  extended by net.sf.ehcache.hibernate.strategy.ReadWriteEhcacheEntityRegionAccessStrategy
All Implemented Interfaces:
org.hibernate.cache.access.EntityRegionAccessStrategy

public class ReadWriteEhcacheEntityRegionAccessStrategy
extends Object
implements org.hibernate.cache.access.EntityRegionAccessStrategy

Ehcache specific read/write entity region access strategy

Author:
Chris Dennis

Nested Class Summary
protected static class AbstractReadWriteEhcacheAccessStrategy.Item
          Wrapper type representing unlocked items.
protected static class AbstractReadWriteEhcacheAccessStrategy.Lock
          Wrapper type representing locked items.
protected static interface AbstractReadWriteEhcacheAccessStrategy.Lockable
          Interface type implemented by all wrapper objects in the cache.
 
Field Summary
protected  T region
          The wrapped Hibernate cache region.
protected  org.hibernate.cfg.Settings settings
          The settings for this persistence unit.
 
Constructor Summary
ReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region, org.hibernate.cfg.Settings settings)
          Create a read/write access strategy accessing the given entity region.
 
Method Summary
 boolean afterInsert(Object key, Object value, Object version)
          
 boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, org.hibernate.cache.access.SoftLock lock)
          
protected  void decrementLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lock lock)
          Unlock and re-put the given key, lock combination.
 void evict(Object key)
          Remove the given mapping without regard to transactional safety
 void evictAll()
          Remove all mappings without regard to transactional safety
 Object get(Object key, long txTimestamp)
          Returns null if the item is not readable.
 org.hibernate.cache.EntityRegion getRegion()
          
protected  void handleMissingLock(Object key, AbstractReadWriteEhcacheAccessStrategy.Lockable lock)
          Handle the timeout of a previous lock mapped to this key
 boolean insert(Object key, Object value, Object version)
          A no-op since this is an asynchronous cache access strategy.
 org.hibernate.cache.access.SoftLock lockItem(Object key, Object version)
          Soft-lock a cache item.
 org.hibernate.cache.access.SoftLock lockRegion()
          Region locks are not supported.
 boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
          This method is a placeholder for method signatures supplied by interfaces pulled in further down the class hierarchy.
 boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
          Returns false and fails to put the value if there is an existing un-writeable item mapped to this key.
 void remove(Object key)
          A no-op since this is an asynchronous cache access strategy.
 void removeAll()
          Called to evict data from the entire region
 void unlockItem(Object key, org.hibernate.cache.access.SoftLock lock)
          Soft-unlock a cache item.
 void unlockRegion(org.hibernate.cache.access.SoftLock lock)
          Region locks are not supported - perform a cache clear as a precaution.
 boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
          A no-op since this is an asynchronous cache access strategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.cache.access.EntityRegionAccessStrategy
evict, evictAll, get, lockItem, lockRegion, putFromLoad, putFromLoad, remove, removeAll, unlockItem, unlockRegion
 

Field Detail

region

protected final T extends EhcacheTransactionalDataRegion region
The wrapped Hibernate cache region.


settings

protected final org.hibernate.cfg.Settings settings
The settings for this persistence unit.

Constructor Detail

ReadWriteEhcacheEntityRegionAccessStrategy

public ReadWriteEhcacheEntityRegionAccessStrategy(EhcacheEntityRegion region,
                                                  org.hibernate.cfg.Settings settings)
Create a read/write access strategy accessing the given entity region.

Method Detail

getRegion

public org.hibernate.cache.EntityRegion getRegion()

Specified by:
getRegion in interface org.hibernate.cache.access.EntityRegionAccessStrategy

insert

public boolean insert(Object key,
                      Object value,
                      Object version)
               throws org.hibernate.cache.CacheException
A no-op since this is an asynchronous cache access strategy.

Specified by:
insert in interface org.hibernate.cache.access.EntityRegionAccessStrategy
Throws:
org.hibernate.cache.CacheException

afterInsert

public boolean afterInsert(Object key,
                           Object value,
                           Object version)
                    throws org.hibernate.cache.CacheException

Inserts will only succeed if there is no existing value mapped to this key.

Specified by:
afterInsert in interface org.hibernate.cache.access.EntityRegionAccessStrategy
Throws:
org.hibernate.cache.CacheException

update

public boolean update(Object key,
                      Object value,
                      Object currentVersion,
                      Object previousVersion)
               throws org.hibernate.cache.CacheException
A no-op since this is an asynchronous cache access strategy.

Specified by:
update in interface org.hibernate.cache.access.EntityRegionAccessStrategy
Throws:
org.hibernate.cache.CacheException

afterUpdate

public boolean afterUpdate(Object key,
                           Object value,
                           Object currentVersion,
                           Object previousVersion,
                           org.hibernate.cache.access.SoftLock lock)
                    throws org.hibernate.cache.CacheException

Updates will only succeed if this entry was locked by this transaction and exclusively this transaction for the duration of this transaction. It is important to also note that updates will fail if the soft-lock expired during the course of this transaction.

Specified by:
afterUpdate in interface org.hibernate.cache.access.EntityRegionAccessStrategy
Throws:
org.hibernate.cache.CacheException

get

public final Object get(Object key,
                        long txTimestamp)
                 throws org.hibernate.cache.CacheException
Returns null if the item is not readable. Locked items are not readable, nor are items created after the start of this transaction.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.get(java.lang.Object, long), CollectionRegionAccessStrategy.get(java.lang.Object, long)

putFromLoad

public final boolean putFromLoad(Object key,
                                 Object value,
                                 long txTimestamp,
                                 Object version,
                                 boolean minimalPutOverride)
                          throws org.hibernate.cache.CacheException
Returns false and fails to put the value if there is an existing un-writeable item mapped to this key.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean), CollectionRegionAccessStrategy.putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean)

lockItem

public final org.hibernate.cache.access.SoftLock lockItem(Object key,
                                                          Object version)
                                                   throws org.hibernate.cache.CacheException
Soft-lock a cache item.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.lockItem(java.lang.Object, java.lang.Object), CollectionRegionAccessStrategy.lockItem(java.lang.Object, java.lang.Object)

unlockItem

public final void unlockItem(Object key,
                             org.hibernate.cache.access.SoftLock lock)
                      throws org.hibernate.cache.CacheException
Soft-unlock a cache item.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.unlockItem(java.lang.Object, org.hibernate.cache.access.SoftLock), CollectionRegionAccessStrategy.unlockItem(java.lang.Object, org.hibernate.cache.access.SoftLock)

decrementLock

protected void decrementLock(Object key,
                             AbstractReadWriteEhcacheAccessStrategy.Lock lock)
Unlock and re-put the given key, lock combination.


handleMissingLock

protected void handleMissingLock(Object key,
                                 AbstractReadWriteEhcacheAccessStrategy.Lockable lock)
Handle the timeout of a previous lock mapped to this key


putFromLoad

public final boolean putFromLoad(Object key,
                                 Object value,
                                 long txTimestamp,
                                 Object version)
                          throws org.hibernate.cache.CacheException
This method is a placeholder for method signatures supplied by interfaces pulled in further down the class hierarchy.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object), CollectionRegionAccessStrategy.putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)

lockRegion

public final org.hibernate.cache.access.SoftLock lockRegion()
Region locks are not supported.

Returns:
null
See Also:
EntityRegionAccessStrategy.lockRegion(), CollectionRegionAccessStrategy.lockRegion()

unlockRegion

public final void unlockRegion(org.hibernate.cache.access.SoftLock lock)
                        throws org.hibernate.cache.CacheException
Region locks are not supported - perform a cache clear as a precaution.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.unlockRegion(org.hibernate.cache.access.SoftLock), CollectionRegionAccessStrategy.unlockRegion(org.hibernate.cache.access.SoftLock)

remove

public void remove(Object key)
            throws org.hibernate.cache.CacheException
A no-op since this is an asynchronous cache access strategy.

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.remove(java.lang.Object), CollectionRegionAccessStrategy.remove(java.lang.Object)

removeAll

public final void removeAll()
                     throws org.hibernate.cache.CacheException
Called to evict data from the entire region

Throws:
org.hibernate.cache.CacheException - Propogated from underlying Region
See Also:
EntityRegionAccessStrategy.removeAll(), CollectionRegionAccessStrategy.removeAll()

evict

public final void evict(Object key)
                 throws org.hibernate.cache.CacheException
Remove the given mapping without regard to transactional safety

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.evict(java.lang.Object), CollectionRegionAccessStrategy.evict(java.lang.Object)

evictAll

public final void evictAll()
                    throws org.hibernate.cache.CacheException
Remove all mappings without regard to transactional safety

Throws:
org.hibernate.cache.CacheException
See Also:
EntityRegionAccessStrategy.evictAll(), CollectionRegionAccessStrategy.evictAll()

ehcache

Copyright © 2003-2014 Terracotta, Inc.. All Rights Reserved.