KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Emmanuel Cecchet.
20  * Contributor(s): Sara Bouchenak.
21  */

22
23 package org.continuent.sequoia.controller.cache.result;
24
25 import org.continuent.sequoia.common.xml.DatabasesXmlTags;
26
27 /**
28  * This class defines request cache granularities.
29  *
30  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
31  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk</a>
32  * @version 1.0
33  */

34 public class CachingGranularities
35 {
36   /**
37    * Database granularity: entries in the cache are invalidated every time a
38    * write (INSERT/UPDATE/DELETE/DROP/...) is sent to the database.
39    */

40   public static final int DATABASE = 0;
41
42   /**
43    * Table granularity: entries in the cache are invalidated based on table
44    * dependencies.
45    */

46   public static final int TABLE = 1;
47
48   /**
49    * Column granularity: entries in the cache are invalidated based on column
50    * dependencies.
51    */

52   public static final int COLUMN = 2;
53
54   /**
55    * Column granularity with <code>UNIQUE</code> queries: same as <code>COLUMN</code>
56    * except that <code>UNIQUE</code> queries that selects a single row based
57    * on a key are invalidated only when needed.
58    */

59   public static final int COLUMN_UNIQUE = 3;
60
61   /**
62    * Gets the name corresponding to a cache granularity level.
63    *
64    * @param cacheGrain cache granularity level
65    * @return the name of the granularity level
66    */

67   public static final String JavaDoc getGranularityName(int cacheGrain)
68   {
69     switch (cacheGrain)
70     {
71       case DATABASE :
72         return "DATABASE";
73       case TABLE :
74         return "TABLE";
75       case COLUMN :
76         return "COLUMN";
77       case COLUMN_UNIQUE :
78         return "COLUMN_UNIQUE";
79       default :
80         return "UNSUPPORTED";
81     }
82   }
83
84   /**
85    * This method is needed to convert the value into the corresponding xml
86    * attribute value. If fails, returns noInvalidation granularity value so the
87    * xml retrieved can be used.
88    *
89    * @param cacheGrain cache granularity level
90    * @return the xml attribute value of the granularity level
91    */

92   public static final String JavaDoc getGranularityXml(int cacheGrain)
93   {
94     switch (cacheGrain)
95     {
96       case DATABASE :
97         return DatabasesXmlTags.VAL_database;
98       case TABLE :
99         return DatabasesXmlTags.VAL_table;
100       case COLUMN :
101         return DatabasesXmlTags.VAL_column;
102       case COLUMN_UNIQUE :
103         return DatabasesXmlTags.VAL_columnUnique;
104       default :
105         return DatabasesXmlTags.VAL_noInvalidation;
106     }
107   }
108 }
109
Popular Tags