org.objectweb.cjdbc.controller.cache
Class QueryCache

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.cache.AbstractRequestCache
      extended byorg.objectweb.cjdbc.controller.cache.QueryCache

public class QueryCache
extends AbstractRequestCache

This is a query cache implementation with tunable granularity.
Cache invalidation granularity can take on of the following values:

Version:
1.0
Author:
Emmanuel Cecchet, Julie Marguerite, Sara Bouchenak

Field Summary
private  int cacheGrain
           
private  CacheDatabaseSchema cdbs
           
private  java.util.Hashtable entriesForTransaction
           
private  QueryCacheEntry lruHead
           
private  QueryCacheEntry lruTail
           
private  java.util.HashSet pendingQueries
           
private  java.util.Hashtable queries
           
private  CacheStatistics stats
           
 
Fields inherited from class org.objectweb.cjdbc.controller.cache.AbstractRequestCache
logger, parsingGranularity, pendingQueryTimeout
 
Constructor Summary
QueryCache(int cacheGranularity)
          Creates a new Cache instance.
 
Method Summary
 void addToCache(SelectRequest request, java.sql.ResultSet result)
          Adds an entry request/reply to the cache.
 void commit(TransactionMarkerMetaData tm)
          Commit a transaction given its id.
 void flushCache()
          Removes all entries from the cache.
 QueryCacheEntry getFromCache(SelectRequest request, boolean addToPendingQueries)
          Gets the result to the given request from the cache.
 java.lang.String getInformation()
          Gets information about the request cache
 int getParsingGranularity()
          Gets the needed query parsing granularity.
 java.lang.String getXmlInformation()
          Gets information about the request cache
private  void initQueryCache(int cacheGranularity)
           
 void mergeDatabaseSchema(DatabaseSchema dbs)
          Merge the given DatabaseSchema with the current one.
 void removeFromCache(SelectRequest request)
          Removes an entry from the cache (both request and reply are dropped).
protected  void removeOldest()
          Removes the oldest entry from the cache.
 void rollback(TransactionMarkerMetaData tm)
          Rollback a transaction given its id.
 void setDatabaseSchema(DatabaseSchema dbs)
          Sets the DatabaseSchema of the current virtual database.
 void writeNotify(AbstractWriteRequest request)
          Notifies the cache that this write request has been issued, so that cache coherency can be maintained.
 
Methods inherited from class org.objectweb.cjdbc.controller.cache.AbstractRequestCache
getPendingQueryTimeout, setParsingGranularity, setPendingQueryTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queries

private java.util.Hashtable queries

pendingQueries

private java.util.HashSet pendingQueries

lruHead

private QueryCacheEntry lruHead

lruTail

private QueryCacheEntry lruTail

cdbs

private CacheDatabaseSchema cdbs

entriesForTransaction

private java.util.Hashtable entriesForTransaction

cacheGrain

private int cacheGrain

stats

private CacheStatistics stats
Constructor Detail

QueryCache

public QueryCache(int cacheGranularity)
Creates a new Cache instance.

Parameters:
cacheGranularity - an int value
Method Detail

initQueryCache

private void initQueryCache(int cacheGranularity)
                     throws CacheException
Throws:
CacheException

setDatabaseSchema

public void setDatabaseSchema(DatabaseSchema dbs)
Sets the DatabaseSchema of the current virtual database.

Overrides:
setDatabaseSchema in class AbstractRequestCache
Parameters:
dbs - a DatabaseSchema value
See Also:
CacheDatabaseSchema

mergeDatabaseSchema

public void mergeDatabaseSchema(DatabaseSchema dbs)
Merge the given DatabaseSchema with the current one.

Overrides:
mergeDatabaseSchema in class AbstractRequestCache
Parameters:
dbs - a DatabaseSchema value
See Also:
CacheDatabaseSchema

addToCache

public void addToCache(SelectRequest request,
                       java.sql.ResultSet result)
                throws CacheException
Adds an entry request/reply to the cache. Note that if the request was already in the cache, only the result is updated.

Specified by:
addToCache in class AbstractRequestCache
Parameters:
request - the request
result - the result corresponding to the request
Throws:
CacheException - if an error occurs

getFromCache

public QueryCacheEntry getFromCache(SelectRequest request,
                                    boolean addToPendingQueries)
Gets the result to the given request from the cache. The returned QueryCacheEntry is null if the request is not present in the cache.

An invalid QueryCacheEntry may be returned (it means that the result is null) but the already parsed query can be retrieved from the cache entry.

Specified by:
getFromCache in class AbstractRequestCache
Parameters:
request - an SQL select request
addToPendingQueries - true if the request must be added to the pending query list on a cache miss
Returns:
the QueryCacheEntry if found, else null

removeFromCache

public void removeFromCache(SelectRequest request)
                     throws CacheException
Removes an entry from the cache (both request and reply are dropped). The request is also removed from the pending query list.

Specified by:
removeFromCache in class AbstractRequestCache
Parameters:
request - a SelectRequest
Throws:
CacheException - if an error occurs

writeNotify

public void writeNotify(AbstractWriteRequest request)
                 throws CacheException
Notifies the cache that this write request has been issued, so that cache coherency can be maintained. If the cache is distributed, this method is reponsible for broadcasting this information to other caches.

Specified by:
writeNotify in class AbstractRequestCache
Parameters:
request - an AbstractRequest value
Throws:
CacheException - if an error occurs

flushCache

public void flushCache()
Removes all entries from the cache.

Specified by:
flushCache in class AbstractRequestCache

removeOldest

protected void removeOldest()
Removes the oldest entry from the cache.


getParsingGranularity

public int getParsingGranularity()
Gets the needed query parsing granularity.

Overrides:
getParsingGranularity in class AbstractRequestCache
Returns:
needed query parsing granularity
See Also:
AbstractRequestCache.setParsingGranularity(int)

commit

public void commit(TransactionMarkerMetaData tm)
            throws CacheException
Commit a transaction given its id.

Specified by:
commit in class AbstractRequestCache
Parameters:
tm - the transaction marker metadata
Throws:
CacheException - if an error occurs

rollback

public void rollback(TransactionMarkerMetaData tm)
              throws CacheException
Rollback a transaction given its id.

Specified by:
rollback in class AbstractRequestCache
Parameters:
tm - the transaction marker metadata
Throws:
CacheException - if an error occurs

getXmlInformation

public java.lang.String getXmlInformation()
Gets information about the request cache

Specified by:
getXmlInformation in class AbstractRequestCache
Returns:
String containing information

getInformation

public java.lang.String getInformation()
Gets information about the request cache

Specified by:
getInformation in class AbstractRequestCache
Returns:
String containing information


Copyright © 2002, 2003 - ObjectWeb Consortium - All Rights Reserved.