01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2002-2004 French National Institute For Research In Computer
04: * Science And Control (INRIA).
05: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
06: * Contact: sequoia@continuent.org
07: *
08: * Licensed under the Apache License, Version 2.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: * Initial developer(s): Emmanuel Cecchet.
21: * Contributor(s): Nicolas Modzyk.
22: */package org.continuent.sequoia.controller.cache.result;
23:
24: import java.util.Collection;
25: import java.util.Iterator;
26:
27: import org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry;
28: import org.continuent.sequoia.controller.cache.result.schema.CacheDatabaseTable;
29: import org.continuent.sequoia.controller.requests.AbstractWriteRequest;
30: import org.continuent.sequoia.controller.requests.ParsingGranularities;
31: import org.continuent.sequoia.controller.requests.SelectRequest;
32: import org.continuent.sequoia.controller.requests.UpdateRequest;
33:
34: /**
35: * This is a query cache implementation with a table granularity:
36: * <ul>
37: * <li><code>TABLE</code>: table granularity, entries in the cache are
38: * invalidated based on table dependencies.</li>
39: * </ul>
40: *
41: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
42: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
43: * @version 1.0
44: */
45: public class ResultCacheTable extends ResultCache {
46: /**
47: * Builds a new ResultCache with a table granularity.
48: *
49: * @param maxEntries maximum number of entries
50: * @param pendingTimeout pending timeout for concurrent queries
51: */
52: public ResultCacheTable(int maxEntries, int pendingTimeout) {
53: super (maxEntries, pendingTimeout);
54: parsingGranularity = ParsingGranularities.TABLE;
55: }
56:
57: /**
58: * @see org.continuent.sequoia.controller.cache.result.ResultCache#processAddToCache
59: */
60: protected void processAddToCache(AbstractResultCacheEntry qe) {
61: SelectRequest request = qe.getRequest();
62: Collection from = request.getFrom();
63: if (from == null)
64: return;
65: for (Iterator i = from.iterator(); i.hasNext();)
66: cdbs.getTable((String) i.next()).addCacheEntry(qe);
67: }
68:
69: /**
70: * @see org.continuent.sequoia.controller.cache.result.AbstractResultCache#isUpdateNecessary(org.continuent.sequoia.controller.requests.UpdateRequest)
71: */
72: public boolean isUpdateNecessary(UpdateRequest request) {
73: return true;
74: }
75:
76: /**
77: * @see org.continuent.sequoia.controller.cache.result.ResultCache#processWriteNotify(org.continuent.sequoia.controller.requests.AbstractWriteRequest)
78: */
79: protected void processWriteNotify(AbstractWriteRequest request) {
80: CacheDatabaseTable cdt = cdbs.getTable(request.getTableName());
81:
82: if (cdt != null)
83: cdt.invalidateAll();
84: else {
85: logger
86: .warn("Table "
87: + request.getTableName()
88: + " not found in cache schema. Flushing whole cache.");
89: flushCache();
90: }
91: }
92:
93: /**
94: * @see org.continuent.sequoia.controller.cache.result.ResultCache#getName()
95: */
96: public String getName() {
97: return "table";
98: }
99: }
|