com.hazelcast.hibernate.access
Class AbstractAccessDelegate<T extends HazelcastRegion>

java.lang.Object
  extended by com.hazelcast.hibernate.access.AbstractAccessDelegate<T>
Type Parameters:
T - implementation type of HazelcastRegion
All Implemented Interfaces:
AccessDelegate<T>
Direct Known Subclasses:
NonStrictReadWriteAccessDelegate, ReadWriteAccessDelegate

public abstract class AbstractAccessDelegate<T extends HazelcastRegion>
extends Object
implements AccessDelegate<T>

Base implementation for consistency guarantees

Author:
Leo Kim (lkim@limewire.com)

Field Summary
protected  RegionCache cache
           
protected  T hazelcastRegion
           
protected  ILogger log
           
protected  Comparator<Object> versionComparator
           
 
Constructor Summary
protected AbstractAccessDelegate(T hazelcastRegion, Properties props)
           
 
Method Summary
 void evict(Object key)
          Forcibly evict an item from the cache immediately without regard for transaction isolation.
 void evictAll()
          Forcibly evict all items from the cache immediately without regard for transaction isolation.
 Object get(Object key, long txTimestamp)
          Attempt to retrieve an object from the cache.
 T getHazelcastRegion()
          Get the wrapped cache region
 boolean insert(Object key, Object value, Object version)
          This is an asynchronous cache access strategy.
 SoftLock lockRegion()
          NO-OP
protected  boolean put(Object key, Object value, Object currentVersion)
           
 boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
          Attempt to cache an object, after loading from the database.
 void remove(Object key)
          Called after an item has become stale (before the transaction completes).
 void removeAll()
          Called to evict data from the entire region
 void unlockRegion(SoftLock lock)
          NO-OP
 boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
          This is an asynchronous cache access strategy.
protected  boolean update(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.hazelcast.hibernate.access.AccessDelegate
afterInsert, afterUpdate, lockItem, putFromLoad, unlockItem
 

Field Detail

log

protected final ILogger log

hazelcastRegion

protected final T extends HazelcastRegion hazelcastRegion

cache

protected final RegionCache cache

versionComparator

protected final Comparator<Object> versionComparator
Constructor Detail

AbstractAccessDelegate

protected AbstractAccessDelegate(T hazelcastRegion,
                                 Properties props)
Method Detail

getHazelcastRegion

public final T getHazelcastRegion()
Description copied from interface: AccessDelegate
Get the wrapped cache region

Specified by:
getHazelcastRegion in interface AccessDelegate<T extends HazelcastRegion>
Returns:
The underlying region

put

protected boolean put(Object key,
                      Object value,
                      Object currentVersion)

update

protected boolean update(Object key,
                         Object value,
                         Object currentVersion,
                         Object previousVersion,
                         SoftLock lock)

get

public Object get(Object key,
                  long txTimestamp)
           throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.

Specified by:
get in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The key of the item to be retrieved.
txTimestamp - a timestamp prior to the transaction start time
Returns:
the cached object or null
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

putFromLoad

public boolean putFromLoad(Object key,
                           Object value,
                           long txTimestamp,
                           Object version)
                    throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Attempt to cache an object, after loading from the database.

Specified by:
putFromLoad in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The item key
value - The item
txTimestamp - a timestamp prior to the transaction start time
version - the item version number
Returns:
true if the object was successfully cached
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

remove

public void remove(Object key)
            throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Called after an item has become stale (before the transaction completes). This method is used by "synchronous" concurrency strategies.

Specified by:
remove in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The key of the item to remove
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

removeAll

public void removeAll()
               throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Called to evict data from the entire region

Specified by:
removeAll in interface AccessDelegate<T extends HazelcastRegion>
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

evict

public void evict(Object key)
           throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Forcibly evict an item from the cache immediately without regard for transaction isolation.

Specified by:
evict in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The key of the item to remove
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

evictAll

public void evictAll()
              throws org.hibernate.cache.CacheException
Description copied from interface: AccessDelegate
Forcibly evict all items from the cache immediately without regard for transaction isolation.

Specified by:
evictAll in interface AccessDelegate<T extends HazelcastRegion>
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

lockRegion

public SoftLock lockRegion()
                    throws org.hibernate.cache.CacheException
NO-OP

Specified by:
lockRegion in interface AccessDelegate<T extends HazelcastRegion>
Returns:
A representation of our lock on the item; or null.
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

unlockRegion

public void unlockRegion(SoftLock lock)
                  throws org.hibernate.cache.CacheException
NO-OP

Specified by:
unlockRegion in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
lock - The lock previously obtained from AccessDelegate.lockRegion()
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

insert

public boolean insert(Object key,
                      Object value,
                      Object version)
               throws org.hibernate.cache.CacheException
This is an asynchronous cache access strategy. NO-OP

Specified by:
insert in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The item key
value - The item
version - The item's version value
Returns:
Were the contents of the cache actual changed by this operation?
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region

update

public boolean update(Object key,
                      Object value,
                      Object currentVersion,
                      Object previousVersion)
               throws org.hibernate.cache.CacheException
This is an asynchronous cache access strategy. NO-OP

Specified by:
update in interface AccessDelegate<T extends HazelcastRegion>
Parameters:
key - The item key
value - The item
currentVersion - The item's current version value
previousVersion - The item's previous version value
Returns:
Were the contents of the cache actual changed by this operation?
Throws:
org.hibernate.cache.CacheException - Propogated from underlying org.hibernate.cache.Region


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.