com.atlassian.confluence.cache.tangosol.hibernate
Class CoherenceCacheStrategy

java.lang.Object
  extended by com.atlassian.confluence.cache.tangosol.hibernate.CoherenceCacheStrategy
All Implemented Interfaces:
net.sf.hibernate.cache.CacheConcurrencyStrategy

public class CoherenceCacheStrategy
extends java.lang.Object
implements net.sf.hibernate.cache.CacheConcurrencyStrategy

This class is a copied from ReadWriteCache. The difference is that this class doesn't synchronize on a method level and instead of explicitly calling lock->operation->unlock on the underlying cache it makes use of Coherence's InvocableMap.EntryProcessor to reduce the amount of network requests. This implementation only works with the CoherenceInvokableHibernateCache.


Nested Class Summary
static class CoherenceCacheStrategy.Item
          An item of cached data, timestamped with the time it was cached,.
static class CoherenceCacheStrategy.Lock
          A soft lock which supports concurrent locking, timestamped with the time it was released
static interface CoherenceCacheStrategy.Lockable
           
 
Nested classes/interfaces inherited from interface net.sf.hibernate.cache.CacheConcurrencyStrategy
net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock
 
Constructor Summary
CoherenceCacheStrategy()
           
 
Method Summary
 void afterInsert(java.lang.Object key, java.lang.Object value, java.lang.Object version)
          Add the new item to the cache, checking that no other transaction has accessed the item.
 void afterUpdate(java.lang.Object key, java.lang.Object value, java.lang.Object version, net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock clientLock)
          Re-cache the updated state, if and only if there there are no other concurrent soft locks.
 void clear()
           
 void destroy()
           
 void evict(java.lang.Object key)
          Do nothing.
 java.lang.Object get(java.lang.Object key, long txTimestamp)
          Do not return an item whose timestamp is later than the current transaction timestamp.
 void insert(java.lang.Object key, java.lang.Object value)
          Do nothing.
 net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock lock(java.lang.Object key, java.lang.Object version)
          Stop any other transactions reading or writing this item to/from the cache.
 boolean put(java.lang.Object key, java.lang.Object value, long txTimestamp, java.lang.Object version, java.util.Comparator versionComparator)
          Do not add an item to the cache unless the current transaction timestamp is later than the timestamp at which the item was invalidated.
 void release(java.lang.Object key, net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock clientLock)
          Release the soft lock on the item.
 void remove(java.lang.Object key)
           
 void setCache(net.sf.hibernate.cache.Cache cache)
           
 void setMinimalPuts(boolean minimalPuts)
           
 void update(java.lang.Object key, java.lang.Object value)
          Do nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoherenceCacheStrategy

public CoherenceCacheStrategy()
Method Detail

setCache

public void setCache(net.sf.hibernate.cache.Cache cache)
Specified by:
setCache in interface net.sf.hibernate.cache.CacheConcurrencyStrategy

get

public java.lang.Object get(java.lang.Object key,
                            long txTimestamp)
                     throws net.sf.hibernate.cache.CacheException
Do not return an item whose timestamp is later than the current transaction timestamp. (Otherwise we might compromise repeatable read unnecessarily.) Do not return an item which is soft-locked. Always go straight to the database instead.

Note that since reading an item from that cache does not actually go to the database, it is possible to see a kind of phantom read due to the underlying row being updated after we have read it from the cache. This would not be possible in a lock-based implementation of repeatable read isolation. It is also possible to overwrite changes made and committed by another transaction after the current transaction read the item from the cache. This problem would be caught by the update-time version-checking, if the data is versioned or timestamped.

Specified by:
get in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

lock

public net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock lock(java.lang.Object key,
                                                                     java.lang.Object version)
                                                              throws net.sf.hibernate.cache.CacheException
Stop any other transactions reading or writing this item to/from the cache. Send them straight to the database instead. (The lock does time out eventually.) This implementation tracks concurrent locks my transactions which simultaneously attempt to write to an item.

Specified by:
lock in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

put

public boolean put(java.lang.Object key,
                   java.lang.Object value,
                   long txTimestamp,
                   java.lang.Object version,
                   java.util.Comparator versionComparator)
            throws net.sf.hibernate.cache.CacheException
Do not add an item to the cache unless the current transaction timestamp is later than the timestamp at which the item was invalidated. (Otherwise, a stale item might be re-added if the database is operating in repeatable read isolation mode.)

Specified by:
put in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

release

public void release(java.lang.Object key,
                    net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock clientLock)
             throws net.sf.hibernate.cache.CacheException
Release the soft lock on the item. Other transactions may now re-cache the item (assuming that no other transaction holds a simultaneous lock).

Specified by:
release in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

clear

public void clear()
           throws net.sf.hibernate.cache.CacheException
Specified by:
clear in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

remove

public void remove(java.lang.Object key)
            throws net.sf.hibernate.cache.CacheException
Specified by:
remove in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

destroy

public void destroy()
Specified by:
destroy in interface net.sf.hibernate.cache.CacheConcurrencyStrategy

afterUpdate

public void afterUpdate(java.lang.Object key,
                        java.lang.Object value,
                        java.lang.Object version,
                        net.sf.hibernate.cache.CacheConcurrencyStrategy.SoftLock clientLock)
                 throws net.sf.hibernate.cache.CacheException
Re-cache the updated state, if and only if there there are no other concurrent soft locks. Release our lock.

Specified by:
afterUpdate in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

afterInsert

public void afterInsert(java.lang.Object key,
                        java.lang.Object value,
                        java.lang.Object version)
                 throws net.sf.hibernate.cache.CacheException
Add the new item to the cache, checking that no other transaction has accessed the item.

Specified by:
afterInsert in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

evict

public void evict(java.lang.Object key)
           throws net.sf.hibernate.cache.CacheException
Do nothing.

Specified by:
evict in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

insert

public void insert(java.lang.Object key,
                   java.lang.Object value)
            throws net.sf.hibernate.cache.CacheException
Do nothing.

Specified by:
insert in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

update

public void update(java.lang.Object key,
                   java.lang.Object value)
            throws net.sf.hibernate.cache.CacheException
Do nothing.

Specified by:
update in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.cache.CacheException

setMinimalPuts

public void setMinimalPuts(boolean minimalPuts)
                    throws net.sf.hibernate.HibernateException
Specified by:
setMinimalPuts in interface net.sf.hibernate.cache.CacheConcurrencyStrategy
Throws:
net.sf.hibernate.HibernateException


Copyright © 2003-2010 Atlassian. All Rights Reserved.