org.objectweb.cjdbc.controller.cache
Class AbstractRequestCache

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.cache.AbstractRequestCache
Direct Known Subclasses:
QueryCache, QueryCacheDB

public abstract class AbstractRequestCache
extends java.lang.Object

This class defines the minimal functionnalities that a request cache must provide.

Only read requests (SELECTs) can be cached, there is no sense to cache writes as they do not provide any result to cache. However, the cache must be notified of the write queries in order to maintain cache coherency.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
(package private) static Trace logger
          Logger instance.
protected  int parsingGranularity
          Parsing granularity.
protected  long pendingQueryTimeout
          Pending query timeout.
 
Constructor Summary
AbstractRequestCache()
           
 
Method Summary
abstract  void addToCache(SelectRequest request, java.sql.ResultSet result)
          Adds an entry request/reply to the cache.
abstract  void commit(TransactionMarkerMetaData tm)
          Commit a transaction given its id.
abstract  void flushCache()
          Removes all entries from the cache.
abstract  QueryCacheEntry getFromCache(SelectRequest request, boolean addToPendingQueries)
          Gets the result to the given request from the cache.
abstract  java.lang.String getInformation()
          Gets information about the request cache.
 int getParsingGranularity()
          Gets the needed query parsing granularity.
 int getPendingQueryTimeout()
          Returns the pending query timeout.
abstract  java.lang.String getXmlInformation()
          Gets information about the request cache in xml
 void mergeDatabaseSchema(DatabaseSchema dbs)
          Merge the given DatabaseSchema with the current one.
abstract  void removeFromCache(SelectRequest request)
          Removes an entry from the cache (both request and reply are dropped).
abstract  void rollback(TransactionMarkerMetaData tm)
          Rollback a transaction given its id.
 void setDatabaseSchema(DatabaseSchema dbs)
          Sets the DatabaseSchema of the current virtual database.
 void setParsingGranularity(int parsingGranularity)
          Sets the needed query parsing granularity.
 void setPendingQueryTimeout(int pendingQueryTimeout)
          Sets the pending query timeout.
abstract  void writeNotify(AbstractWriteRequest request)
          Notifies the cache that the given write request has been issued, so that cache coherency can be maintained.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parsingGranularity

protected int parsingGranularity
Parsing granularity. Default is: ParsingGranularities.NO_PARSING.


pendingQueryTimeout

protected long pendingQueryTimeout
Pending query timeout. Default is: 0 (wait forever).


logger

static Trace logger
Logger instance.

Constructor Detail

AbstractRequestCache

public AbstractRequestCache()
Method Detail

getParsingGranularity

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

Returns:
needed query parsing granularity
See Also:
setParsingGranularity(int)

setParsingGranularity

public void setParsingGranularity(int parsingGranularity)
Sets the needed query parsing granularity.

Parameters:
parsingGranularity - the query parsing granularity to set
See Also:
getParsingGranularity()

getPendingQueryTimeout

public int getPendingQueryTimeout()
Returns the pending query timeout.

Returns:
the pending query timeout.
See Also:
setPendingQueryTimeout(int)

setPendingQueryTimeout

public void setPendingQueryTimeout(int pendingQueryTimeout)
Sets the pending query timeout.

Parameters:
pendingQueryTimeout - the pending query timeout to set.
See Also:
getPendingQueryTimeout()

setDatabaseSchema

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

Parameters:
dbs - a DatabaseSchema value
See Also:
CacheDatabaseSchema

mergeDatabaseSchema

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

Parameters:
dbs - a DatabaseSchema value
See Also:
CacheDatabaseSchema

addToCache

public abstract 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, its result must be updated in any case but the request must never appear twice in the cache.

Parameters:
request - the request
result - the result corresponding to the request
Throws:
CacheException - if an error occurs

getFromCache

public abstract 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.

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 abstract void removeFromCache(SelectRequest request)
                              throws CacheException
Removes an entry from the cache (both request and reply are dropped). The query is also removed from the pending query list.

Parameters:
request - a SelectRequest
Throws:
CacheException - if an error occurs

writeNotify

public abstract void writeNotify(AbstractWriteRequest request)
                          throws CacheException
Notifies the cache that the given 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.

Parameters:
request - an AbstractWriteRequest value
Throws:
CacheException - if an error occurs

flushCache

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


commit

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

Parameters:
tm - the transaction marker metadata
Throws:
CacheException - if an error occurs

rollback

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

Parameters:
tm - the transaction marker metadata
Throws:
CacheException - if an error occurs

getInformation

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

Returns:
String containing information

getXmlInformation

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

Returns:
xml formatted String containing information


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