Public Member Functions | |
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 () |
ArrayList | getEagerCache () |
ArrayList | getRelaxedCache () |
Protected Member Functions | |
abstract void | processAddToCache (CacheEntry qe) |
abstract void | processWriteNotify (AbstractWriteRequest request) |
String | getXmlImpl () |
Protected Attributes | |
CacheDatabaseSchema | cdbs |
NO_INVALIDATE
: no invalidation, the cache is inconsistent and this should just be used to determine hit ratio upper bound. DATABASE
: the cache is flushed each time the database is updated (every INSERT, UPDATE, DELETE, ... statement). TABLE
: table granularity, entries in the cache are invalidated based on table dependencies. COLUMN
: column granularity, entries in the cache are invalidated based on column dependencies COLUMN_UNIQUE
: same as COLUMN
except that UNIQUE
queries that selects a single row based on a key are invalidated only when needed.
Definition at line 79 of file ResultCache.java.
|
Creates a new
Definition at line 130 of file ResultCache.java. 00131 { 00132 this.maxEntries = maxEntries; 00133 this.pendingQueryTimeout = pendingTimeout; 00134 cdbs = null; 00135 stats = new CacheStatistics(); 00136 queries = new HashMap(1000, (float) 0.75); 00137 pendingQueries = new HashSet(); 00138 cachingRules = new HashSet(); 00139 relaxedCache = new ArrayList(); 00140 eagerCache = new ArrayList(); 00141 lruHead = null; 00142 lruTail = null; 00143 defaultRule = null; 00144 relaxedThread = new RelaxedCacheThread(this); 00145 relaxedThread.setPriority(9); 00146 relaxedThread.start(); 00147 eagerThread = new EagerCacheThread(this); 00148 eagerThread.setPriority(9); 00149 eagerThread.start(); 00150 }
|
|
Add a rule for this
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 264 of file ResultCache.java. 00265 { 00266 cachingRules.add(rule); 00267 }
|
|
Adds an entry request/reply to the cache. Note that if the request was already in the cache, only the result is updated.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 390 of file ResultCache.java. References org.objectweb.cjdbc.controller.cache.result.CacheBehavior.getCacheEntry(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryEager.getDeadline(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntryRelaxed.getDeadline(), and org.objectweb.cjdbc.controller.cache.result.entries.CacheEntry.NO_DEADLINE. 00392 { 00393 String sqlQuery = request.getSQL(); 00394 00395 // Sanity checks 00396 if (request.getCacheAbility() == RequestType.UNCACHEABLE) 00397 throw new CacheException(Translate.get("resultcache.uncacheable.request", 00398 sqlQuery)); 00399 00400 if (result == null) 00401 throw new CacheException(Translate.get("resultcache.null.result", 00402 sqlQuery)); 00403 00404 boolean notifyThread = false; 00405 00406 try 00407 { 00408 synchronized (pendingQueries) 00409 { 00410 // Remove the pending query from the list and wake up 00411 // all waiting queries 00412 if (pendingQueries.remove(sqlQuery)) 00413 { 00414 if (logger.isDebugEnabled()) 00415 logger.debug(Translate.get("resultcache.removing.pending.query", 00416 sqlQuery)); 00417 pendingQueries.notifyAll(); 00418 } 00419 else 00420 logger.warn(Translate.get( 00421 "resultcache.removing.pending.query.failed", sqlQuery)); 00422 00423 // Check against streamable ResultSets 00424 if (result.hasMoreData()) 00425 { 00426 logger.info(Translate.get("resultcache.streamed.resultset", request 00427 .getSQLShortForm(20))); 00428 return; 00429 } 00430 00431 if (logger.isDebugEnabled()) 00432 logger.debug(Translate.get("resultcache.adding.query", sqlQuery)); 00433 00434 CacheEntry ce; 00435 synchronized (queries) 00436 { 00437 // Check first that the query is not already in the cache 00438 ce = (ResultCacheEntry) queries.get(sqlQuery); 00439 if (ce == null) 00440 { 00441 // Not in cache, add this entry 00442 // check the rule 00443 CacheBehavior behavior = getCacheBehavior(request); 00444 ce = behavior.getCacheEntry(request, result, this); 00445 if (ce instanceof ResultCacheEntryNoCache) 00446 return; 00447 00448 // Test size of cache 00449 if (maxEntries > 0) 00450 { 00451 int size = queries.size(); 00452 if (size >= maxEntries) 00453 // LRU replacement policy: Remove the oldest cache entry 00454 removeOldest(); 00455 } 00456 // Add to the cache 00457 queries.put(sqlQuery, ce); 00458 00459 notifyThread = true; 00460 00461 } 00462 else 00463 { // Oh, oh, already in cache ... 00464 if (ce.isValid()) 00465 logger.warn(Translate.get( 00466 "resultcache.modifying.result.valid.entry", sqlQuery)); 00467 ce.setResult(result); 00468 } 00469 00470 // Update LRU 00471 if (lruHead != null) 00472 { 00473 lruHead.setPrev(ce); 00474 ce.setNext(lruHead); 00475 ce.setPrev(null); 00476 } 00477 if (lruTail == null) 00478 lruTail = ce; 00479 lruHead = ce; // This is also fine if LRUHead == null 00480 } 00481 processAddToCache(ce); 00482 00483 // process thread notification out of the synchronized block on 00484 // pending queries to avoid deadlock, while adding/removing 00485 // on cache 00486 if (notifyThread) 00487 { 00488 // relaxed entry 00489 if (ce instanceof ResultCacheEntryRelaxed) 00490 { 00491 ResultCacheEntryRelaxed qcer = (ResultCacheEntryRelaxed) ce; 00492 synchronized (relaxedThread) 00493 { 00494 relaxedCache.add(qcer); 00495 if (qcer.getDeadline() < relaxedThread.getThreadWakeUpTime() 00496 || relaxedThread.getThreadWakeUpTime() == 0) 00497 { 00498 relaxedThread.notify(); 00499 } 00500 } 00501 } 00502 else if (ce instanceof ResultCacheEntryEager) 00503 { 00504 // eager entry 00505 ResultCacheEntryEager qcee = (ResultCacheEntryEager) ce; 00506 if (qcee.getDeadline() != ResultCacheEntry.NO_DEADLINE) 00507 { // Only deal with entries that specify a timeout 00508 synchronized (eagerThread) 00509 { 00510 eagerCache.add(qcee); 00511 if (qcee.getDeadline() < eagerThread.getThreadWakeUpTime() 00512 || eagerThread.getThreadWakeUpTime() == 0) 00513 { 00514 eagerThread.notify(); 00515 } 00516 } 00517 } 00518 } 00519 } 00520 00521 } 00522 } 00523 catch (OutOfMemoryError oome) 00524 { 00525 flushCache(); 00526 System.gc(); 00527 logger.warn(Translate.get("cache.memory.error.cache.flushed", this 00528 .getClass())); 00529 } 00530 }
|
|
Commit a transaction given its id.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 935 of file ResultCache.java. 00936 {
00937 // Ok, the transaction has commited, nothing to do
00938 }
|
|
Removes all entries from the cache. Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 819 of file ResultCache.java. Referenced by org.objectweb.cjdbc.controller.cache.result.ResultCacheTable.processWriteNotify(), org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase.processWriteNotify(), and org.objectweb.cjdbc.controller.cache.result.ResultCache.setDatabaseSchema(). 00820 { 00821 // Check if we are already flushing the cache 00822 synchronized (this) 00823 { 00824 if (flushingCache) 00825 return; 00826 flushingCache = true; 00827 } 00828 00829 try 00830 { 00831 synchronized (queries) 00832 { // Invalidate the whole cache until it is empty 00833 while (!queries.isEmpty()) 00834 { 00835 Iterator iter = queries.values().iterator(); 00836 ((ResultCacheEntry) iter.next()).invalidate(); 00837 } 00838 } 00839 00840 synchronized (pendingQueries) 00841 { // Clean pending queries to unblock everyone if some queries/backends 00842 // remained in an unstable state. 00843 pendingQueries.clear(); 00844 pendingQueries.notifyAll(); 00845 } 00846 } 00847 finally 00848 { 00849 synchronized (this) 00850 { 00851 flushingCache = false; 00852 } 00853 if (logger.isDebugEnabled()) 00854 logger.debug(Translate.get("resultcache.cache.flushed")); 00855 } 00856 }
|
|
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 960 of file ResultCache.java. References org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.next, and org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.toStringTable(). 00961 { 00962 try 00963 { 00964 synchronized (queries) 00965 { 00966 String[][] data = new String[queries.size()][]; 00967 int count = 0; 00968 for (Iterator iter = queries.values().iterator(); iter.hasNext(); count++) 00969 { 00970 ResultCacheEntry qe = (ResultCacheEntry) iter.next(); 00971 if (qe != null) 00972 { 00973 data[count] = qe.toStringTable(); 00974 } 00975 } 00976 return data; 00977 } 00978 } 00979 catch (Exception e) 00980 { 00981 logger.error(Translate.get("resultcache.error.retrieving.cache.data", e)); 00982 throw new CacheException(e.getMessage()); 00983 } 00984 }
|
|
Get Cache size
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 863 of file ResultCache.java. 00864 { 00865 // No need to synchronize, the implementation returns an int 00866 return queries.size(); 00867 }
|
|
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 1003 of file ResultCache.java. 01004 {
01005 return stats;
01006 }
|
|
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 989 of file ResultCache.java. 00990 { 00991 String[][] data = new String[1][]; 00992 String[] stat = stats.getCacheStatsData(); 00993 data[0] = new String[stat.length + 1]; 00994 for (int i = 0; i < stat.length; i++) 00995 data[0][i] = stat[i]; 00996 data[0][data[0].length - 1] = "" + queries.size(); 00997 return data; 00998 }
|
|
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 272 of file ResultCache.java. 00273 {
00274 return defaultRule;
00275 }
|
|
Returns the eagerCache value.
Definition at line 1013 of file ResultCache.java. Referenced by org.objectweb.cjdbc.controller.cache.result.threads.EagerCacheThread.run(). 01014 {
01015 return eagerCache;
01016 }
|
|
Gets the result to the given request from the cache. The returned
An invalid
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 554 of file ResultCache.java. References org.objectweb.cjdbc.common.sql.SelectRequest.debug(), 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(), and org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setPrev(). 00556 { 00557 stats.addSelect(); 00558 00559 if (request.getCacheAbility() == RequestType.UNCACHEABLE) 00560 { 00561 stats.addUncacheable(); 00562 return null; 00563 } 00564 00565 String sqlQuery = request.getSQL(); 00566 00567 // Check if we have the same query pending 00568 synchronized (pendingQueries) 00569 { 00570 if (addToPendingQueries) 00571 { 00572 long timeout = pendingQueryTimeout; 00573 // Yes, wait for the result 00574 // As we use a single lock for all pending queries, we use a 00575 // while to re-check that this wake-up was for us! 00576 while (pendingQueries.contains(sqlQuery)) 00577 { 00578 try 00579 { 00580 if (logger.isDebugEnabled()) 00581 logger.debug(Translate.get("resultcache.waiting.pending.query", 00582 sqlQuery)); 00583 00584 if (timeout > 0) 00585 { 00586 long start = System.currentTimeMillis(); 00587 pendingQueries.wait(pendingQueryTimeout); 00588 long end = System.currentTimeMillis(); 00589 timeout = timeout - (end - start); 00590 if (timeout <= 0) 00591 { 00592 logger.warn(Translate.get("resultcache.pending.query.timeout")); 00593 break; 00594 } 00595 } 00596 else 00597 pendingQueries.wait(); 00598 } 00599 catch (InterruptedException e) 00600 { 00601 logger.warn(Translate.get("resultcache.pending.query.timeout")); 00602 break; 00603 } 00604 } 00605 } 00606 00607 // Check the cache 00608 ResultCacheEntry ce; 00609 synchronized (queries) 00610 { 00611 ce = (ResultCacheEntry) queries.get(sqlQuery); 00612 if (ce == null) 00613 // if ((ce == null) || !ce.isValid()) 00614 { // Cache miss or dirty entry 00615 if (addToPendingQueries) 00616 { 00617 pendingQueries.add(sqlQuery); 00618 // Add this query to the pending queries 00619 if (logger.isDebugEnabled()) 00620 { 00621 logger.debug(Translate.get("resultcache.cache.miss")); 00622 logger.debug(Translate.get( 00623 "resultcache.adding.to.pending.queries", sqlQuery)); 00624 } 00625 } 00626 return null; 00627 } 00628 else 00629 { // Cache hit (must update LRU) 00630 // Move cache entry to head of LRU 00631 CacheEntry before = ce.getPrev(); 00632 if (before != null) 00633 { 00634 CacheEntry after = ce.getNext(); 00635 before.setNext(after); 00636 if (after != null) 00637 after.setPrev(before); 00638 else 00639 // We were the tail, update the tail 00640 lruTail = before; 00641 ce.setNext(lruHead); 00642 ce.setPrev(null); 00643 if (lruHead != ce) 00644 lruHead.setPrev(ce); 00645 lruHead = ce; 00646 } 00647 // else it was already the LRU head 00648 } 00649 } 00650 00651 if (ce.getResult() == null) 00652 { 00653 if (addToPendingQueries) 00654 { 00655 pendingQueries.add(sqlQuery); 00656 // Add this query to the pending queries 00657 if (logger.isDebugEnabled()) 00658 { 00659 logger.debug(Translate.get("resultcache.cache.miss")); 00660 logger.debug(Translate.get("resultcache.adding.to.pending.queries", 00661 sqlQuery)); 00662 } 00663 } 00664 if (ce.isValid() && logger.isInfoEnabled()) 00665 logger.info(Translate.get("resultcache.valid.entry.without.result", 00666 ce.getRequest().getSQL())); 00667 } 00668 else 00669 { 00670 if (logger.isDebugEnabled()) 00671 logger.debug(Translate.get("resultcache.cache.hit", sqlQuery)); 00672 stats.addHits(); 00673 } 00674 00675 return ce; 00676 } 00677 }
|
|
Retrieve the name of this cache
Implemented in org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, and org.objectweb.cjdbc.controller.cache.result.ResultCacheTable. |
|
Gets the needed query parsing granularity.
Reimplemented from org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 913 of file ResultCache.java. 00914 { 00915 return this.parsingGranularity; 00916 }
|
|
Returns the pending query timeout in seconds.
Definition at line 158 of file ResultCache.java. 00159 {
00160 return (int) (pendingQueryTimeout / 1000);
00161 }
|
|
Possibly we want to access the queries in the cache for timing purposes
Definition at line 179 of file ResultCache.java. 00180 { 00181 return this.queries; 00182 }
|
|
Returns the relaxedCache value.
Definition at line 1023 of file ResultCache.java. Referenced by org.objectweb.cjdbc.controller.cache.result.threads.RelaxedCacheThread.run(). 01024 {
01025 return relaxedCache;
01026 }
|
|
Gets information about the request cache
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 1033 of file ResultCache.java. 01034 { 01035 StringBuffer info = new StringBuffer(); 01036 info.append("<" + DatabasesXmlTags.ELT_ResultCache + " " 01037 + DatabasesXmlTags.ATT_pendingTimeout + "=\"" + pendingQueryTimeout 01038 + "\" " + DatabasesXmlTags.ATT_maxNbOfEntries + "=\"" + maxEntries 01039 + "\" " + DatabasesXmlTags.ATT_granularity + "=\"" + getName() + "\">"); 01040 info.append("<" + DatabasesXmlTags.ELT_DefaultResultCacheRule + " " 01041 + DatabasesXmlTags.ATT_timestampResolution + "=\"" 01042 + defaultRule.getTimestampResolution() / 1000 + "\">"); 01043 info.append(defaultRule.getCacheBehavior().getXml()); 01044 info.append("</" + DatabasesXmlTags.ELT_DefaultResultCacheRule + ">"); 01045 for (Iterator iter = cachingRules.iterator(); iter.hasNext();) 01046 info.append(((ResultCacheRule) iter.next()).getXml()); 01047 info.append("</" + DatabasesXmlTags.ELT_ResultCache + ">"); 01048 return info.toString(); 01049 }
|
|
|
Merge the given
Reimplemented from org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 245 of file ResultCache.java. References org.objectweb.cjdbc.common.log.Trace.error(), and org.objectweb.cjdbc.common.log.Trace.info(). 00246 { 00247 try 00248 { 00249 logger.info(Translate.get("resultcache.merging.new.database.schema")); 00250 cdbs.mergeSchema(new CacheDatabaseSchema(dbs)); 00251 } 00252 catch (Exception e) 00253 { 00254 logger.error(Translate.get("resultcache.error.while.merging", e)); 00255 } 00256 }
|
|
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).
Definition at line 326 of file ResultCache.java. References org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet.getData(), org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet.getFields(), and org.objectweb.cjdbc.common.sql.UpdateRequest.getUpdatedValues(). Referenced by org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.isUpdateNecessary(), and org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processWriteNotify(). 00328 { 00329 HashMap updatedValues = request.getUpdatedValues(); 00330 boolean needInvalidate = false; 00331 boolean needToSendQuery = false; 00332 String value; 00333 String columnName; 00334 try 00335 { 00336 // If we don't have exactly one row, we don't handle the optimization 00337 if ((result == null) || (result.getData() == null) 00338 || (result.getData().size() != 1)) 00339 return TRUE_TRUE; 00340 } 00341 catch (Exception e) 00342 { 00343 return TRUE_TRUE; 00344 } 00345 Field[] fields = result.getFields(); 00346 ArrayList data = result.getData(); 00347 int size = fields.length; 00348 for (Iterator iter = updatedValues.keySet().iterator(); iter.hasNext();) 00349 { 00350 columnName = (String) iter.next(); 00351 value = (String) updatedValues.get(columnName); 00352 for (int i = 0; i < size; i++) 00353 { // Find the corresponding column in the ResultSet by comparing column 00354 // names 00355 00356 // We can have something like: 00357 // FIRSTNAME and ADDRESS.FIRSTNAME 00358 if (columnName.equals(fields[i].getFieldName())) 00359 { 00360 Object o = ((Object[]) data.get(0))[i]; 00361 if (!value.equals(o)) 00362 { 00363 // The value from the cache entry is different we need to update 00364 // the 00365 // cache and the database 00366 return TRUE_TRUE; 00367 } 00368 else 00369 break; 00370 } 00371 } 00372 // We don't need to invalidate the cache because the columns affected are 00373 // different but we need to send the query to the database. 00374 needToSendQuery = true; 00375 // We don't stop here though because other columns could be updated and 00376 // we 00377 // could need invalidation 00378 } 00379 return new boolean[]{needInvalidate, needToSendQuery}; 00380 }
|
|
Process the add to cache to update implementation specific data structures.
Implemented in org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, and org.objectweb.cjdbc.controller.cache.result.ResultCacheTable. |
|
Implementation specific invalidation of the cache.
Implemented in org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn, org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique, org.objectweb.cjdbc.controller.cache.result.ResultCacheDatabase, and org.objectweb.cjdbc.controller.cache.result.ResultCacheTable. |
|
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.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 686 of file ResultCache.java. References org.objectweb.cjdbc.common.sql.SelectRequest.debug(), 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.setNext(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setPrev(), and org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.setResult(). Referenced by org.objectweb.cjdbc.controller.cache.result.threads.EagerCacheThread.run(). 00687 { 00688 String sqlQuery = request.getSQL(); 00689 00690 if (logger.isDebugEnabled()) 00691 logger.debug("Removing from cache: " + sqlQuery); 00692 00693 synchronized (queries) 00694 { 00695 // Remove from the cache 00696 ResultCacheEntry ce = (ResultCacheEntry) queries.remove(sqlQuery); 00697 if (ce == null) 00698 return; // Was not in the cache! 00699 else 00700 { 00701 // Update result set 00702 ce.setResult(null); 00703 // Update LRU 00704 CacheEntry before = ce.getPrev(); 00705 CacheEntry after = ce.getNext(); 00706 if (before != null) 00707 { 00708 before.setNext(after); 00709 if (after != null) 00710 after.setPrev(before); 00711 else 00712 // We were the tail, update the tail 00713 lruTail = before; 00714 } 00715 else 00716 { // We are the LRUHead 00717 lruHead = ce.getNext(); 00718 if (after != null) 00719 after.setPrev(null); 00720 else 00721 // We were the tail, update the tail 00722 lruTail = before; 00723 } 00724 // Remove links to other cache entries for GC 00725 ce.setNext(null); 00726 ce.setPrev(null); 00727 } 00728 } 00729 }
|
|
Removes an entry from the pending query list.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 736 of file ResultCache.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(). 00737 { 00738 String sqlQuery = request.getSQL(); 00739 00740 synchronized (pendingQueries) 00741 { 00742 // Remove the pending query from the list and wake up 00743 // all waiting queries 00744 if (pendingQueries.remove(sqlQuery)) 00745 pendingQueries.notifyAll(); 00746 } 00747 }
|
|
Rollback a transaction given its id.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 946 of file ResultCache.java. 00947 { 00948 logger.info(Translate.get("resultcache.flushing.cache.cause.rollback", 00949 transactionId)); 00950 flushCache(); 00951 }
|
|
Sets the
Reimplemented from org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 190 of file ResultCache.java. References 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(), and org.objectweb.cjdbc.common.log.Trace.isInfoEnabled(). 00191 { 00192 if (cdbs == null) 00193 { 00194 logger.info(Translate.get("resultcache.setting.database.schema")); 00195 cdbs = new CacheDatabaseSchema(dbs); 00196 } 00197 else 00198 { // Schema is updated, compute the diff ! 00199 CacheDatabaseSchema newSchema = new CacheDatabaseSchema(dbs); 00200 ArrayList tables = cdbs.getTables(); 00201 ArrayList newTables = newSchema.getTables(); 00202 if (newTables == null) 00203 { // New schema is empty (no backend is active anymore) 00204 logger.info(Translate.get("resultcache.flusing.whole.cache")); 00205 flushCache(); 00206 cdbs = null; 00207 return; 00208 } 00209 00210 // Remove extra-tables 00211 for (int i = 0; i < tables.size(); i++) 00212 { 00213 CacheDatabaseTable t = (CacheDatabaseTable) tables.get(i); 00214 if (!newSchema.hasTable(t.getName())) 00215 { 00216 t.invalidateAll(); 00217 cdbs.removeTable(t); 00218 if (logger.isInfoEnabled()) 00219 logger.info(Translate 00220 .get("resultcache.removing.table", t.getName())); 00221 } 00222 } 00223 00224 // Add missing tables 00225 int size = newTables.size(); 00226 for (int i = 0; i < size; i++) 00227 { 00228 CacheDatabaseTable t = (CacheDatabaseTable) newTables.get(i); 00229 if (!cdbs.hasTable(t.getName())) 00230 { 00231 cdbs.addTable(t); 00232 if (logger.isInfoEnabled()) 00233 logger.info(Translate.get("resultcache.adding.table", t.getName())); 00234 } 00235 } 00236 } 00237 }
|
|
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 280 of file ResultCache.java. 00281 {
00282 this.defaultRule = defaultRule;
00283 }
|
|
Sets the pending query timeout in seconds.
Definition at line 169 of file ResultCache.java. 00170 {
00171 this.pendingQueryTimeout = pendingQueryTimeout * 1000L;
00172 }
|
|
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.
Implements org.objectweb.cjdbc.controller.cache.result.AbstractResultCache. Definition at line 763 of file ResultCache.java. References org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.invalidateAll(). 00764 { 00765 // Update the stats 00766 if (request.isInsert()) 00767 stats.addInsert(); 00768 else if (request.isUpdate()) 00769 stats.addUpdate(); 00770 else if (request.isDelete()) 00771 stats.addDelete(); 00772 else if (request.isCreate()) 00773 { 00774 stats.addCreate(); 00775 // Create: we only need to update the schema 00776 if (parsingGranularity != ParsingGranularities.NO_PARSING) 00777 cdbs.addTable(new CacheDatabaseTable(((CreateRequest) request) 00778 .getDatabaseTable())); 00779 return; 00780 } 00781 else if (request.isDrop()) 00782 { 00783 stats.addDrop(); 00784 // Drop: we need to update the schema 00785 if (parsingGranularity != ParsingGranularities.NO_PARSING) 00786 { 00787 // Invalidate the cache entries associated with this table 00788 CacheDatabaseTable cdt = cdbs.getTable(request.getTableName()); 00789 if (cdt != null) 00790 { 00791 cdt.invalidateAll(); 00792 cdbs.removeTable(cdt); 00793 return; 00794 } 00795 // else: the table was not previously cached 00796 // (no previous 'select' requests on the table). 00797 } 00798 } 00799 else 00800 { 00801 stats.addUnknown(); 00802 } 00803 if (logger.isDebugEnabled()) 00804 logger.debug("Notifying write " + request.getSQL()); 00805 00806 processWriteNotify(request); 00807 }
|