1 25 package org.ofbiz.entity.cache; 26 27 import java.util.List ; 28 29 import org.ofbiz.base.util.Debug; 30 import org.ofbiz.entity.GenericEntity; 31 import org.ofbiz.entity.GenericPK; 32 import org.ofbiz.entity.condition.EntityCondition; 33 34 public class Cache { 35 36 public static final String module = Cache.class.getName(); 37 38 protected EntityCache entityCache; 39 protected EntityListCache entityListCache; 40 protected EntityObjectCache entityObjectCache; 41 42 protected String delegatorName; 43 44 public Cache(String delegatorName) { 45 this.delegatorName = delegatorName; 46 entityCache = new EntityCache(delegatorName); 47 entityObjectCache = new EntityObjectCache(delegatorName); 48 entityListCache = new EntityListCache(delegatorName); 49 } 50 51 public void clear() { 52 entityCache.clear(); 53 entityListCache.clear(); 54 entityObjectCache.clear(); 55 } 56 57 public void remove(String entityName) { 58 entityCache.remove(entityName); 59 entityListCache.remove(entityName); 60 } 61 62 public GenericEntity get(GenericPK pk) { 63 return entityCache.get(pk); 64 } 65 66 public List get(String entityName, EntityCondition condition, List orderBy) { 67 return entityListCache.get(entityName, condition, orderBy); 68 } 69 70 public Object get(String entityName, EntityCondition condition, String name) { 71 return entityObjectCache.get(entityName, condition, name); 72 } 73 74 public List put(String entityName, EntityCondition condition, List orderBy, List entities) { 75 return entityListCache.put(entityName, condition, orderBy, entities); 76 } 77 78 public Object put(String entityName, EntityCondition condition, String name, Object value) { 79 return entityObjectCache.put(entityName, condition, name, value); 80 } 81 82 public GenericEntity put(GenericEntity entity) { 83 GenericEntity oldEntity = entityCache.put(entity.getPrimaryKey(), entity); 84 if (entity.getModelEntity().getAutoClearCache()) { 85 entityListCache.storeHook(entity); 86 entityObjectCache.storeHook(entity); 87 } 88 return oldEntity; 89 } 90 91 public GenericEntity put(GenericPK pk, GenericEntity entity) { 92 GenericEntity oldEntity = entityCache.put(pk, entity); 93 if (pk.getModelEntity().getAutoClearCache()) { 94 entityListCache.storeHook(pk, entity); 95 entityObjectCache.storeHook(pk, entity); 96 } 97 return oldEntity; 98 } 99 100 public List remove(String entityName, EntityCondition condition, List orderBy) { 101 entityCache.remove(entityName, condition); 102 entityObjectCache.remove(entityName, condition); 103 return entityListCache.remove(entityName, condition, orderBy); 104 } 105 106 public void remove(String entityName, EntityCondition condition) { 107 entityCache.remove(entityName, condition); 108 entityListCache.remove(entityName, condition); 109 entityObjectCache.remove(entityName, condition); 110 } 111 112 public Object remove(String entityName, EntityCondition condition, String name) { 113 return entityObjectCache.remove(entityName, condition, name); 114 } 115 116 public GenericEntity remove(GenericEntity entity) { 117 if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericEntity: " + entity, module); 118 GenericEntity oldEntity = entityCache.remove(entity.getPrimaryKey()); 119 entityListCache.storeHook(entity, null); 120 entityObjectCache.storeHook(entity, null); 121 return oldEntity; 122 } 123 124 public GenericEntity remove(GenericPK pk) { 125 if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericPK: " + pk, module); 126 GenericEntity oldEntity = entityCache.remove(pk); 127 entityListCache.storeHook(pk, null); 128 entityObjectCache.storeHook(pk, null); 129 return oldEntity; 130 } 131 } 132 | Popular Tags |