001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Emmanuel Cecchet.
020: * Contributor(s): Sara Bouchenak.
021: */package org.continuent.sequoia.controller.cache.result;
022:
023: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
024:
025: /**
026: * This class defines request cache granularities.
027: *
028: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
029: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk</a>
030: * @version 1.0
031: */
032: public class CachingGranularities {
033: /**
034: * Database granularity: entries in the cache are invalidated every time a
035: * write (INSERT/UPDATE/DELETE/DROP/...) is sent to the database.
036: */
037: public static final int DATABASE = 0;
038:
039: /**
040: * Table granularity: entries in the cache are invalidated based on table
041: * dependencies.
042: */
043: public static final int TABLE = 1;
044:
045: /**
046: * Column granularity: entries in the cache are invalidated based on column
047: * dependencies.
048: */
049: public static final int COLUMN = 2;
050:
051: /**
052: * Column granularity with <code>UNIQUE</code> queries: same as <code>COLUMN</code>
053: * except that <code>UNIQUE</code> queries that selects a single row based
054: * on a key are invalidated only when needed.
055: */
056: public static final int COLUMN_UNIQUE = 3;
057:
058: /**
059: * Gets the name corresponding to a cache granularity level.
060: *
061: * @param cacheGrain cache granularity level
062: * @return the name of the granularity level
063: */
064: public static final String getGranularityName(int cacheGrain) {
065: switch (cacheGrain) {
066: case DATABASE:
067: return "DATABASE";
068: case TABLE:
069: return "TABLE";
070: case COLUMN:
071: return "COLUMN";
072: case COLUMN_UNIQUE:
073: return "COLUMN_UNIQUE";
074: default:
075: return "UNSUPPORTED";
076: }
077: }
078:
079: /**
080: * This method is needed to convert the value into the corresponding xml
081: * attribute value. If fails, returns noInvalidation granularity value so the
082: * xml retrieved can be used.
083: *
084: * @param cacheGrain cache granularity level
085: * @return the xml attribute value of the granularity level
086: */
087: public static final String getGranularityXml(int cacheGrain) {
088: switch (cacheGrain) {
089: case DATABASE:
090: return DatabasesXmlTags.VAL_database;
091: case TABLE:
092: return DatabasesXmlTags.VAL_table;
093: case COLUMN:
094: return DatabasesXmlTags.VAL_column;
095: case COLUMN_UNIQUE:
096: return DatabasesXmlTags.VAL_columnUnique;
097: default:
098: return DatabasesXmlTags.VAL_noInvalidation;
099: }
100: }
101: }
|