KickJava   Java API By Example, From Geeks To Geeks.

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


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 Modrzyk.
22  */

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

51
52 public class ResultCacheColumn extends ResultCache
53 {
54   /**
55    * Builds a new ResultCache with a Column granularity.
56    *
57    * @param maxEntries maximum number of entries
58    * @param pendingTimeout pending timeout for concurrent queries
59    */

60   public ResultCacheColumn(int maxEntries, int pendingTimeout)
61   {
62     super(maxEntries, pendingTimeout);
63     parsingGranularity = ParsingGranularities.COLUMN;
64   }
65
66   /**
67    * @see org.continuent.sequoia.controller.cache.result.ResultCache#processAddToCache(AbstractResultCacheEntry)
68    */

69   public void processAddToCache(AbstractResultCacheEntry qe)
70   {
71     SelectRequest request = qe.getRequest();
72     ArrayList JavaDoc selectedColumns = request.getSelect();
73     // Update the tables columns dependencies
74
if (selectedColumns == null || selectedColumns.isEmpty())
75     {
76       logger
77           .warn("No parsing of select clause found - Fallback to table granularity");
78       Collection JavaDoc from = request.getFrom();
79       if (from == null)
80         return;
81       for (Iterator JavaDoc i = from.iterator(); i.hasNext();)
82       {
83         CacheDatabaseTable table = cdbs.getTable((String JavaDoc) i.next());
84         table.addCacheEntry(qe);
85         // Add all columns, entries will be added below.
86
ArrayList JavaDoc columns = table.getColumns();
87         for (int j = 0; j < columns.size(); j++)
88         {
89           ((CacheDatabaseColumn) columns.get(j)).addCacheEntry(qe);
90         }
91         return;
92       }
93     }
94     for (Iterator JavaDoc i = selectedColumns.iterator(); i.hasNext();)
95     {
96       TableColumn tc = (TableColumn) i.next();
97       cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
98           .addCacheEntry(qe);
99     }
100     if (request.getWhere() != null)
101       for (Iterator JavaDoc i = request.getWhere().iterator(); i.hasNext();)
102       {
103         TableColumn tc = (TableColumn) i.next();
104         cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
105             .addCacheEntry(qe);
106       }
107   }
108
109   /**
110    * @see org.continuent.sequoia.controller.cache.result.AbstractResultCache#isUpdateNecessary(org.continuent.sequoia.controller.requests.UpdateRequest)
111    */

112   public boolean isUpdateNecessary(UpdateRequest request)
113   {
114     return true;
115   }
116
117   /**
118    * @see org.continuent.sequoia.controller.cache.result.ResultCache#processWriteNotify(AbstractRequest)
119    */

120   protected void processWriteNotify(AbstractRequest request)
121   {
122     // Columns parsing not supported anymore
123
for (Iterator JavaDoc iter = request.getSemantic().getWriteSet().iterator(); iter
124         .hasNext();)
125     {
126       String JavaDoc tableName = (String JavaDoc) iter.next();
127       CacheDatabaseTable cdt = cdbs.getTable(tableName);
128
129       if (cdt != null)
130         cdt.invalidateAll();
131       else
132       {
133         logger.warn("Table " + tableName
134             + " not found in cache schema. Flushing whole cache.");
135         flushCache();
136       }
137     }
138   }
139
140   /**
141    * @see org.continuent.sequoia.controller.cache.result.ResultCache#getName()
142    */

143   public String JavaDoc getName()
144   {
145     return "column";
146   }
147
148 }
Popular Tags