クラス org.objectweb.cjdbc.controller.cache.result.ResultCache

org.objectweb.cjdbc.controller.cache.result.ResultCacheに対する継承グラフ

Inheritance graph
[凡例]
org.objectweb.cjdbc.controller.cache.result.ResultCacheのコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

説明

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

作者:
Emmanuel Cecchet

Julie Marguerite

Sara Bouchenak

Nicolas Modrzyk

バージョン:
1.0

ResultCache.java77 行で定義されています。

Public メソッド

 ResultCache (int maxEntries, int pendingTimeout)
int getPendingQueryTimeout ()
void setPendingQueryTimeout (int pendingQueryTimeout)
HashMap getQueries ()
void setDatabaseSchema (DatabaseSchema dbs)
void mergeDatabaseSchema (DatabaseSchema dbs)
void addCachingRule (ResultCacheRule rule)
ResultCacheRule getDefaultRule ()
void setDefaultRule (ResultCacheRule defaultRule)
boolean[] needInvalidate (ControllerResultSet result, UpdateRequest request)
void addToCache (SelectRequest request, ControllerResultSet result) throws CacheException
CacheEntry getFromCache (SelectRequest request, boolean addToPendingQueries)
void removeFromCache (SelectRequest request)
void removeFromPendingQueries (SelectRequest request)
abstract boolean isUpdateNecessary (UpdateRequest request) throws CacheException
void writeNotify (AbstractWriteRequest request) throws CacheException
void flushCache ()
long getCacheSize ()
int getParsingGranularity ()
abstract String getName ()
void commit (long transactionId) throws CacheException
void rollback (long transactionId) throws CacheException
String[][] getCacheData () throws CacheException
String[][] getCacheStatsData () throws CacheException
CacheStatistics getCacheStatistics ()

Protected メソッド

abstract void processAddToCache (CacheEntry qe)
abstract void processWriteNotify (AbstractWriteRequest request)
String getXmlImpl ()

Protected 変数

CacheDatabaseSchema cdbs

Private メソッド

CacheBehavior getCacheBehavior (SelectRequest request)
void removeOldest ()

Private 変数

int maxEntries
long pendingQueryTimeout = 0
HashMap queries
HashSet pendingQueries
HashSet cachingRules
ResultCacheRule defaultRule
ArrayList relaxedCache
CacheEntry lruHead
CacheEntry lruTail
CacheStatistics stats
long threadWakeUpTime
RelaxedCacheThread relaxedThread

Static Private 変数

final boolean[] TRUE_TRUE = new boolean[]{true, true}


コンストラクタとデストラクタ

org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache int  maxEntries,
int  pendingTimeout
 

Creates a new Cache instance.

引数:
maxEntries maximum number of cache entries
pendingTimeout pending queries timeout
ResultCache.java126 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.cachingRules, org.objectweb.cjdbc.controller.cache.result.ResultCache.cdbs, org.objectweb.cjdbc.controller.cache.result.ResultCache.defaultRule, org.objectweb.cjdbc.controller.cache.result.ResultCache.lruHead, org.objectweb.cjdbc.controller.cache.result.ResultCache.lruTail, org.objectweb.cjdbc.controller.cache.result.ResultCache.pendingQueries, org.objectweb.cjdbc.controller.cache.result.ResultCache.queries, org.objectweb.cjdbc.controller.cache.result.ResultCache.relaxedCache, org.objectweb.cjdbc.controller.cache.result.ResultCache.relaxedThread, org.objectweb.cjdbc.controller.cache.result.ResultCache.stats, と org.objectweb.cjdbc.controller.cache.result.ResultCache.threadWakeUpTime.

00127 { 00128 this.maxEntries = maxEntries; 00129 this.pendingQueryTimeout = pendingTimeout; 00130 cdbs = null; 00131 stats = new CacheStatistics(); 00132 queries = new HashMap(1000, (float) 0.75); 00133 pendingQueries = new HashSet(); 00134 cachingRules = new HashSet(); 00135 relaxedCache = new ArrayList(); 00136 lruHead = null; 00137 lruTail = null; 00138 defaultRule = null; 00139 threadWakeUpTime = 0; 00140 relaxedThread = new RelaxedCacheThread(); 00141 relaxedThread.setPriority(9); 00142 relaxedThread.start(); 00143 }


メソッド

void org.objectweb.cjdbc.controller.cache.result.ResultCache.addCachingRule ResultCacheRule  rule  )  [virtual]
 

