org.apache.openjpa.jdbc.kernel
Class FinderCacheImpl

java.lang.Object
  extended by org.apache.openjpa.jdbc.kernel.FinderCacheImpl
All Implemented Interfaces:
FinderCache<ClassMapping,SelectExecutor,Result>, Configurable

public class FinderCacheImpl
extends Object
implements FinderCache<ClassMapping,SelectExecutor,Result>

Implementation of FinderCache for JDBC.

Since:
2.0.0
Author:
Pinaki Poddar

Constructor Summary
FinderCacheImpl()
           
 
Method Summary
 void addExclusionPattern(String pattern)
          Adds a pattern for exclusion.
 FinderQuery<ClassMapping,SelectExecutor,Result> cache(ClassMapping mapping, SelectExecutor select, FetchConfiguration fetch)
          Cache a Finder Query for the given mapping and select.
 void endConfiguration()
          Invoked upon completion of bean property configuration for this object.
 FinderQuery<ClassMapping,SelectExecutor,Result> get(ClassMapping mapping, FetchConfiguration fetch)
          Gets the finder query for the given mapping.
 boolean getEnableStats()
           
 List<String> getExcludes()
          Gets the excluded stringified keys.
 Map<String,String> getMapView()
          Get a map-oriented view of the cache.
 QueryStatistics<ClassMapping> getStatistics()
          Gets basic statistics of execution and hit count of finder queries.
 boolean invalidate(ClassMapping mapping)
          Remove the FinderQuery for the given key from this cache.
 boolean isExcluded(ClassMapping mapping)
          Affirms if the given mapping is excluded from being cached.
(package private)  boolean isHinted(FetchConfiguration fetch, String hint)
           
(package private)  void lock()
           
 FinderQuery<ClassMapping,SelectExecutor,Result> markUncachable(ClassMapping mapping)
          Marks the given key as not amenable to caching.
 FinderQuery<ClassMapping,SelectExecutor,Result> markUncachable(String id)
           
(package private)  boolean matches(String pattern, ClassMapping mapping)
           
(package private)  boolean matches(String pattern, String target)
           
 void removeExclusionPattern(String pattern)
          Removes a pattern for exclusion.
(package private)  ClassMapping searchMappingByName(String cls)
           
 void setConfiguration(Configuration conf)
          Invoked prior to setting bean properties.
 void setEnableStats(boolean b)
           
 void setExcludes(String excludes)
           
 void startConfiguration()
          Invoked before bean property configuration is begun on this object.
(package private)  void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FinderCacheImpl

public FinderCacheImpl()
Method Detail

getMapView

public Map<String,String> getMapView()
Get a map-oriented view of the cache.

Specified by:
getMapView in interface FinderCache<ClassMapping,SelectExecutor,Result>
Returns:
a map of the query string with class names as key.

getStatistics

public QueryStatistics<ClassMapping> getStatistics()
Gets basic statistics of execution and hit count of finder queries.

Specified by:
getStatistics in interface FinderCache<ClassMapping,SelectExecutor,Result>

get

public FinderQuery<ClassMapping,SelectExecutor,Result> get(ClassMapping mapping,
                                                           FetchConfiguration fetch)
Gets the finder query for the given mapping. The get operation can be controlled by FetchConfiguration hints. HINT_IGNORE_FINDER will ignore any cached finder that may exist in this cache and will return null. HINT_INVALIDATE_FINDER will invalidate any cached finder that may exist in this cache and will return null.

Specified by:
get in interface FinderCache<ClassMapping,SelectExecutor,Result>
Parameters:
mapping - for which the finder is looked up
Returns:
FinderQuery for the given mapping.

cache

public FinderQuery<ClassMapping,SelectExecutor,Result> cache(ClassMapping mapping,
                                                             SelectExecutor select,
                                                             FetchConfiguration fetch)
Cache a Finder Query for the given mapping and select. The put operation can be controlled by FetchConfiguration hints. If no entry exists for the given mapping then an attempt is made to create a new FinderQuery. The attempt, however, may not be successful because all Selects can not be cached.

Specified by:
cache in interface FinderCache<ClassMapping,SelectExecutor,Result>
Parameters:
mapping - the class for which the finder is to be cached
select - the finder query
fetch - may contain hints to control cache operation
Returns:
the finder query that has been cached. It may be newly constructed or an existing query. If the given key-value can not be cached, then return null.
See Also:
If a entry for the given mapping exists then the value of {@link QueryHints#HINT_RECACHE_FINDER HINT_RECACHE_FINDER} hint determines whether the existing entry is returned or a new FinderQuery with the given argument overwrites the existing one.

isExcluded

public boolean isExcluded(ClassMapping mapping)
Affirms if the given mapping is excluded from being cached.

Specified by:
isExcluded in interface FinderCache<ClassMapping,SelectExecutor,Result>

addExclusionPattern

public void addExclusionPattern(String pattern)
Adds a pattern for exclusion. Any cached finder whose class name matches the given pattern will be marked invalidated as a side-effect.

Specified by:
addExclusionPattern in interface FinderCache<ClassMapping,SelectExecutor,Result>

removeExclusionPattern

public void removeExclusionPattern(String pattern)
Removes a pattern for exclusion. Any query identifier marked as not cachable due to the given pattern will now be removed from the list of uncachables as a side-effect.

Specified by:
removeExclusionPattern in interface FinderCache<ClassMapping,SelectExecutor,Result>

matches

boolean matches(String pattern,
                ClassMapping mapping)

matches

boolean matches(String pattern,
                String target)

invalidate

public boolean invalidate(ClassMapping mapping)
Description copied from interface: FinderCache
Remove the FinderQuery for the given key from this cache.

Specified by:
invalidate in interface FinderCache<ClassMapping,SelectExecutor,Result>

markUncachable

public FinderQuery<ClassMapping,SelectExecutor,Result> markUncachable(ClassMapping mapping)
Description copied from interface: FinderCache
Marks the given key as not amenable to caching. Explicit marking helps to avoid repeated computational cost of determining whether finder for a key can be cached or not. Explicit marking can not be reversed by removal of exclusion patterns.

Specified by:
markUncachable in interface FinderCache<ClassMapping,SelectExecutor,Result>
Returns:
finder query for the given class if it had been cached before. null otherwise.

markUncachable

public FinderQuery<ClassMapping,SelectExecutor,Result> markUncachable(String id)

searchMappingByName

ClassMapping searchMappingByName(String cls)

setExcludes

public void setExcludes(String excludes)

getExcludes

public List<String> getExcludes()
Description copied from interface: FinderCache
Gets the excluded stringified keys.

Specified by:
getExcludes in interface FinderCache<ClassMapping,SelectExecutor,Result>

isHinted

boolean isHinted(FetchConfiguration fetch,
                 String hint)

lock

void lock()

unlock

void unlock()

setEnableStats

public void setEnableStats(boolean b)

getEnableStats

public boolean getEnableStats()

startConfiguration

public void startConfiguration()
Description copied from interface: Configurable
Invoked before bean property configuration is begun on this object.

Specified by:
startConfiguration in interface Configurable

setConfiguration

public void setConfiguration(Configuration conf)
Description copied from interface: Configurable
Invoked prior to setting bean properties.

Specified by:
setConfiguration in interface Configurable

endConfiguration

public void endConfiguration()
Description copied from interface: Configurable
Invoked upon completion of bean property configuration for this object.

Specified by:
endConfiguration in interface Configurable


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.