org.objectweb.cjdbc.controller.cache
Class QueryCacheDB

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

public class QueryCacheDB
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, Nicolas Modrzyk

Field Summary
private  int cacheGrain
           
private  CacheDatabaseSchema cdbs
           
private  java.sql.Connection conn
           
private  int create
           
private  int delete
           
private  java.lang.String driver
           
private  int drop
           
private  int hits
           
private  int insert
           
private  QueryCacheEntry lruHead
           
private  QueryCacheEntry lruTail
           
private  java.lang.String password
           
private  java.util.Hashtable queries
           
private  int remove
           
private  int select
           
private  int unknown
           
private  int update
           
private  java.lang.String url
           
private  java.lang.String user
           
 
Fields inherited from class org.objectweb.cjdbc.controller.cache.AbstractRequestCache
logger, parsingGranularity, pendingQueryTimeout
 
Constructor Summary
QueryCacheDB(int cacheGranularity, java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password, DatabaseSchema dbs)
          Creates a new Cache instance and connect to the given cache database.
 
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.
private  void executeCacheDB(java.lang.String sql)
           
 void flushCache()
          Removes all entries from the cache.
 QueryCacheEntry getFromCache(SelectRequest sqlQuery, 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 in xml
private  void handleWrite(AbstractWriteRequest request)
          This method maintains cache coherency upon a write request.
private  void initQueryCache(int cacheGranularity, DatabaseSchema dbs)
           
 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 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, mergeDatabaseSchema, setDatabaseSchema, setParsingGranularity, setPendingQueryTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

private java.sql.Connection conn

queries

private java.util.Hashtable queries

lruHead

private QueryCacheEntry lruHead

lruTail

private QueryCacheEntry lruTail

cdbs

private CacheDatabaseSchema cdbs

select

private int select

hits

private int hits

insert

private int insert

update

private int update

delete

private int delete

unknown

private int unknown

remove

private int remove

create

private int create

drop

private int drop

user

private java.lang.String user

password

private java.lang.String password

url

private java.lang.String url

driver

private java.lang.String driver

cacheGrain

private int cacheGrain
Constructor Detail

QueryCacheDB

public QueryCacheDB(int cacheGranularity,
                    java.lang.String driver,
                    java.lang.String url,
                    java.lang.String user,
                    java.lang.String password,
                    DatabaseSchema dbs)
Creates a new Cache instance and connect to the given cache database.

Parameters:
cacheGranularity - an int value
driver - cache database driver class
url - JDBC URL to access the cache database
user - user name to use to access the cache database
password - password to use to access the cache database
dbs - the CacheDatabaseSchema
Method Detail

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)

initQueryCache

private void initQueryCache(int cacheGranularity,
                            DatabaseSchema dbs)
                     throws CacheException
Throws:
CacheException

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, just 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 sqlQuery,
                                    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:
sqlQuery - an SQL 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).

Specified by:
removeFromCache in class AbstractRequestCache
Parameters:
request - an 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

handleWrite

private void handleWrite(AbstractWriteRequest request)
                  throws CacheException
This method maintains cache coherency upon a write request.

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

executeCacheDB

private void executeCacheDB(java.lang.String sql)

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.


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

getInformation

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

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

getXmlInformation

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

Specified by:
getXmlInformation in class AbstractRequestCache
Returns:
String containing information, xml formatted.


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