1 24 25 package org.objectweb.cjdbc.controller.cache.result; 26 27 import java.util.Hashtable ; 28 29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 30 import org.objectweb.cjdbc.controller.cache.result.rules.EagerCaching; 31 import org.objectweb.cjdbc.controller.cache.result.rules.NoCaching; 32 import org.objectweb.cjdbc.controller.cache.result.rules.RelaxedCaching; 33 34 40 public class ResultCacheFactory 41 { 42 52 public static AbstractResultCache getCacheInstance(int granularityValue, 53 int maxEntries, int pendingTimeout) throws InstantiationException 54 { 55 AbstractResultCache currentRequestCache = null; 56 switch (granularityValue) 57 { 58 case CachingGranularities.TABLE : 59 currentRequestCache = new ResultCacheTable(maxEntries, pendingTimeout); 60 break; 61 case CachingGranularities.DATABASE : 62 currentRequestCache = new ResultCacheDatabase(maxEntries, 63 pendingTimeout); 64 break; 65 case CachingGranularities.COLUMN : 66 currentRequestCache = new ResultCacheColumn(maxEntries, pendingTimeout); 67 break; 68 case CachingGranularities.COLUMN_UNIQUE : 69 currentRequestCache = new ResultCacheColumnUnique(maxEntries, 70 pendingTimeout); 71 break; 72 default : 73 throw new InstantiationException ("Invalid Granularity Value"); 74 } 75 return currentRequestCache; 76 } 77 78 85 public static CacheBehavior getCacheBehaviorInstance(String behaviorString, 86 Hashtable options) 87 { 88 if (behaviorString.equalsIgnoreCase(DatabasesXmlTags.ELT_NoCaching)) 89 return new NoCaching(); 90 if (behaviorString.equals(DatabasesXmlTags.ELT_EagerCaching)) 91 { 92 long timeout = 1000 * Long.parseLong((String ) options 95 .get(DatabasesXmlTags.ATT_timeout)); 96 return new EagerCaching(timeout); 97 } 98 if (behaviorString.equals(DatabasesXmlTags.ELT_RelaxedCaching)) 99 { 100 long timeout = 1000 * Long.parseLong((String ) options 102 .get(DatabasesXmlTags.ATT_timeout)); 103 boolean keepIfNotDirty = new Boolean ((String ) options 104 .get(DatabasesXmlTags.ATT_keepIfNotDirty)).booleanValue(); 105 return new RelaxedCaching(keepIfNotDirty, timeout); 106 } 107 else 108 return null; 109 } 110 } | Popular Tags |