KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > cache > result > ResultCacheTable


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * 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  */

23
24 package org.continuent.sequoia.controller.cache.result;
25
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry;
30 import org.continuent.sequoia.controller.cache.result.schema.CacheDatabaseTable;
31 import org.continuent.sequoia.controller.requests.AbstractRequest;
32 import org.continuent.sequoia.controller.requests.ParsingGranularities;
33 import org.continuent.sequoia.controller.requests.SelectRequest;
34 import org.continuent.sequoia.controller.requests.UpdateRequest;
35
36 /**
37  * This is a query cache implementation with a table granularity:
38  * <ul>
39  * <li><code>TABLE</code>: table granularity, entries in the cache are
40  * invalidated based on table dependencies.</li>
41  * </ul>
42  *
43  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
44  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
45  * @version 1.0
46  */

47 public class ResultCacheTable extends ResultCache
48 {
49   /**
50    * Builds a new ResultCache with a table granularity.
51    *
52    * @param maxEntries maximum number of entries
53    * @param pendingTimeout pending timeout for concurrent queries
54    */

55   public ResultCacheTable(int maxEntries, int pendingTimeout)
56   {
57     super(maxEntries, pendingTimeout);
58     parsingGranularity = ParsingGranularities.TABLE;
59   }
60
61   /**
62    * @see org.continuent.sequoia.controller.cache.result.ResultCache#processAddToCache
63    */

64   protected void processAddToCache(AbstractResultCacheEntry qe)
65   {
66     SelectRequest request = qe.getRequest();
67     Collection JavaDoc from = request.getFrom();
68     if (from == null)
69       return;
70     for (Iterator JavaDoc i = from.iterator(); i.hasNext();)
71       cdbs.getTable((String JavaDoc) i.next()).addCacheEntry(qe);
72   }
73
74   /**
75    * @see org.continuent.sequoia.controller.cache.result.AbstractResultCache#isUpdateNecessary(org.continuent.sequoia.controller.requests.UpdateRequest)
76    */

77   public boolean isUpdateNecessary(UpdateRequest request)
78   {
79     return true;
80   }
81
82   /**
83    * @see org.continuent.sequoia.controller.cache.result.ResultCache#processWriteNotify(AbstractRequest)
84    */

85   protected void processWriteNotify(AbstractRequest request)
86   {
87     for (Iterator JavaDoc iter = request.getSemantic().getWriteSet().iterator(); iter
88         .hasNext();)
89     {
90       String JavaDoc tableName = (String JavaDoc) iter.next();
91       CacheDatabaseTable cdt = cdbs.getTable(tableName);
92
93       if (cdt != null)
94         cdt.invalidateAll();
95       else
96       {
97         logger.warn("Table " + tableName
98             + " not found in cache schema. Flushing whole cache.");
99         flushCache();
100       }
101     }
102   }
103
104   /**
105    * @see org.continuent.sequoia.controller.cache.result.ResultCache#getName()
106    */

107   public String JavaDoc getName()
108   {
109     return "table";
110   }
111 }
Popular Tags