org.openware.job.data
Class QueryCache

java.lang.Object
  |
  +--org.openware.job.data.QueryCache

public class QueryCache
extends java.lang.Object

Cache queries.

Queries are cached by the table name and where clause of the query. The cache's size can be set in terms of number of queries cached. This value defaults to 100 but can be changed in the constructor. When a new query needs to be cached and the cache is full the least recently used query is removed and the new one put in its place.

Version:
$Revision: 1.5 $ $Date: 2001/07/12 20:19:13 $
Author:
Vincent Sheffer

Constructor Summary
QueryCache()
           
QueryCache(int maxSize)
           
 
Method Summary
 void addToCache(TableRow tableRow, java.lang.String query, java.lang.String[] joinTables, java.util.Collection results)
          Add query results to the cache.
 java.util.Collection getFromCache(TableRow tableRow, java.lang.String query)
          Get query results from the cache.
 void invalidateCache(CacheInvalidationInfo cacheInfo)
          The database has been updated and now we need to invalidate certain parts of the cache.
 void invalidateCacheForTableName(java.lang.String tablename)
           
 void purgeCache()
          Remove all of the cached queries.
 void setCacheSize(int maxSize)
          Set the maximum size for the cache.
 void setDebugMode(boolean mode)
          Set the debug mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryCache

public QueryCache()

QueryCache

public QueryCache(int maxSize)
Method Detail

getFromCache

public java.util.Collection getFromCache(TableRow tableRow,
                                         java.lang.String query)
                                  throws PersistException
Get query results from the cache. Results are cached by table name and the query, itself.

If the cache doesn't contain the results then null is returned.

Parameters:
tableRow - Information about the table that we are looking the results in.
query - The query by which the results are cached.

setCacheSize

public void setCacheSize(int maxSize)
Set the maximum size for the cache. If adding results to the cache will result in a cache size greater than what you pass in here the least recently used results will be removed.

This value defaults to 100.

Parameters:
maxSize - The maximum size of the cache.

setDebugMode

public void setDebugMode(boolean mode)
Set the debug mode. If you want debugging information to printed to stdout pass in true to this method.

This method is normally going to be called by the PersistentManager when the call is made to set the query cache. If you want to override the settings for the PersistentManager call this method after you have called the setQueryCache method in the PersistentManager.

Parameters:
mode - true if you want to print debugging information to stdout, false otherwise.

addToCache

public void addToCache(TableRow tableRow,
                       java.lang.String query,
                       java.lang.String[] joinTables,
                       java.util.Collection results)
Add query results to the cache. The results are cached by table name and query (the SELECT where clause). If the cache is full the least recently used (LRU) value is removed
Parameters:
tableRow - Information about the table that we are caching the results for.
query - The query by which we are going to cache the results.
results - The actual results to cache.

invalidateCacheForTableName

public void invalidateCacheForTableName(java.lang.String tablename)

invalidateCache

public void invalidateCache(CacheInvalidationInfo cacheInfo)
The database has been updated and now we need to invalidate certain parts of the cache. Basically, if any row has been inserted or deleted from a table all of the cached queries for that table are purged.
Parameters:
cacheInfo - The object that contains the information on which parts of the cache to purge.

purgeCache

public void purgeCache()
Remove all of the cached queries.


Copyright © 2000,2001 Openware. All Rights Reserved.