org.hibernate.cache.jbc.entity
Class OptimisticReadOnlyAccess

java.lang.Object
  extended by org.hibernate.cache.jbc.entity.TransactionalAccess
      extended by org.hibernate.cache.jbc.entity.OptimisticTransactionalAccess
          extended by org.hibernate.cache.jbc.entity.OptimisticReadOnlyAccess
All Implemented Interfaces:
EntityRegionAccessStrategy

public class OptimisticReadOnlyAccess
extends OptimisticTransactionalAccess

This defines the strategy for read-only access to enity data in an optimistic-locking JBossCache using its 2.x APIs

The read-only access to a JBossCache really is still transactional, just with the extra semantic or guarantee that we will not update data.

Author:
Brian Stansberry

Field Summary
 
Fields inherited from class org.hibernate.cache.jbc.entity.TransactionalAccess
region
 
Constructor Summary
OptimisticReadOnlyAccess(EntityRegionImpl region)
           
 
Method Summary
 boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
          Called after an item has been updated (after the transaction completes), instead of calling release().
 SoftLock lockItem(Object key, Object version)
          We are going to attempt to update/delete the keyed object.
 SoftLock lockRegion()
          Lock the entire region
 void unlockItem(Object key, SoftLock lock)
          Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.
 void unlockRegion(SoftLock lock)
          Called after we have finished the attempted invalidation of the entire region
 boolean update(Object key, Object value, Object currentVersion, Object previousVersion)
          Called after an item has been updated (before the transaction completes), instead of calling evict().
 
Methods inherited from class org.hibernate.cache.jbc.entity.TransactionalAccess
afterInsert, evict, evictAll, get, getRegion, insert, putFromLoad, putFromLoad, remove, removeAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptimisticReadOnlyAccess

public OptimisticReadOnlyAccess(EntityRegionImpl region)
Method Detail

lockItem

public SoftLock lockItem(Object key,
                         Object version)
                  throws CacheException
Description copied from interface: EntityRegionAccessStrategy
We are going to attempt to update/delete the keyed object. This method is used by "asynchronous" concurrency strategies.

The returned object must be passed back to release(), to release the lock. Concurrency strategies which do not support client-visible locks may silently return null.

Specified by:
lockItem in interface EntityRegionAccessStrategy
Overrides:
lockItem in class TransactionalAccess
Parameters:
key - The key of the item to lock
version - The item's current version value
Returns:
A representation of our lock on the item; or null.
Throws:
CacheException - Propogated from underlying Region

lockRegion

public SoftLock lockRegion()
                    throws CacheException
Description copied from interface: EntityRegionAccessStrategy
Lock the entire region

Specified by:
lockRegion in interface EntityRegionAccessStrategy
Overrides:
lockRegion in class TransactionalAccess
Returns:
A representation of our lock on the item; or null.
Throws:
CacheException - Propogated from underlying Region

unlockItem

public void unlockItem(Object key,
                       SoftLock lock)
                throws CacheException
Description copied from interface: EntityRegionAccessStrategy
Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion. This method is used by "asynchronous" concurrency strategies.

Specified by:
unlockItem in interface EntityRegionAccessStrategy
Overrides:
unlockItem in class TransactionalAccess
Parameters:
key - The item key
lock - The lock previously obtained from EntityRegionAccessStrategy.lockItem(java.lang.Object, java.lang.Object)
Throws:
CacheException - Propogated from underlying Region

unlockRegion

public void unlockRegion(SoftLock lock)
                  throws CacheException
Description copied from interface: EntityRegionAccessStrategy
Called after we have finished the attempted invalidation of the entire region

Specified by:
unlockRegion in interface EntityRegionAccessStrategy
Overrides:
unlockRegion in class TransactionalAccess
Parameters:
lock - The lock previously obtained from EntityRegionAccessStrategy.lockRegion()
Throws:
CacheException - Propogated from underlying Region

update

public boolean update(Object key,
                      Object value,
                      Object currentVersion,
                      Object previousVersion)
               throws CacheException
Description copied from interface: EntityRegionAccessStrategy
Called after an item has been updated (before the transaction completes), instead of calling evict(). This method is used by "synchronous" concurrency strategies.

Specified by:
update in interface EntityRegionAccessStrategy
Overrides:
update in class TransactionalAccess
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:
CacheException - Propogated from underlying Region

afterUpdate

public boolean afterUpdate(Object key,
                           Object value,
                           Object currentVersion,
                           Object previousVersion,
                           SoftLock lock)
                    throws CacheException
Description copied from interface: EntityRegionAccessStrategy
Called after an item has been updated (after the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.

Specified by:
afterUpdate in interface EntityRegionAccessStrategy
Overrides:
afterUpdate in class TransactionalAccess
Parameters:
key - The item key
value - The item
currentVersion - The item's current version value
previousVersion - The item's previous version value
lock - The lock previously obtained from EntityRegionAccessStrategy.lockItem(java.lang.Object, java.lang.Object)
Returns:
Were the contents of the cache actual changed by this operation?
Throws:
CacheException - Propogated from underlying Region


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.