net.sf.ehcache.openjpa.datacache
Class EhCacheDataCache

java.lang.Object
  extended by org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
      extended by org.apache.openjpa.datacache.AbstractDataCache
          extended by net.sf.ehcache.openjpa.datacache.EhCacheDataCache
All Implemented Interfaces:
java.io.Serializable, org.apache.openjpa.datacache.DataCache, org.apache.openjpa.lib.conf.Configurable, org.apache.openjpa.lib.util.Closeable, org.apache.openjpa.lib.util.EventManager

public class EhCacheDataCache
extends org.apache.openjpa.datacache.AbstractDataCache
implements org.apache.openjpa.datacache.DataCache

A plug-in L2 Cache for OpenJPA to use EhCache.

This cache maintains a set of Ehcaches per-class basis. The name of the NamedCache for a persistence class C is determined by the @DataCache annotation in the class C. If no name is specified in @DataCache annotation then a default name is used. The default name is openjpa but can be configured via this plug-in's DefaultName property unless UseDefaultForUnnamedCaches is set to false.

Author:
Pinaki Poddar, Craig Andrews, Greg Luck
See Also:
Serialized Form

Field Summary
protected  java.util.Map<java.lang.Class,net.sf.ehcache.Ehcache> caches
           
protected  java.lang.String defaultName
           
protected static org.apache.openjpa.lib.util.Localizer LOCALIZER
           
protected  boolean useDefaultForUnnamedCaches
           
protected  java.util.concurrent.locks.ReentrantLock writeLock
           
 
Fields inherited from class org.apache.openjpa.datacache.AbstractDataCache
conf, log
 
Fields inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
_listeners
 
Fields inherited from interface org.apache.openjpa.datacache.DataCache
NAME_DEFAULT
 
Constructor Summary
EhCacheDataCache()
           
 
Method Summary
protected  void clearInternal()
          Clears all entries from the cache
protected  java.lang.Class determineClassFromObjectId(java.lang.Object oid)
           
protected  net.sf.ehcache.Ehcache findCache(java.lang.Class clazz)
          Find an Ehcache for the given Class.
 java.lang.String getDefaultName()
          Gets the default name for the Ehcache used for classes which do not specify explicitly a name in its @DataCache annotation.
protected  org.apache.openjpa.datacache.DataCachePCData getInternal(java.lang.Object oid)
           
protected  net.sf.ehcache.Ehcache getOrCreateCache(java.lang.String name)
          Gets a cache.
 boolean isUseDefaultForUnnamedCaches()
          Asserts if default name will be used for the Ehcache for classes which do not specify explicitly a name in its @DataCache annotation.
protected  boolean pinInternal(java.lang.Object oid)
          Pinning is is not implemented in this version
protected  org.apache.openjpa.datacache.DataCachePCData putInternal(java.lang.Object oid, org.apache.openjpa.datacache.DataCachePCData pc)
           
protected  void removeAllInternal(java.lang.Class cls, boolean subclasses)
           
protected  org.apache.openjpa.datacache.DataCachePCData removeInternal(java.lang.Object oid)
           
 void setDefaultName(java.lang.String defaultName)
          Sets the default name for the Ehcache used for classes which do not specify explicitly a name in its @DataCache annotation.
 void setUseDefaultForUnnamedCaches(boolean flag)
          Sets if default name will be used for the Ehcache for classes which do not specify explicitly a name in its @DataCache annotation.
protected  boolean unpinInternal(java.lang.Object oid)
          Pinning and unpinning are not implemented in this version
 void writeLock()
           
 void writeUnlock()
           
 
Methods inherited from class org.apache.openjpa.datacache.AbstractDataCache
addExpirationListener, afterCommit, clear, close, close, commit, contains, containsAll, endConfiguration, fireEvent, get, getAll, getEvictionSchedule, getName, initialize, isClosed, keyRemoved, pin, pinAll, pinAll, put, putAllInternal, recacheUpdates, remove, removeAll, removeAll, removeAllInternal, removeAllTypeNamesInternal, removeExpirationListener, setConfiguration, setEvictionSchedule, setName, startConfiguration, toString, unpin, unpinAll, unpinAll, update
 