Add a rule for this ResultCache

引数:
rule that contains information on the action to perform for a specific query

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java257 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.cachingRules.

00258 { 00259 cachingRules.add(rule); 00260 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.addToCache SelectRequest  request,
ControllerResultSet  result
throws CacheException [virtual]
 

Adds an entry request/reply to the cache. Note that if the request was already in the cache, only the result is updated.

引数:
request the request
result the result corresponding to the request
例外:
CacheException if an error occurs

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java383 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.CacheBehavior.getCacheEntry(), と org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.getDeadline().

00385 { 00386 String sqlQuery = request.getSQL(); 00387 00388 // Sanity checks 00389 if (request.getCacheAbility() == RequestType.UNCACHEABLE) 00390 throw new CacheException(Translate.get("resultcache.uncacheable.request", 00391 sqlQuery)); 00392 00393 if (result == null) 00394 throw new CacheException(Translate.get("resultcache.null.result", 00395 sqlQuery)); 00396 00397 synchronized (pendingQueries) 00398 { 00399 // Remove the pending query from the list and wake up 00400 // all waiting queries 00401 if (pendingQueries.remove(sqlQuery)) 00402 { 00403 if (logger.isDebugEnabled()) 00404 logger.debug(Translate.get("resultcache.removing.pending.query", 00405 sqlQuery)); 00406 pendingQueries.notifyAll(); 00407 } 00408 else 00409 logger.warn(Translate.get("resultcache.removing.pending.query.failed", 00410 sqlQuery)); 00411 00412 // Check against streamable ResultSets 00413 if (result.hasMoreData()) 00414 { 00415 logger.info(Translate.get("resultcache.streamed.resultset", request 00416 .getSQLShortForm(20))); 00417 return; 00418 } 00419 00420 if (logger.isDebugEnabled()) 00421 logger.debug(Translate.get("resultcache.adding.query", sqlQuery)); 00422 00423 CacheEntry ce; 00424 synchronized (queries) 00425 { 00426 // Check first that the query is not already in the cache 00427 ce = (ResultCacheEntry) queries.get(sqlQuery); 00428 if (ce == null) 00429 { 00430 // Not in cache, add this entry 00431 // check the rule 00432 CacheBehavior behavior = getCacheBehavior(request); 00433 ce = behavior.getCacheEntry(request, result, this); 00434 if (ce instanceof ResultCacheEntryNoCache) 00435 return; 00436 00437 // Test size of cache 00438 if (maxEntries > 0) 00439 { 00440 int size = queries.size(); 00441 if (size >= maxEntries) 00442 // LRU replacement policy: Remove the oldest cache entry 00443 removeOldest(); 00444 } 00445 // Add to the cache 00446 queries.put(sqlQuery, ce); 00447 if (ce instanceof ResultCacheEntryRelaxed) 00448 { 00449 ResultCacheEntryRelaxed qcer = (ResultCacheEntryRelaxed) ce; 00450 synchronized (relaxedThread) 00451 { 00452 relaxedCache.add(qcer); 00453 if (qcer.getDeadline() < threadWakeUpTime 00454 || threadWakeUpTime == 0) 00455 { 00456 relaxedThread.notify(); 00457 } 00458 } 00459 } 00460 } 00461 else 00462 { // Oh, oh, already in cache ... 00463 if (ce.isValid()) 00464 logger.warn(Translate.get( 00465 "resultcache.modifying.result.valid.entry", sqlQuery)); 00466 ce.setResult(result); 00467 } 00468 00469 // Update LRU 00470 if (lruHead != null) 00471 { 00472 lruHead.setPrev(ce); 00473 ce.setNext(lruHead); 00474 ce.setPrev(null); 00475 } 00476 if (lruTail == null) 00477 lruTail = ce; 00478 lruHead = ce; // This is also fine if LRUHead == null 00479 } 00480 processAddToCache(ce); 00481 } 00482 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.commit long  transactionId  )  throws CacheException [virtual]
 

Commit a transaction given its id.

引数:
transactionId the transaction id
例外:
CacheException if an error occurs

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java867 行で定義されています。

00868 { 00869 // Ok, the transaction has commited, nothing to do 00870 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.flushCache  )  [virtual]
 

Removes all entries from the cache.

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java768 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCacheTable.processWriteNotify(), org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase.processWriteNotify(), と org.objectweb.cjdbc.controller.cache.result.ResultCache.setDatabaseSchema().

00769 { 00770 synchronized (queries) 00771 { // Invalidate the whole cache until it is empty 00772 while (!queries.isEmpty()) 00773 { 00774 Iterator iter = queries.values().iterator(); 00775 ((ResultCacheEntry) iter.next()).invalidate(); 00776 } 00777 } 00778 00779 synchronized (pendingQueries) 00780 { // Clean pending queries to unblock everyone if some queries/backends 00781 // remained in an unstable state. 00782 pendingQueries.clear(); 00783 pendingQueries.notifyAll(); 00784 } 00785 00786 if (logger.isDebugEnabled()) 00787 logger.debug(Translate.get("resultcache.cache.flushed")); 00788 }

CacheBehavior org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheBehavior SelectRequest  request  )  [private]
 

Finds the behavior of the cache with the given query skeleton. If the query match a pattern of a rule then we get the associated action for this, otherwise we look for the default behavior.

引数:
request to get action for
戻り値:
the CacheBehavior associated for this query.
ResultCache.java286 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.cachingRules, org.objectweb.cjdbc.common.log.Trace.debug(), org.objectweb.cjdbc.controller.cache.result.ResultCache.defaultRule, org.objectweb.cjdbc.controller.cache.result.ResultCacheRule.getCacheBehavior(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.controller.cache.result.CacheBehavior.getType(), と org.objectweb.cjdbc.common.log.Trace.isDebugEnabled().

00287 { 00288 CacheBehavior behavior = null; 00289 for (Iterator iter = cachingRules.iterator(); iter.hasNext();) 00290 { 00291 behavior = ((ResultCacheRule) iter.next()).matches(request); 00292 if (behavior != null) 00293 { 00294 break; 00295 } 00296 } 00297 if (behavior == null) 00298 behavior = defaultRule.getCacheBehavior(); 00299 if (logger.isDebugEnabled()) 00300 logger.debug(Translate.get("resultcache.behavior.for.request", 00301 new String[]{request.getSQL(), behavior.getType()})); 00302 return behavior; 00303 }

String [][] org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheData  )  throws CacheException [virtual]
 

参照:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.getCacheData

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java892 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.toStringTable().

00893 { 00894 try 00895 { 00896 synchronized (queries) 00897 { 00898 String[][] data = new String[queries.size()][]; 00899 int count = 0; 00900 for (Iterator iter = queries.values().iterator(); iter.hasNext(); count++) 00901 { 00902 ResultCacheEntry qe = (ResultCacheEntry) iter.next(); 00903 if (qe != null) 00904 { 00905 data[count] = qe.toStringTable(); 00906 } 00907 } 00908 return data; 00909 } 00910 } 00911 catch (Exception e) 00912 { 00913 logger.error(Translate.get("resultcache.error.retrieving.cache.data", e)); 00914 throw new CacheException(e.getMessage()); 00915 } 00916 }

long org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheSize  )  [virtual]
 

Get Cache size

戻り値:
the approximate size of the cache in bytes

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java795 行で定義されています。

00796 { 00797 // No need to synchronize, the implementation returns an int 00798 return queries.size(); 00799 }

CacheStatistics org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheStatistics  )  [virtual]
 

戻り値:
Returns the stats.

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java935 行で定義されています。

00936 { 00937 return stats; 00938 }

String [][] org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheStatsData  )  throws CacheException [virtual]
 

参照:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.getCacheStatsData()

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java921 行で定義されています。

00922 { 00923 String[][] data = new String[1][]; 00924 String[] stat = stats.getCacheStatsData(); 00925 data[0] = new String[stat.length + 1]; 00926 for (int i = 0; i < stat.length; i++) 00927 data[0][i] = stat[i]; 00928 data[0][data[0].length - 1] = "" + queries.size(); 00929 return data; 00930 }

ResultCacheRule org.objectweb.cjdbc.controller.cache.result.ResultCache.getDefaultRule  )  [virtual]
 

参照:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.getDefaultRule()

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java265 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.defaultRule.

00266 { 00267 return defaultRule; 00268 }

CacheEntry org.objectweb.cjdbc.controller.cache.result.ResultCache.getFromCache SelectRequest  request,
boolean  addToPendingQueries
[virtual]
 

Gets the result to the given request from the cache. The returned ResultCacheEntry is null if the request is not present in the cache.

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

引数:
request an SQL select request
addToPendingQueries true if the request must be added to the pending query list on a cache miss
戻り値:
the ResultCacheEntry if found, else null

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java506 行で定義されています。

参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getCacheAbility(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getNext(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getPrev(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getRequest(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getResult(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.isValid(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setNext(), と org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setPrev().

00508 { 00509 stats.addSelect(); 00510 00511 if (request.getCacheAbility() == RequestType.UNCACHEABLE) 00512 { 00513 stats.addUncacheable(); 00514 return null; 00515 } 00516 00517 String sqlQuery = request.getSQL(); 00518 00519 // Check if we have the same query pending 00520 synchronized (pendingQueries) 00521 { 00522 if (addToPendingQueries) 00523 { 00524 long timeout = pendingQueryTimeout; 00525 // Yes, wait for the result 00526 // As we use a single lock for all pending queries, we use a 00527 // while to re-check that this wake-up was for us! 00528 while (pendingQueries.contains(sqlQuery)) 00529 { 00530 try 00531 { 00532 if (logger.isDebugEnabled()) 00533 logger.debug(Translate.get("resultcache.waiting.pending.query", 00534 sqlQuery)); 00535 00536 if (timeout > 0) 00537 { 00538 long start = System.currentTimeMillis(); 00539 pendingQueries.wait(pendingQueryTimeout); 00540 long end = System.currentTimeMillis(); 00541 timeout = timeout - (end - start); 00542 if (timeout <= 0) 00543 { 00544 logger.warn(Translate.get("resultcache.pending.query.timeout")); 00545 break; 00546 } 00547 } 00548 else 00549 pendingQueries.wait(); 00550 } 00551 catch (InterruptedException e) 00552 { 00553 logger.warn(Translate.get("resultcache.pending.query.timeout")); 00554 break; 00555 } 00556 } 00557 } 00558 00559 // Check the cache 00560 ResultCacheEntry ce; 00561 synchronized (queries) 00562 { 00563 ce = (ResultCacheEntry) queries.get(sqlQuery); 00564 if (ce == null) 00565 //if ((ce == null) || !ce.isValid()) 00566 { // Cache miss or dirty entry 00567 if (addToPendingQueries) 00568 { 00569 pendingQueries.add(sqlQuery); 00570 // Add this query to the pending queries 00571 if (logger.isDebugEnabled()) 00572 { 00573 logger.debug(Translate.get("resultcache.cache.miss")); 00574 logger.debug(Translate.get( 00575 "resultcache.adding.to.pending.queries", sqlQuery)); 00576 } 00577 } 00578 return null; 00579 } 00580 else 00581 { // Cache hit (must update LRU) 00582 // Move cache entry to head of LRU 00583 CacheEntry before = ce.getPrev(); 00584 if (before != null) 00585 { 00586 CacheEntry after = ce.getNext(); 00587 before.setNext(after); 00588 if (after != null) 00589 after.setPrev(before); 00590 else 00591 // We were the tail, update the tail 00592 lruTail = before; 00593 ce.setNext(lruHead); 00594 ce.setPrev(null); 00595 if (lruHead != ce) 00596 lruHead.setPrev(ce); 00597 lruHead = ce; 00598 } 00599 // else it was already the LRU head 00600 } 00601 } 00602 00603 if (ce.getResult() == null) 00604 { 00605 if (addToPendingQueries) 00606 { 00607 pendingQueries.add(sqlQuery); 00608 // Add this query to the pending queries 00609 if (logger.isDebugEnabled()) 00610 { 00611 logger.debug(Translate.get("resultcache.cache.miss")); 00612 logger.debug(Translate.get("resultcache.adding.to.pending.queries", 00613 sqlQuery)); 00614 } 00615 } 00616 if (ce.isValid() && logger.isInfoEnabled()) 00617 logger.info(Translate.get("resultcache.valid.entry.without.result", 00618 ce.getRequest().getSQL())); 00619 } 00620 else 00621 { 00622 if (logger.isDebugEnabled()) 00623 logger.debug(Translate.get("resultcache.cache.hit", sqlQuery)); 00624 stats.addHits(); 00625 } 00626 00627 return ce; 00628 } 00629 }

abstract String org.objectweb.cjdbc.controller.cache.result.ResultCache.getName  )  [pure virtual]
 

Retrieve the name of this cache

戻り値:
name

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, と org.objectweb.cjdbc.controller.cache.result.ResultCacheTableで実装されています.

int org.objectweb.cjdbc.controller.cache.result.ResultCache.getParsingGranularity  ) 
 

Gets the needed query parsing granularity.

戻り値:
needed query parsing granularity

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを再定義しています。

ResultCache.java845 行で定義されています。

00846 { 00847 return this.parsingGranularity; 00848 }

int org.objectweb.cjdbc.controller.cache.result.ResultCache.getPendingQueryTimeout  ) 
 

Returns the pending query timeout in seconds.

戻り値:
the pending query timeout.
参照:
setPendingQueryTimeout
ResultCache.java151 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.pendingQueryTimeout.

00152 { 00153 return (int) (pendingQueryTimeout / 1000); 00154 }

HashMap org.objectweb.cjdbc.controller.cache.result.ResultCache.getQueries  ) 
 

Possibly we want to access the queries in the cache for timing purposes

戻り値:
the HashMap of queries (not synchronized)
ResultCache.java172 行で定義されています。
00173 { 00174 return this.queries; 00175 }

String org.objectweb.cjdbc.controller.cache.result.ResultCache.getXmlImpl  )  [protected, virtual]
 

Gets information about the request cache

戻り値:
String containing information

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java945 行で定義されています。

00946 { 00947 StringBuffer info = new StringBuffer(); 00948 info.append("<" + DatabasesXmlTags.ELT_ResultCache + " " 00949 + DatabasesXmlTags.ATT_pendingTimeout + "=\"" + pendingQueryTimeout 00950 + "\" " + DatabasesXmlTags.ATT_maxNbOfEntries + "=\"" + maxEntries 00951 + "\" " + DatabasesXmlTags.ATT_granularity + "=\"" + getName() + "\">"); 00952 info.append("<" + DatabasesXmlTags.ELT_DefaultResultCacheRule + " " 00953 + DatabasesXmlTags.ATT_timestampResolution + "=\"" 00954 + defaultRule.getTimestampResolution() / 1000 + "\">"); 00955 info.append(defaultRule.getCacheBehavior().getXml()); 00956 info.append("</" + DatabasesXmlTags.ELT_DefaultResultCacheRule + ">"); 00957 for (Iterator iter = cachingRules.iterator(); iter.hasNext();) 00958 info.append(((ResultCacheRule) iter.next()).getXml()); 00959 info.append("</" + DatabasesXmlTags.ELT_ResultCache + ">"); 00960 return info.toString(); 00961 }

abstract boolean org.objectweb.cjdbc.controller.cache.result.ResultCache.isUpdateNecessary UpdateRequest  request  )  throws CacheException [pure virtual]
 

参照:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.isUpdateNecessary(org.objectweb.cjdbc.common.sql.UpdateRequest)

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, と org.objectweb.cjdbc.controller.cache.result.ResultCacheTableで実装されています.

void org.objectweb.cjdbc.controller.cache.result.ResultCache.mergeDatabaseSchema DatabaseSchema  dbs  ) 
 

Merge the given DatabaseSchema with the current one.

引数:
dbs a DatabaseSchema value
参照:
org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseSchema

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを再定義しています。

ResultCache.java238 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.cdbs, org.objectweb.cjdbc.common.log.Trace.error(), と org.objectweb.cjdbc.common.log.Trace.info().

00239 { 00240 try 00241 { 00242 logger.info(Translate.get("resultcache.merging.new.database.schema")); 00243 cdbs.mergeSchema(new CacheDatabaseSchema(dbs)); 00244 } 00245 catch (Exception e) 00246 { 00247 logger.error(Translate.get("resultcache.error.while.merging", e)); 00248 } 00249 }

boolean [] org.objectweb.cjdbc.controller.cache.result.ResultCache.needInvalidate ControllerResultSet  result,
UpdateRequest  request
 

Do we need invalidation after an update request, given a ControllerResultSet. Note that this method is meant to be used with unique queries where the ControllerResultSet is the result of a pk selection (like an Entity Bean).

引数:
result that could be in the cache
request the update we want to get updated values from
戻り値:
boolean[] {needInvalidate,needToSendQuery}
ResultCache.java319 行で定義されています。

参照先 org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet.getData(), org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet.getFields(), と org.objectweb.cjdbc.common.sql.UpdateRequest.getUpdatedValues().

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.isUpdateNecessary(), と org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processWriteNotify().

00321 { 00322 HashMap updatedValues = request.getUpdatedValues(); 00323 boolean needInvalidate = false; 00324 boolean needToSendQuery = false; 00325 String value; 00326 String columnName; 00327 try 00328 { 00329 // If we don't have exactly one row, we don't handle the optimization 00330 if ((result == null) || (result.getData() == null) 00331 || (result.getData().size() != 1)) 00332 return TRUE_TRUE; 00333 } 00334 catch (Exception e) 00335 { 00336 return TRUE_TRUE; 00337 } 00338 Field[] fields = result.getFields(); 00339 ArrayList data = result.getData(); 00340 int size = fields.length; 00341 for (Iterator iter = updatedValues.keySet().iterator(); iter.hasNext();) 00342 { 00343 columnName = (String) iter.next(); 00344 value = (String) updatedValues.get(columnName); 00345 for (int i = 0; i < size; i++) 00346 { // Find the corresponding column in the ResultSet by comparing column 00347 // names 00348 00349 // We can have something like: 00350 // FIRSTNAME and ADDRESS.FIRSTNAME 00351 if (columnName.equals(fields[i].getFieldName())) 00352 { 00353 Object o = ((Object[]) data.get(0))[i]; 00354 if (!value.equals(o)) 00355 { 00356 // The value from the cache entry is different we need to update 00357 // the 00358 // cache and the database 00359 return TRUE_TRUE; 00360 } 00361 else 00362 break; 00363 } 00364 } 00365 // We don't need to invalidate the cache because the columns affected are 00366 // different but we need to send the query to the database. 00367 needToSendQuery = true; 00368 // We don't stop here though because other columns could be updated and 00369 // we 00370 // could need invalidation 00371 } 00372 return new boolean[]{needInvalidate, needToSendQuery}; 00373 }

abstract void org.objectweb.cjdbc.controller.cache.result.ResultCache.processAddToCache CacheEntry  qe  )  [protected, pure virtual]
 

Process the add to cache to update implementation specific data structures.

引数:
qe to add to the cache.

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, と org.objectweb.cjdbc.controller.cache.result.ResultCacheTableで実装されています.

abstract void org.objectweb.cjdbc.controller.cache.result.ResultCache.processWriteNotify AbstractWriteRequest  request  )  [protected, pure virtual]
 

Implementation specific invalidation of the cache.

引数:
request Write request that invalidates the cache.

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, と org.objectweb.cjdbc.controller.cache.result.ResultCacheTableで実装されています.

void org.objectweb.cjdbc.controller.cache.result.ResultCache.removeFromCache SelectRequest  request  )  [virtual]
 

