Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ResultCacheFactory.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): 
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.cache.result;
00026 
00027 import java.util.Hashtable;
00028 
00029 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00030 import org.objectweb.cjdbc.controller.cache.result.rules.EagerCaching;
00031 import org.objectweb.cjdbc.controller.cache.result.rules.NoCaching;
00032 import org.objectweb.cjdbc.controller.cache.result.rules.RelaxedCaching;
00033 
00034 /**
00035  * Create a cache that conforms to AbstractResultCache, that is implementation
00036  * independant
00037  * 
00038  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00039  */
00040 public class ResultCacheFactory
00041 {
00042   /**
00043    * Get an instance of the current cache implementation
00044    * 
00045    * @param granularityValue of the parsing
00046    * @param maxEntries to the cache
00047    * @param pendingTimeout before pending query timeout
00048    * @return <code>ResultCache</code> implementation of the
00049    *         <code>AbstractResultCache</code>
00050    * @throws InstantiationException if parsing granularity is not valid
00051    */
00052   public static AbstractResultCache getCacheInstance(int granularityValue,
00053       int maxEntries, int pendingTimeout) throws InstantiationException
00054   {
00055     AbstractResultCache currentRequestCache = null;
00056     switch (granularityValue)
00057     {
00058       case CachingGranularities.TABLE :
00059         currentRequestCache = new ResultCacheTable(maxEntries, pendingTimeout);
00060         break;
00061       case CachingGranularities.DATABASE :
00062         currentRequestCache = new ResultCacheDatabase(maxEntries,
00063             pendingTimeout);
00064         break;
00065       case CachingGranularities.COLUMN :
00066         currentRequestCache = new ResultCacheColumn(maxEntries, pendingTimeout);
00067         break;
00068       case CachingGranularities.COLUMN_UNIQUE :
00069         currentRequestCache = new ResultCacheColumnUnique(maxEntries,
00070             pendingTimeout);
00071         break;
00072       default :
00073         throw new InstantiationException("Invalid Granularity Value");
00074     }
00075     return currentRequestCache;
00076   }
00077 
00078   /**
00079    * Get an instance of a cache behavior for this cache
00080    * 
00081    * @param behaviorString representation of this cache behavior, xml tag
00082    * @param options for different cache rules
00083    * @return an instance of a cache behavior
00084    */
00085   public static CacheBehavior getCacheBehaviorInstance(String behaviorString,
00086       Hashtable options)
00087   {
00088     if (behaviorString.equalsIgnoreCase(DatabasesXmlTags.ELT_NoCaching))
00089       return new NoCaching();
00090     if (behaviorString.equals(DatabasesXmlTags.ELT_EagerCaching))
00091     {
00092       // Timeout is in seconds: *1000      
00093       // 0, is no timeout, and 0x1000=0 !
00094       long timeout = 1000 * Long.parseLong((String) options
00095           .get(DatabasesXmlTags.ATT_timeout));
00096       return new EagerCaching(timeout);
00097     }
00098     if (behaviorString.equals(DatabasesXmlTags.ELT_RelaxedCaching))
00099     {
00100       // Timeout is in seconds: *1000
00101       long timeout = 1000 * Long.parseLong((String) options
00102           .get(DatabasesXmlTags.ATT_timeout));
00103       boolean keepIfNotDirty = new Boolean((String) options
00104           .get(DatabasesXmlTags.ATT_keepIfNotDirty)).booleanValue();
00105       return new RelaxedCaching(keepIfNotDirty, timeout);
00106     }
00107     else
00108       return null;
00109   }
00110 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1