SolarMetric Kodo JDO 3.0.3 generated on February 20 2004

kodo.datacache
Class CacheAwareQuery

java.lang.Object
  |
  +--kodo.datacache.CacheAwareQuery
All Implemented Interfaces:
KodoQuery, Query, Serializable

public class CacheAwareQuery
extends Object
implements KodoQuery

A Query implementation that caches the OIDs involved in the query, and can determine whether or not the query has been dirtied.

Since:
2.5.0
See Also:
Serialized Form

Fields inherited from interface kodo.query.KodoQuery
FLUSH_FALSE, FLUSH_TRUE, FLUSH_WITH_CONNECTION
 
Constructor Summary
CacheAwareQuery(KodoQuery query, QueryCache cache)
          Create a new CacheAwareQuery that delegates to query if no cached results are available.
 
Method Summary
 void abortCaching()
          Instructs this query to notify all CachingList objects created by it to stop caching results.
protected  ResultList checkCache(QueryKey qk)
          Look in the query cache for a result for the given query key.
 void close(Object arg)
           
 void closeAll()
           
 void compile()
           
 void declareImports(String arg)
           
 void declareParameters(String arg)
           
 void declareVariables(String arg)
           
 Object execute()
           
 Object execute(Object arg)
           
 Object execute(Object arg0, Object arg1)
           
 Object execute(Object arg0, Object arg1, Object arg2)
           
 Object executeWithArray(Object[] args)
           
 Object executeWithMap(Map args)
           
 ClassMetaData[] getAccessPathMetaDatas()
          Return an array of ClassMetaData for all classes involved in this query, or null if the access path for this query cannot be computed.
 boolean[] getAscending()
          For each expression returned by getOrdering(), return whether that expression is ascending.
 QueryCache getCache()
          Return the QueryCache that this object is associated with.
 Class getCandidateClass()
          Return the class of the objects that this query will return, or null if this information is not available / not relevant.
 Collection getCandidateCollection()
          Return the candidate collection, or null if an extent was specified instead of a collection.
 KodoExtent getCandidateExtent()
          Return the candidate extent, or null if a collection was specified instead of an extent.
 KodoQuery getDelegate()
          Returns the query that is being cached.
 FetchConfiguration getFetchConfiguration()
          Return the (mutable) fetch configuration for this query.
 String getFilter()
          Return the filter that this query has been configured with.
 boolean getIgnoreCache()
           
 String[] getOrdering()
          Return the ordering expressions that this query was configured with.
 String[][] getParameterDeclarations()
          Return a two-dimensional String array containing the parameter declarations for this query.
 PersistenceManager getPersistenceManager()
           
 String[] getResult()
          Return the result expressions set for this query.
 String[] getResultAliases()
          For each expression from getResult(), return the alias set for that expression.
 Class getResultClass()
          Returns the result class that has been set through setResultClass(java.lang.Class), or null if none.
 void registerListener(AggregateListener listener)
          Register a filter listener for the query.
 void registerListener(FilterListener listener)
          Register a filter listener for the query.
 void setCandidates(Collection arg)
           
 void setCandidates(Extent arg)
           
 void setClass(Class arg)
           
 void setFilter(String arg)
           
 void setIgnoreCache(boolean arg)
           
 void setOrdering(String arg)
           
 void setResult(String result)
          JDO 2.0 Preview.
 void setResultClass(Class cls)
          JDO 2.0 Preview.
 void setUnique(boolean unique)
          JDO 2.0 Preview.
protected  Object wrapResult(Object o, QueryKey qk)
          Wrap the query result in a list that will cache the values upon completion of the traversal of the underlying list.
 Object writeReplace()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheAwareQuery

public CacheAwareQuery(KodoQuery query,
                       QueryCache cache)
Create a new CacheAwareQuery that delegates to query if no cached results are available.
Method Detail

checkCache

protected ResultList checkCache(QueryKey qk)

Look in the query cache for a result for the given query key. Only look if this query is being executed outside a transaction or in a transaction with IgnoreCache set to true or in a transaction with IgnoreCache set to false but in which none of the classes involved in this query have been touched.

Caching is not used when using pessimistic transactions. This is because we must obtain locks on the data, and it is likely that making n trips to the database to make the locks will be slower than running the query against the database.

If KodoQuery#getQueryCacheEnabled returns false, this method returns null.

Return the list if we meet the above criteria and if a list is found for qk. Else, return null.

This implementation means that queries against the cache are of READ_COMMITTED isolation level. It'd be nice to support READ_SERIALIZABLE -- to do so, we'd just return false when in a transaction.


wrapResult

protected Object wrapResult(Object o,
                            QueryKey qk)

Wrap the query result in a list that will cache the values upon completion of the traversal of the underlying list.

This list must not register its results with the cache if one of the classes involved in this query is touched during the traversal of the query.

This method may decide not to do any caching of the query identified. For example, it might just return the supplied list if the query involves classes that are not cacheable.


getCache

public QueryCache getCache()
Return the QueryCache that this object is associated with.

abortCaching

public void abortCaching()
Instructs this query to notify all CachingList objects created by it to stop caching results. Upon invoking this method, all caching efforts are aborted, and any partial results are dropped.

getDelegate

public KodoQuery getDelegate()
Returns the query that is being cached.

writeReplace

public Object writeReplace()
                    throws ObjectStreamException

setClass

public void setClass(Class arg)
Specified by:
setClass in interface Query

setCandidates

public void setCandidates(Extent arg)
Specified by:
setCandidates in interface Query

setCandidates

public void setCandidates(Collection arg)
Specified by:
setCandidates in interface Query

setFilter

public void setFilter(String arg)
Specified by:
setFilter in interface Query

declareImports

