1 package org.apache.ojb.broker.cache; 2 3 17 18 import org.apache.ojb.broker.Identity; 19 import org.apache.ojb.broker.PersistenceBroker; 20 import org.apache.ojb.broker.util.logging.LoggerFactory; 21 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.Properties ; 26 27 59 60 public class ObjectCacheJCSPerClassImpl extends AbstractMetaCache 61 { 62 private static Map cachesByClass = new HashMap (); 63 64 67 public ObjectCacheJCSPerClassImpl(PersistenceBroker broker, Properties prop) 68 { 69 } 70 71 public ObjectCache getCache(Identity oid, Object obj, int methodCall) 72 { 73 if (oid.getObjectsRealClass() == null) 74 { 75 LoggerFactory.getDefaultLogger().info("[" + this.getClass() 76 + "] Can't get JCS cache, real class was 'null' for Identity: " + oid); 77 return null; 78 } 79 return getCachePerClass(oid.getObjectsRealClass(), methodCall); 80 } 81 82 85 public void clear() 86 { 87 Iterator it = cachesByClass.values().iterator(); 88 while (it.hasNext()) 89 { 90 ObjectCache cache = (ObjectCache) it.next(); 91 if (cache != null) 92 { 93 cache.clear(); 94 } 95 else 96 { 97 it.remove(); 98 } 99 } 100 } 101 102 108 private ObjectCache getCachePerClass(Class objectClass, int methodCall) 109 { 110 ObjectCache cache = (ObjectCache) cachesByClass.get(objectClass.getName()); 111 if (cache == null && methodCall == AbstractMetaCache.METHOD_CACHE) 112 { 113 117 cache = new ObjectCacheJCSImpl(objectClass.getName()); 118 cachesByClass.put(objectClass.getName(), cache); 119 } 120 return cache; 121 } 122 } 123 | Popular Tags |