KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > cache > result > ResultCacheTable


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Nicolas Modzyk.
23  */

24
25 package org.objectweb.cjdbc.controller.cache.result;
26
27 import java.util.Iterator JavaDoc;
28
29 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
30 import org.objectweb.cjdbc.common.sql.ParsingGranularities;
31 import org.objectweb.cjdbc.common.sql.SelectRequest;
32 import org.objectweb.cjdbc.common.sql.UpdateRequest;
33 import org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry;
34 import org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable;
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.objectweb.cjdbc.controller.cache.result.ResultCache#processAddToCache
63    */

64   protected void processAddToCache(AbstractResultCacheEntry qe)
65   {
66     SelectRequest request = qe.getRequest();
67     for (Iterator JavaDoc i = request.getFrom().iterator(); i.hasNext();)
68       cdbs.getTable((String JavaDoc) i.next()).addCacheEntry(qe);
69   }
70
71   /**
72    * @see org.objectweb.cjdbc.controller.cache.result.AbstractResultCache#isUpdateNecessary(org.objectweb.cjdbc.common.sql.UpdateRequest)
73    */

74   public boolean isUpdateNecessary(UpdateRequest request)
75   {
76     return true;
77   }
78
79   /**
80    * @see org.objectweb.cjdbc.controller.cache.result.ResultCache#processWriteNotify(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)
81    */

82   protected void processWriteNotify(AbstractWriteRequest request)
83   {
84     CacheDatabaseTable cdt = cdbs.getTable(request.getTableName());
85
86     if (cdt != null)
87       cdt.invalidateAll();
88     else
89     {
90       logger.warn("Table " + request.getTableName()
91           + " not found in cache schema. Flushing whole cache.");
92       flushCache();
93     }
94   }
95
96   /**
97    * @see org.objectweb.cjdbc.controller.cache.result.ResultCache#getName()
98    */

99   public String JavaDoc getName()
100   {
101     return "table";
102   }
103 }
Popular Tags