Removes an entry from the cache (both request and reply are dropped). The request is NOT removed from the pending query list, but it shouldn't be in this list.

引数:
request a SelectRequest

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java638 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getNext(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getPrev(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), と org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setResult().

00639 { 00640 String sqlQuery = request.getSQL(); 00641 00642 if (logger.isDebugEnabled()) 00643 logger.debug("Removing from cache: " + sqlQuery); 00644 00645 synchronized (queries) 00646 { 00647 // Remove from the cache 00648 ResultCacheEntry ce = (ResultCacheEntry) queries.remove(sqlQuery); 00649 if (ce == null) 00650 return; // Was not in the cache! 00651 else 00652 { 00653 // Update result set 00654 ce.setResult(null); 00655 // Update LRU 00656 CacheEntry before = ce.getPrev(); 00657 CacheEntry after = ce.getNext(); 00658 if (before != null) 00659 { 00660 before.setNext(after); 00661 if (after != null) 00662 after.setPrev(before); 00663 else 00664 // We were the tail, update the tail 00665 lruTail = before; 00666 } 00667 else 00668 { // We are the LRUHead 00669 lruHead = ce.getNext(); 00670 if (after != null) 00671 after.setPrev(null); 00672 else 00673 // We were the tail, update the tail 00674 lruTail = before; 00675 } 00676 } 00677 } 00678 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.removeFromPendingQueries SelectRequest  request  )  [virtual]
 

Removes an entry from the pending query list.

引数:
request a SelectRequest

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java685 行で定義されています。

参照先 org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL().

00686 { 00687 String sqlQuery = request.getSQL(); 00688 00689 synchronized (pendingQueries) 00690 { 00691 // Remove the pending query from the list and wake up 00692 // all waiting queries 00693 if (pendingQueries.remove(sqlQuery)) 00694 pendingQueries.notifyAll(); 00695 } 00696 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.removeOldest  )  [private]
 

Removes the oldest entry from the cache.

!Warning! This method is not synchronized and should be called in the scope of a synchronized(queries) ResultCache.java807 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getRequest(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.invalidate(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.isValid(), と org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setResult().

00808 { 00809 if (lruTail == null) 00810 return; 00811 // Update the LRU 00812 ResultCacheEntry oldce = (ResultCacheEntry) lruTail; 00813 lruTail = lruTail.getPrev(); 00814 if (lruTail != null) 00815 lruTail.setNext(null); 00816 00817 if (logger.isDebugEnabled()) 00818 logger.debug(Translate.get("resultcache.removing.oldest.cache.entry", 00819 oldce.getRequest().getSQL())); 00820 00821 /* 00822 * We remove the query from the hashtable so that the garbage collector can 00823 * do its job. We need to remove the query from the queries HashTable first 00824 * in case we invalidate an eager cache entry that will call removeFromCache 00825 * (and will try to update the LRU is the entry is still in the queries 00826 * HashTable). So, to be compatible with all type of cache entries: 1. 00827 * queries.remove(ce) 2. ce.invalidate 00828 */ 00829 queries.remove(oldce.getRequest().getSQL()); 00830 00831 if (oldce.isValid()) 00832 { 00833 oldce.setResult(null); 00834 oldce.invalidate(); 00835 } 00836 00837 stats.addRemove(); 00838 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.rollback long  transactionId  )  throws CacheException [virtual]
 

Rollback a transaction given its id.

引数:
transactionId the transaction id
例外:
CacheException if an error occurs

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java878 行で定義されています。

00879 { 00880 logger.info(Translate.get("resultcache.flushing.cache.cause.rollback", 00881 transactionId)); 00882 flushCache(); 00883 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.setDatabaseSchema DatabaseSchema  dbs  ) 
 

Sets the DatabaseSchema of the current virtual database.

引数:
dbs a DatabaseSchema value
参照:
org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseSchema

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを再定義しています。

ResultCache.java183 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.ResultCache.cdbs, org.objectweb.cjdbc.controller.cache.result.ResultCache.flushCache(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getName(), org.objectweb.cjdbc.common.log.Trace.info(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.invalidateAll(), と org.objectweb.cjdbc.common.log.Trace.isInfoEnabled().

00184 { 00185 if (cdbs == null) 00186 { 00187 logger.info(Translate.get("resultcache.setting.database.schema")); 00188 cdbs = new CacheDatabaseSchema(dbs); 00189 } 00190 else 00191 { // Schema is updated, compute the diff ! 00192 CacheDatabaseSchema newSchema = new CacheDatabaseSchema(dbs); 00193 ArrayList tables = cdbs.getTables(); 00194 ArrayList newTables = newSchema.getTables(); 00195 if (newTables == null) 00196 { // New schema is empty (no backend is active anymore) 00197 logger.info(Translate.get("resultcache.flusing.whole.cache")); 00198 flushCache(); 00199 cdbs = null; 00200 return; 00201 } 00202 00203 // Remove extra-tables 00204 for (int i = 0; i < tables.size(); i++) 00205 { 00206 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 00207 if (!newSchema.hasTable(t.getName())) 00208 { 00209 t.invalidateAll(); 00210 cdbs.removeTable(t); 00211 if (logger.isInfoEnabled()) 00212 logger.info(Translate 00213 .get("resultcache.removing.table", t.getName())); 00214 } 00215 } 00216 00217 // Add missing tables 00218 int size = newTables.size(); 00219 for (int i = 0; i < size; i++) 00220 { 00221 CacheDatabaseTable t = (CacheDatabaseTable) newTables.get(i); 00222 if (!cdbs.hasTable(t.getName())) 00223 { 00224 cdbs.addTable(t); 00225 if (logger.isInfoEnabled()) 00226 logger.info(Translate.get("resultcache.adding.table", t.getName())); 00227 } 00228 } 00229 } 00230 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.setDefaultRule ResultCacheRule  defaultRule  )  [virtual]
 

参照:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.setDefaultRule(ResultCacheRule)

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java273 行で定義されています。

00274 { 00275 this.defaultRule = defaultRule; 00276 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.setPendingQueryTimeout int  pendingQueryTimeout  ) 
 

Sets the pending query timeout in seconds.

引数:
pendingQueryTimeout the pending query timeout to set.
参照:
getPendingQueryTimeout
ResultCache.java162 行で定義されています。
00163 { 00164 this.pendingQueryTimeout = pendingQueryTimeout * 1000L; 00165 }

void org.objectweb.cjdbc.controller.cache.result.ResultCache.writeNotify AbstractWriteRequest  request  )  throws CacheException [virtual]
 

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.

引数:
request an AbstractRequest value
例外:
CacheException if an error occurs

org.objectweb.cjdbc.controller.cache.result.AbstractResultCacheを実装しています.

ResultCache.java712 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.invalidateAll().

00713 { 00714 // Update the stats 00715 if (request.isInsert()) 00716 stats.addInsert(); 00717 else if (request.isUpdate()) 00718 stats.addUpdate(); 00719 else if (request.isDelete()) 00720 stats.addDelete(); 00721 else if (request.isCreate()) 00722 { 00723 stats.addCreate(); 00724 // Create: we only need to update the schema 00725 if (parsingGranularity != ParsingGranularities.NO_PARSING) 00726 cdbs.addTable(new CacheDatabaseTable(((CreateRequest) request) 00727 .getDatabaseTable())); 00728 return; 00729 } 00730 else if (request.isDrop()) 00731 { 00732 stats.addDrop(); 00733 // Drop: we need to update the schema 00734 if (parsingGranularity != ParsingGranularities.NO_PARSING) 00735 { 00736 // Invalidate the cache entries associated with this table 00737 CacheDatabaseTable cdt = cdbs.getTable(request.getTableName()); 00738 if (cdt != null) 00739 { 00740 cdt.invalidateAll(); 00741 cdbs.removeTable(cdt); 00742 return; 00743 } 00744 // else: the table was not previously cached 00745 // (no previous 'select' requests on the table). 00746 } 00747 } 00748 else 00749 { 00750 stats.addUnknown(); 00751 } 00752 if (logger.isDebugEnabled()) 00753 logger.debug("Notifying write " + request.getSQL()); 00754 00755 processWriteNotify(request); 00756 }


変数

HashSet org.objectweb.cjdbc.controller.cache.result.ResultCache.cachingRules [private]
 

ResultCache.java98 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.addCachingRule(), org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheBehavior(), と org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

CacheDatabaseSchema org.objectweb.cjdbc.controller.cache.result.ResultCache.cdbs [protected]
 

ResultCache.java108 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.mergeDatabaseSchema(), org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache(), と org.objectweb.cjdbc.controller.cache.result.ResultCache.setDatabaseSchema().

ResultCacheRule org.objectweb.cjdbc.controller.cache.result.ResultCache.defaultRule [private]
 

ResultCache.java99 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.getCacheBehavior(), org.objectweb.cjdbc.controller.cache.result.ResultCache.getDefaultRule(), と org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

CacheEntry org.objectweb.cjdbc.controller.cache.result.ResultCache.lruHead [private]
 

ResultCache.java103 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

CacheEntry org.objectweb.cjdbc.controller.cache.result.ResultCache.lruTail [private]
 

ResultCache.java105 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

int org.objectweb.cjdbc.controller.cache.result.ResultCache.maxEntries [private]
 

ResultCache.java90 行で定義されています。

HashSet org.objectweb.cjdbc.controller.cache.result.ResultCache.pendingQueries [private]
 

ResultCache.java96 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

long org.objectweb.cjdbc.controller.cache.result.ResultCache.pendingQueryTimeout = 0 [private]
 

Pending query timeout in ms. Default is: 0 (wait forever). ResultCache.java92 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.getPendingQueryTimeout().

HashMap org.objectweb.cjdbc.controller.cache.result.ResultCache.queries [private]
 

ResultCache.java94 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

ArrayList org.objectweb.cjdbc.controller.cache.result.ResultCache.relaxedCache [private]
 

ResultCache.java100 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

RelaxedCacheThread org.objectweb.cjdbc.controller.cache.result.ResultCache.relaxedThread [private]
 

ResultCache.java113 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

CacheStatistics org.objectweb.cjdbc.controller.cache.result.ResultCache.stats [private]
 

ResultCache.java110 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

long org.objectweb.cjdbc.controller.cache.result.ResultCache.threadWakeUpTime [private]
 

ResultCache.java112 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.result.ResultCache.ResultCache().

final boolean [] org.objectweb.cjdbc.controller.cache.result.ResultCache.TRUE_TRUE = new boolean[]{true, true} [static, private]
 

ResultCache.java114 行で定義されています。


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:37 2004に生成されました。 doxygen 1.3.8