org.apache.openjpa.jdbc.kernel
Class PreparedQueryCacheImpl

java.lang.Object
  extended by org.apache.openjpa.jdbc.kernel.PreparedQueryCacheImpl
All Implemented Interfaces:
PreparedQueryCache, Configurable

public class PreparedQueryCacheImpl
extends Object
implements PreparedQueryCache

An implementation of the cache of prepared queries.

Since:
2.0.0
Author:
Pinaki Poddar

Nested Class Summary
static class PreparedQueryCacheImpl.StrongExclusion
          Strong exclusion.
static class PreparedQueryCacheImpl.WeakExclusion
          Weak exclusion.
 
Nested classes/interfaces inherited from interface org.apache.openjpa.kernel.PreparedQueryCache
PreparedQueryCache.Exclusion
 
Constructor Summary
PreparedQueryCacheImpl()
           
 
Method Summary
 void addExclusionPattern(String pattern)
          Adds a pattern for exclusion.
 boolean cache(PreparedQuery q)
          Cache the given query keyed by its identifier.
 void clear()
           
 void endConfiguration()
           
 PreparedQuery get(String id)
           
 boolean getEnableStatistics()
           
 List<PreparedQueryCache.Exclusion> getExcludes()
           
 Map<String,String> getMapView()
           
 QueryStatistics<String> getStatistics()
           
 PreparedQuery initialize(String key, Object result)
           
 boolean invalidate(String id)
           
 Boolean isCachable(String id)
           
 PreparedQueryCache.Exclusion isExcluded(String id)
           
(package private)  boolean isHinted(FetchConfiguration fetch, String hint)
           
protected  void lock(boolean readOnly)
          Note: Care needs to be taken so that a read lock is never held while requesting a write lock.
 PreparedQuery markUncachable(String id, PreparedQueryCache.Exclusion exclusion)
           
(package private)  boolean matches(String pattern, String target)
           
 Boolean register(String id, Query query, FetchConfiguration hints)
           
 void removeExclusionPattern(String pattern)
          Removes a pattern for exclusion.
 void setConfiguration(Configuration conf)
           
 void setEnableStatistics(boolean enable)
           
 void setExcludes(String excludes)
           
 void startConfiguration()
           
protected  void unlock(boolean readOnly)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreparedQueryCacheImpl

public PreparedQueryCacheImpl()
Method Detail

register

public Boolean register(String id,
                        Query query,
                        FetchConfiguration hints)
Specified by:
register in interface PreparedQueryCache

getMapView

public Map<String,String> getMapView()
Specified by:
getMapView in interface PreparedQueryCache

cache

public boolean cache(PreparedQuery q)
Cache the given query keyed by its identifier. Does not cache if the identifier matches any exclusion pattern or has been marked as non-cachable. Also register the identifier as not cachable against the matched exclusion pattern.

Specified by:
cache in interface PreparedQueryCache

initialize

public PreparedQuery initialize(String key,
                                Object result)
Specified by:
initialize in interface PreparedQueryCache

invalidate

public boolean invalidate(String id)
Specified by:
invalidate in interface PreparedQueryCache

get

public PreparedQuery get(String id)
Specified by:
get in interface PreparedQueryCache

isCachable

public Boolean isCachable(String id)
Specified by:
isCachable in interface PreparedQueryCache

markUncachable

public PreparedQuery markUncachable(String id,
                                    PreparedQueryCache.Exclusion exclusion)
Specified by:
markUncachable in interface PreparedQueryCache

isExcluded

public PreparedQueryCache.Exclusion isExcluded(String id)
Specified by:
isExcluded in interface PreparedQueryCache

setExcludes

public void setExcludes(String excludes)
Specified by:
setExcludes in interface PreparedQueryCache

getExcludes

public List<PreparedQueryCache.Exclusion> getExcludes()
Specified by:
getExcludes in interface PreparedQueryCache

addExclusionPattern

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

Specified by:
addExclusionPattern in interface PreparedQueryCache

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 PreparedQueryCache

getStatistics

public QueryStatistics<String> getStatistics()
Specified by:
getStatistics in interface PreparedQueryCache

lock

protected void lock(boolean readOnly)
Note: Care needs to be taken so that a read lock is never held while requesting a write lock. This will result in a deadlock.

Parameters:
readOnly - - If true, a read lock will be acquired. Else a write lock will be acquired.

unlock

protected void unlock(boolean readOnly)
Parameters:
readOnly - - If true, the read lock will be released. Else a write lock will be released.

matches

boolean matches(String pattern,
                String target)

isHinted

boolean isHinted(FetchConfiguration fetch,
                 String hint)

clear

public void clear()
Specified by:
clear in interface PreparedQueryCache

setEnableStatistics

public void setEnableStatistics(boolean enable)
Specified by:
setEnableStatistics in interface PreparedQueryCache

getEnableStatistics

public boolean getEnableStatistics()
Specified by:
getEnableStatistics in interface PreparedQueryCache

setConfiguration

public void setConfiguration(Configuration conf)
Specified by:
setConfiguration in interface Configurable

startConfiguration

public void startConfiguration()
Specified by:
startConfiguration in interface Configurable

endConfiguration

public void endConfiguration()
Specified by:
endConfiguration in interface Configurable


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