KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 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): Sara Bouchenak.
23  */

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

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

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

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

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

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

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

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