CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.coherence.hibernate
Class CoherenceCache

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.coherence.hibernate.CoherenceCache
All Implemented Interfaces:
org.hibernate.cache.Cache

public class CoherenceCache
extends Base
implements org.hibernate.cache.Cache

Provides a cache wrapper for storing Hibernate objects in Coherence NamedCache instances.

Author:
jp 2005.08.31, jh 2005.08.31

Field Summary
protected static int DEFAULT_LOCK_LEASE_MILLIS
          The default lock lease millis
protected static int DEFAULT_LOCK_OBTAIN_MILLIS
          The default lock attempt millis
static String LOCK_LEASE_TIMEOUT
          The system property specifying the lock lease timeout
static String LOCK_OBTAIN_TIMEOUT
          The system property specifying the lock acquisition timeout
 
Constructor Summary
CoherenceCache(NamedCache cache, Properties properties)
          Construct a Hibernate cache instance.
 
Method Summary
 void clear()
          Clear the entire cache.
 void destroy()
          Release local (JVM) resources associated with this cache.
 Object get(Object oKey)
          Get an object from the cache.
 long getElementCountInMemory()
          Get the size of the cache in memory (object count)
 long getElementCountOnDisk()
          Get the size of the cache on disk (object count)
protected  int getLockLeaseTimeout()
          Get the timeout (in millis) for lock leases.
protected  int getLockObtainTimeout()
          Get the timeout (in millis) for lock acquisition attempts.
 String getRegionName()
          Get the region (cache) name.
 long getSizeInMemory()
          Get the size of the cache in memory (byte count)
 int getTimeout()
          Get the lock timeout (lease duration, not lock acquisition).
protected  long getTimeProperty(Properties properties, String sPropertyName, long cDefaultMillis, long cMaxMillis)
          Get an adjusted time (duration) property
 void lock(Object oKey)
          Lock a key.
 long nextTimestamp()
          Get the current timestamp (in millis).
 void put(Object oKey, Object oValue)
          Put an object into the cache.
 Object read(Object oKey)
          Get an object from the cache.
 void remove(Object oKey)
          Remove an object from the cache.
 Map toMap()
          Get a Map instance representing the contents of the cache.
 void unlock(Object oKey)
          Unlock a key.
 void update(Object oKey, Object oValue)
          Update an item in the cache.
 

Field Detail

LOCK_OBTAIN_TIMEOUT

public static final String LOCK_OBTAIN_TIMEOUT
The system property specifying the lock acquisition timeout

See Also:
Constant Field Values

DEFAULT_LOCK_OBTAIN_MILLIS

protected static final int DEFAULT_LOCK_OBTAIN_MILLIS
The default lock attempt millis

See Also:
Constant Field Values

LOCK_LEASE_TIMEOUT

public static final String LOCK_LEASE_TIMEOUT
The system property specifying the lock lease timeout

See Also:
Constant Field Values

DEFAULT_LOCK_LEASE_MILLIS

protected static final int DEFAULT_LOCK_LEASE_MILLIS
The default lock lease millis

See Also:
Constant Field Values
Constructor Detail

CoherenceCache

public CoherenceCache(NamedCache cache,
                      Properties properties)
Construct a Hibernate cache instance.

Parameters:
cache - the Coherence NamedCache instance that provides the actual data storage
properties - the configuration properties
Method Detail

get

public Object get(Object oKey)
Get an object from the cache.

Specified by:
get in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key
Returns:
the cache value

read

public Object read(Object oKey)
Get an object from the cache.

Specified by:
read in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key
Returns:
the cache value

put

public void put(Object oKey,
                Object oValue)
Put an object into the cache.

Specified by:
put in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key
oValue - the cache value

remove

public void remove(Object oKey)
Remove an object from the cache.

Specified by:
remove in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key

clear

public void clear()
Clear the entire cache.

Specified by:
clear in interface org.hibernate.cache.Cache

destroy

public void destroy()
Release local (JVM) resources associated with this cache.

Specified by:
destroy in interface org.hibernate.cache.Cache

getTimeout

public int getTimeout()
Get the lock timeout (lease duration, not lock acquisition).

Specified by:
getTimeout in interface org.hibernate.cache.Cache
Returns:
the lock timeout in millis

nextTimestamp

public long nextTimestamp()
Get the current timestamp (in millis).

Specified by:
nextTimestamp in interface org.hibernate.cache.Cache
Returns:
the current timestamp

lock

public void lock(Object oKey)
Lock a key.

Specified by:
lock in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key
Throws:
org.hibernate.cache.CacheException - if lock acquisition times out

unlock

public void unlock(Object oKey)
Unlock a key.

Specified by:
unlock in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key

update

public void update(Object oKey,
                   Object oValue)
Update an item in the cache.

Specified by:
update in interface org.hibernate.cache.Cache
Parameters:
oKey - the cache key
oValue - the cache value

getRegionName

public String getRegionName()
Get the region (cache) name.

Specified by:
getRegionName in interface org.hibernate.cache.Cache
Returns:
the region (cache) name.

getSizeInMemory

public long getSizeInMemory()
Get the size of the cache in memory (byte count)

Not supported (returns -1).

Note: Used only by the Cache Statistics package

Specified by:
getSizeInMemory in interface org.hibernate.cache.Cache
Returns:
the number of bytes used by the cache

getElementCountInMemory

public long getElementCountInMemory()
Get the size of the cache in memory (object count)

Not supported (returns total cache size, including disk).

Note: Used only by the Cache Statistics package

Specified by:
getElementCountInMemory in interface org.hibernate.cache.Cache
Returns:
the number of objects in the cache that are in RAM

getElementCountOnDisk

public long getElementCountOnDisk()
Get the size of the cache on disk (object count)

Not supported (returns -1).

Note: Used only by the Cache Statistics package

Specified by:
getElementCountOnDisk in interface org.hibernate.cache.Cache
Returns:
the number of objects in the cache that are on disk

toMap

public Map toMap()
Get a Map instance representing the contents of the cache.

This implementation simply returns the Coherence NamedCache instance.

Specified by:
toMap in interface org.hibernate.cache.Cache
Returns:
the Map representation of the cache

getLockObtainTimeout

protected int getLockObtainTimeout()
Get the timeout (in millis) for lock acquisition attempts.

Returns:
the timeout (in millis)

getLockLeaseTimeout

protected int getLockLeaseTimeout()
Get the timeout (in millis) for lock leases.

Returns:
the timeout (in millis)

getTimeProperty

protected long getTimeProperty(Properties properties,
                               String sPropertyName,
                               long cDefaultMillis,
                               long cMaxMillis)
Get an adjusted time (duration) property

Parameters:
properties - the property set containing the property
sPropertyName - the name of the property
cDefaultMillis - the default value (in milliseconds)
cMaxMillis - the maximum value (saturating, in milliseconds)
Returns:
the time value

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation