ca.uhn.cache.util
Class QueryProcessor

java.lang.Object
  extended byca.uhn.cache.util.QueryProcessor
Direct Known Subclasses:
UnstationaryQueryProcessor

public class QueryProcessor
extends java.lang.Object

TODO: TESTS Ecapsulates the common caching algorithm of querying a cache, getting a remainder, querying the original data source, and combining the results. Objects of this class hold the state of a single query instance. It is left to the caller to provide results from the original data source.

Version:
$Revision: 1.1 $ updated on $Date: 2005/01/24 22:51:49 $ by $Author: bryan_tripp $
Author:
Bryan Tripp

Constructor Summary
QueryProcessor(IQuery theQuery, ISemanticCache theCache, int theMaxGroups, EDU.oswego.cs.dl.util.concurrent.Executor theExecutor)
          Constructor for STATIONARY DATA ONLY.
 
Method Summary
 void declareException(java.lang.String theMessage, java.lang.Exception theException)
           
 IQueryResult getCombinedResult()
          Blocks until a result is available or an exception is encountered.
 IQuery[] getRemainderQueries()
           
protected  void init()
          Performs startup tasks (called by constructor).
protected  void setCombinedResult(IQueryResult theResult)
          Provide an initial value for the combined result.
 void setSourceResult(IQuery theQuery, IQueryResult theSourceResult)
           
protected  void thread(java.lang.Runnable theTask)
          Runs a task in its own thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryProcessor

public QueryProcessor(IQuery theQuery,
                      ISemanticCache theCache,
                      int theMaxGroups,
                      EDU.oswego.cs.dl.util.concurrent.Executor theExecutor)
               throws CacheException
Constructor for STATIONARY DATA ONLY. See IUnstationaryDataSource for discussion.

Parameters:
theQuery - the query to process
theCache - the cache against which to process it
theMaxGroups - maximum number of remainder queries
theExecutor - handler of concurrent tasks (defaults to ThreadedExecutor if null)
Throws:
CacheException - if there is a problem finding the query remainder
Method Detail

init

protected void init()
Performs startup tasks (called by constructor). The default is to start running the cache query. Subclasses can over-ride.


getRemainderQueries

public IQuery[] getRemainderQueries()
Returns:
queries defining those parts of the query associated with this processor that are not contained in the cache

setCombinedResult

protected void setCombinedResult(IQueryResult theResult)
Provide an initial value for the combined result.

Parameters:
theResult - initial value

declareException

public void declareException(java.lang.String theMessage,
                             java.lang.Exception theException)
Parameters:
theMessage - description
theException - an exception that has been encountered that may render query results incorrect (for example exception while querying cache or source data)

setSourceResult

public void setSourceResult(IQuery theQuery,
                            IQueryResult theSourceResult)
Parameters:
theQuery - scope of the results (from a remainder query)
theSourceResult - corresponding results

getCombinedResult

public IQueryResult getCombinedResult()
                               throws CacheException
Blocks until a result is available or an exception is encountered.

Returns:
results including both cached data and data from the source (as they are added)
Throws:
CacheException - if a problem has been encountered getting data from the cache

thread

protected void thread(java.lang.Runnable theTask)
Runs a task in its own thread.

Parameters:
theTask - the task to run


Copyright © 2004-2005 University Health Network. All Rights Reserved.