public void declareImports(String arg)
Specified by:
declareImports in interface Query

declareParameters

public void declareParameters(String arg)
Specified by:
declareParameters in interface Query

declareVariables

public void declareVariables(String arg)
Specified by:
declareVariables in interface Query

setOrdering

public void setOrdering(String arg)
Specified by:
setOrdering in interface Query

setIgnoreCache

public void setIgnoreCache(boolean arg)
Specified by:
setIgnoreCache in interface Query

getIgnoreCache

public boolean getIgnoreCache()
Specified by:
getIgnoreCache in interface Query

compile

public void compile()
Specified by:
compile in interface Query

execute

public Object execute()
Specified by:
execute in interface Query

execute

public Object execute(Object arg)
Specified by:
execute in interface Query

execute

public Object execute(Object arg0,
                      Object arg1)
Specified by:
execute in interface Query

execute

public Object execute(Object arg0,
                      Object arg1,
                      Object arg2)
Specified by:
execute in interface Query

executeWithMap

public Object executeWithMap(Map args)
Specified by:
executeWithMap in interface Query

executeWithArray

public Object executeWithArray(Object[] args)
Specified by:
executeWithArray in interface Query

getPersistenceManager

public PersistenceManager getPersistenceManager()
Specified by:
getPersistenceManager in interface Query

close

public void close(Object arg)
Specified by:
close in interface Query

closeAll

public void closeAll()
Specified by:
closeAll in interface Query

getFetchConfiguration

public FetchConfiguration getFetchConfiguration()
Description copied from interface: KodoQuery
Return the (mutable) fetch configuration for this query.
Specified by:
getFetchConfiguration in interface KodoQuery

registerListener

public void registerListener(FilterListener listener)
Description copied from interface: KodoQuery
Register a filter listener for the query.
Specified by:
registerListener in interface KodoQuery

registerListener

public void registerListener(AggregateListener listener)
Description copied from interface: KodoQuery
Register a filter listener for the query.
Specified by:
registerListener in interface KodoQuery

getCandidateExtent

public KodoExtent getCandidateExtent()
Description copied from interface: KodoQuery
Return the candidate extent, or null if a collection was specified instead of an extent.
Specified by:
getCandidateExtent in interface KodoQuery

getCandidateCollection

public Collection getCandidateCollection()
Description copied from interface: KodoQuery
Return the candidate collection, or null if an extent was specified instead of a collection.
Specified by:
getCandidateCollection in interface KodoQuery

getCandidateClass

public Class getCandidateClass()
Description copied from interface: KodoQuery
Return the class of the objects that this query will return, or null if this information is not available / not relevant.
Specified by:
getCandidateClass in interface KodoQuery

getFilter

public String getFilter()
Description copied from interface: KodoQuery
Return the filter that this query has been configured with.
Specified by:
getFilter in interface KodoQuery

getOrdering

public String[] getOrdering()
Description copied from interface: KodoQuery
Return the ordering expressions that this query was configured with.
Specified by:
getOrdering in interface KodoQuery

getAscending

public boolean[] getAscending()
Description copied from interface: KodoQuery
For each expression returned by KodoQuery.getOrdering(), return whether that expression is ascending.
Specified by:
getAscending in interface KodoQuery

getParameterDeclarations

public String[][] getParameterDeclarations()
Description copied from interface: KodoQuery
Return a two-dimensional String array containing the parameter declarations for this query. For example, a query that has two int parameters called foo and bar would return { { "int", "foo" }, { "int", "bar" } }. Returns null if there are no parameter declarations.
Specified by:
getParameterDeclarations in interface KodoQuery

getResult

public String[] getResult()
Description copied from interface: KodoQuery
Return the result expressions set for this query.
Specified by:
getResult in interface KodoQuery

getResultAliases

public String[] getResultAliases()
Description copied from interface: KodoQuery
For each expression from KodoQuery.getResult(), return the alias set for that expression.
Specified by:
getResultAliases in interface KodoQuery

getAccessPathMetaDatas

public ClassMetaData[] getAccessPathMetaDatas()
Description copied from interface: KodoQuery
Return an array of ClassMetaData for all classes involved in this query, or null if the access path for this query cannot be computed.
Specified by:
getAccessPathMetaDatas in interface KodoQuery

setUnique

public void setUnique(boolean unique)
Description copied from interface: KodoQuery
JDO 2.0 Preview. Specify that only the first result of the query should be returned, rather than a collection. This method will return null if the query result size is 0.
Specified by:
setUnique in interface KodoQuery

setResult

public void setResult(String result)
Description copied from interface: KodoQuery
JDO 2.0 Preview. Configures what type of data this query should return. If this is unset or set to null, this query will return a list of the query's candidate class. Otherwise, this query will return aggregate function results and / or individual field values (projections).
Specified by:
setResult in interface KodoQuery
Following copied from interface: kodo.query.KodoQuery
Parameters:
data - a comma-delimited list of fields, functions on fields, or aggregate functions to return from this query

setResultClass

public void setResultClass(Class cls)
Description copied from interface: KodoQuery
JDO 2.0 Preview. Specify the type of object in which the result of invoking Query.execute() or one of its siblings. The behavior of this method depends the nature of the query being executed. In particular, if used in conjunction with KodoQuery.setResult(java.lang.String), the argument to this method should be Object[].class, a class with bean-like setters for each of the items listed in the result specification, or a class with a method called put with two Object arguments.
Specified by:
setResultClass in interface KodoQuery

getResultClass

public Class getResultClass()
Description copied from interface: KodoQuery
Returns the result class that has been set through KodoQuery.setResultClass(java.lang.Class), or null if none.
Specified by:
getResultClass in interface KodoQuery

SolarMetric Kodo JDO 3.0.3 generated on February 20 2004

Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.