1 25 package org.ofbiz.entity.cache; 26 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.ofbiz.entity.condition.EntityCondition; 32 import org.ofbiz.entity.util.EntityUtil; 33 34 public class EntityListCache extends AbstractEntityConditionCache { 35 36 public static final String module = EntityListCache.class.getName(); 37 38 public EntityListCache(String delegatorName) { 39 super(delegatorName, "entity-list"); 40 } 41 42 public List get(String entityName, EntityCondition condition) { 43 return this.get(entityName, condition, null); 44 } 45 46 public List get(String entityName, EntityCondition condition, List orderBy) { 47 Map conditionCache = getConditionCache(entityName, condition); 48 if (conditionCache == null) return null; 49 Object orderByKey = getOrderByKey(orderBy); 50 List valueList = (List ) conditionCache.get(orderByKey); 51 if (valueList == null) { 52 Iterator it = conditionCache.values().iterator(); 54 if (it.hasNext()) valueList = (List ) it.next(); 55 56 synchronized (conditionCache) { 57 if (valueList != null) { 58 valueList = EntityUtil.orderBy(valueList, orderBy); 59 conditionCache.put(orderByKey, valueList); 60 } 61 } 62 } 63 return valueList; 64 } 65 66 public void put(String entityName, EntityCondition condition, List entities) { 67 this.put(entityName, condition, null, entities); 68 } 69 70 public List put(String entityName, EntityCondition condition, List orderBy, List entities) { 71 return (List ) super.put(entityName, getFrozenConditionKey(condition), getOrderByKey(orderBy), entities); 72 } 73 74 public List remove(String entityName, EntityCondition condition, List orderBy) { 75 return (List ) super.remove(entityName, condition, getOrderByKey(orderBy)); 76 } 77 78 public static final Object getOrderByKey(List orderBy) { 79 return orderBy != null ? (Object ) orderBy : "{null}"; 80 } 81 } 82 | Popular Tags |