Methods inherited from class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
addListener, fireEvent, getListeners, hasListener, hasListeners, isFailFast, newListenerCollection, removeListener, setFailFast
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.openjpa.datacache.DataCache
addExpirationListener, clear, close, commit, contains, containsAll, get, getAll, getName, initialize, pin, pinAll, pinAll, put, remove, removeAll, removeAll, removeExpirationListener, setName, unpin, unpinAll, unpinAll, update
 

Field Detail

LOCALIZER

protected static final org.apache.openjpa.lib.util.Localizer LOCALIZER

caches

protected final java.util.Map<java.lang.Class,net.sf.ehcache.Ehcache> caches

useDefaultForUnnamedCaches

protected boolean useDefaultForUnnamedCaches

defaultName

protected java.lang.String defaultName

writeLock

protected java.util.concurrent.locks.ReentrantLock writeLock
Constructor Detail

EhCacheDataCache

public EhCacheDataCache()
Method Detail

isUseDefaultForUnnamedCaches

public boolean isUseDefaultForUnnamedCaches()
Asserts if default name will be used for the Ehcache for classes which do not specify explicitly a name in its @DataCache annotation. The default value for this flag is true


setUseDefaultForUnnamedCaches

public void setUseDefaultForUnnamedCaches(boolean flag)
Sets if default name will be used for the Ehcache for classes which do not specify explicitly a name in its @DataCache annotation. The default value for this flag is true


getDefaultName

public java.lang.String getDefaultName()
Gets the default name for the Ehcache used for classes which do not specify explicitly a name in its @DataCache annotation. The default name is openjpa


setDefaultName

public void setDefaultName(java.lang.String defaultName)
Sets the default name for the Ehcache used for classes which do not specify explicitly a name in its @DataCache annotation. The default name is openjpa


clearInternal

protected void clearInternal()
Clears all entries from the cache

Specified by:
clearInternal in class org.apache.openjpa.datacache.AbstractDataCache

getInternal

protected org.apache.openjpa.datacache.DataCachePCData getInternal(java.lang.Object oid)
Specified by:
getInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
oid -
Returns:

pinInternal

protected boolean pinInternal(java.lang.Object oid)
Pinning is is not implemented in this version

Specified by:
pinInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
oid -
Returns:

putInternal

protected org.apache.openjpa.datacache.DataCachePCData putInternal(java.lang.Object oid,
                                                                   org.apache.openjpa.datacache.DataCachePCData pc)
Specified by:
putInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
oid -
pc -
Returns:

removeAllInternal

protected void removeAllInternal(java.lang.Class cls,
                                 boolean subclasses)
Specified by:
removeAllInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
cls -
subclasses -

removeInternal

protected org.apache.openjpa.datacache.DataCachePCData removeInternal(java.lang.Object oid)
Specified by:
removeInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
oid -
Returns:

unpinInternal

protected boolean unpinInternal(java.lang.Object oid)
Pinning and unpinning are not implemented in this version

Specified by:
unpinInternal in class org.apache.openjpa.datacache.AbstractDataCache
Parameters:
oid -
Returns:

writeLock

public void writeLock()
Specified by:
writeLock in interface org.apache.openjpa.datacache.DataCache

writeUnlock

public void writeUnlock()
Specified by:
writeUnlock in interface org.apache.openjpa.datacache.DataCache

findCache

protected net.sf.ehcache.Ehcache findCache(java.lang.Class clazz)
Find an Ehcache for the given Class. Makes all the following attempt in order to find a cache and if every attempt fails returns null:

  • NamedCache for the given class has been obtained before
  • Meta-data for the given class annotated for a DataCache.
  • Configured to use default cache.


  • getOrCreateCache

    protected net.sf.ehcache.Ehcache getOrCreateCache(java.lang.String name)
    Gets a cache. If the cache does not exist it is created using a hardcoded default.

    Parameters:
    name -
    Returns:

    determineClassFromObjectId

    protected java.lang.Class determineClassFromObjectId(java.lang.Object oid)
    Parameters:
    oid -
    Returns:


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