svn commit: r585814 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache: AbstractCache.java AbstractEntityConditionCache.java Cache.java EntityCache.java EntityListCache.java EntityObjectCache.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r585814 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache: AbstractCache.java AbstractEntityConditionCache.java Cache.java EntityCache.java EntityListCache.java EntityObjectCache.java

doogie-3
Author: doogie
Date: Wed Oct 17 20:13:00 2007
New Revision: 585814

URL: http://svn.apache.org/viewvc?rev=585814&view=rev
Log:
Java 1.5 markup for entity cache.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityObjectCache.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java Wed Oct 17 20:13:00 2007
@@ -21,7 +21,7 @@
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.entity.GenericDelegator;
 
-public abstract class AbstractCache {
+public abstract class AbstractCache<K, V> {
 
     protected String delegatorName, id;
 
@@ -69,16 +69,16 @@
         return names;
     }
 
-    protected UtilCache getCache(String entityName) {
+    protected UtilCache<K, V> getCache(String entityName) {
         return UtilCache.findCache(getCacheName(entityName));
     }
 
-    protected UtilCache getOrCreateCache(String entityName) {
+    protected UtilCache<K, V> getOrCreateCache(String entityName) {
         synchronized (UtilCache.utilCacheTable) {
             String name = getCacheName(entityName);
-            UtilCache cache = UtilCache.findCache(name);
+            UtilCache<K, V> cache = UtilCache.findCache(name);
             if (cache == null) {
-                cache = new UtilCache(name, 0, 0, true);
+                cache = new UtilCache<K, V>(name, 0, 0, true);
                 String[] names = getCacheNames(entityName);
                 cache.setPropertiesParams(names);
             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java Wed Oct 17 20:13:00 2007
@@ -32,8 +32,9 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelViewEntity;
 
-public abstract class AbstractEntityConditionCache extends AbstractCache {
+public abstract class AbstractEntityConditionCache<K, V> extends AbstractCache<EntityCondition, Map<K, V>> {
 
     public static final String module = AbstractEntityConditionCache.class.getName();
 
@@ -41,34 +42,34 @@
         super(delegatorName, id);
     }
 
-    protected Object get(String entityName, EntityCondition condition, Object key) {
-        Map conditionCache = getConditionCache(entityName, condition);
+    protected V get(String entityName, EntityCondition condition, K key) {
+        Map<K, V> conditionCache = getConditionCache(entityName, condition);
         if (conditionCache == null) return null;
         // the following line was synchronized, but for pretty good safety and better performance, only syncrhnizing the put; synchronized (conditionCache) {
         return conditionCache.get(key);
     }
 
-    protected Object put(String entityName, EntityCondition condition, Object key, Object value) {
+    protected V put(String entityName, EntityCondition condition, K key, V value) {
         ModelEntity entity = this.getDelegator().getModelEntity(entityName);
         if (entity.getNeverCache()) {
             Debug.logWarning("Tried to put a value of the " + entityName + " entity in the cache but this entity has never-cache set to true, not caching.", module);
             return null;
         }
         
-        Map conditionCache = getOrCreateConditionCache(entityName, condition);
+        Map<K, V> conditionCache = getOrCreateConditionCache(entityName, condition);
         synchronized (conditionCache) {
             return conditionCache.put(key, value);
         }
     }
 
     public void remove(String entityName, EntityCondition condition) {
-        UtilCache cache = getCache(entityName);
+        UtilCache<EntityCondition, Map<K, V>> cache = getCache(entityName);
         if (cache == null) return;
         cache.remove(condition);
     }
 
-    protected Object remove(String entityName, EntityCondition condition, Object key) {
-        Map conditionCache = getConditionCache(entityName, condition);
+    protected V remove(String entityName, EntityCondition condition, K key) {
+        Map<K, V> conditionCache = getConditionCache(entityName, condition);
         if (conditionCache == null) return null;
         synchronized (conditionCache) {
             return conditionCache.remove(key);
@@ -91,16 +92,16 @@
         return frozenCondition;
     }
 
-    protected Map getConditionCache(String entityName, EntityCondition condition) {
-        UtilCache cache = getCache(entityName);
+    protected Map<K, V> getConditionCache(String entityName, EntityCondition condition) {
+        UtilCache<EntityCondition, Map<K, V>> cache = getCache(entityName);
         if (cache == null) return null;
-        return (Map) cache.get(getConditionKey(condition));
+        return cache.get(getConditionKey(condition));
     }
 
-    protected Map getOrCreateConditionCache(String entityName, EntityCondition condition) {
-        UtilCache utilCache = getOrCreateCache(entityName);
-        Object conditionKey = getConditionKey(condition);
-        Map conditionCache = (Map) utilCache.get(conditionKey);
+    protected Map<K, V> getOrCreateConditionCache(String entityName, EntityCondition condition) {
+        UtilCache<EntityCondition, Map<K, V>> utilCache = getOrCreateCache(entityName);
+        EntityCondition conditionKey = getConditionKey(condition);
+        Map<K, V> conditionCache = utilCache.get(conditionKey);
         if (conditionCache == null) {
             conditionCache = FastMap.newInstance();
             utilCache.put(conditionKey, conditionCache);
@@ -146,7 +147,7 @@
         storeHook(true, oldPK, newEntity);
     }
 
-    protected List convert(boolean isPK, String targetEntityName, GenericEntity entity) {
+    protected List<? extends Map<String, Object>> convert(boolean isPK, String targetEntityName, GenericEntity entity) {
         if (isNull(entity)) return null;
         if (isPK) {
             return entity.getModelEntity().convertToViewValues(targetEntityName, (GenericPK) entity);
@@ -163,16 +164,16 @@
             //Debug.logInfo("In storeHook calling sub-storeHook for entity name [" + entityName + "] for the oldEntity: " + oldEntity, module);
         }
         storeHook(entityName, isPK, UtilMisc.toList(oldEntity), UtilMisc.toList(newEntity));
-        Iterator it = model.getViewConvertorsIterator();
+        Iterator<Map.Entry<String, ModelViewEntity>> it = model.getViewConvertorsIterator();
         while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
-            String targetEntityName = (String) entry.getKey();
+            Map.Entry<String, ModelViewEntity> entry = it.next();
+            String targetEntityName = entry.getKey();
             storeHook(targetEntityName, isPK, convert(isPK, targetEntityName, oldEntity), convert(false, targetEntityName, newEntity));
         }
     }
 
-    protected void storeHook(String entityName, boolean isPK, List oldValues, List newValues) {
-        UtilCache entityCache = UtilCache.findCache(getCacheName(entityName));
+    protected <T1 extends Map<String, Object>, T2 extends Map<String, Object>> void storeHook(String entityName, boolean isPK, List<T1> oldValues, List<T2> newValues) {
+        UtilCache<EntityCondition, Map<K, V>> entityCache = UtilCache.findCache(getCacheName(entityName));
         // for info about cache clearing
         if (newValues == null || newValues.size() == 0 || newValues.get(0) == null) {
             //Debug.logInfo("In storeHook (cache clear) for entity name [" + entityName + "], got entity cache with name: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
@@ -180,31 +181,29 @@
         if (entityCache == null) {
             return;
         }
-        Iterator cacheKeyIter = entityCache.getCacheLineKeys().iterator();
-        while (cacheKeyIter.hasNext()) {
-            EntityCondition condition = (EntityCondition) cacheKeyIter.next();
+        for (EntityCondition condition: entityCache.getCacheLineKeys()) {
             //Debug.logInfo("In storeHook entityName [" + entityName + "] checking against condition: " + condition, module);
             boolean shouldRemove = false;
             if (condition == null) {
                 shouldRemove = true;
             } else if (oldValues == null) {
-                Iterator newValueIter = newValues.iterator();
+                Iterator<T2> newValueIter = newValues.iterator();
                 while (newValueIter.hasNext() && !shouldRemove) {
-                    Map newValue = (Map) newValueIter.next();
+                    T2 newValue = newValueIter.next();
                     shouldRemove |= condition.mapMatches(getDelegator(), newValue);
                 }
             } else {
                 boolean oldMatched = false;
-                Iterator oldValueIter = oldValues.iterator();
+                Iterator<T1> oldValueIter = oldValues.iterator();
                 while (oldValueIter.hasNext() && !shouldRemove) {
-                    Map oldValue = (Map) oldValueIter.next();
+                    T1 oldValue = oldValueIter.next();
                     if (condition.mapMatches(getDelegator(), oldValue)) {
                         oldMatched = true;
                         //Debug.logInfo("In storeHook, oldMatched for entityName [" + entityName + "]; shouldRemove is false", module);
                         if (newValues != null) {
-                            Iterator newValueIter = newValues.iterator();
+                            Iterator<T2> newValueIter = newValues.iterator();
                             while (newValueIter.hasNext() && !shouldRemove) {
-                                Map newValue = (Map) newValueIter.next();
+                                T2 newValue = newValueIter.next();
                                 shouldRemove |= isNull(newValue) || condition.mapMatches(getDelegator(), newValue);
                                 //Debug.logInfo("In storeHook, for entityName [" + entityName + "] shouldRemove is now " + shouldRemove, module);
                             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/Cache.java Wed Oct 17 20:13:00 2007
@@ -22,6 +22,7 @@
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.entity.GenericEntity;
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.condition.EntityCondition;
 
@@ -53,11 +54,11 @@
         entityListCache.remove(entityName);
     }
 
-    public GenericEntity get(GenericPK pk) {
+    public GenericValue get(GenericPK pk) {
         return entityCache.get(pk);
     }
 
-    public List get(String entityName, EntityCondition condition, List orderBy) {
+    public List<GenericValue> get(String entityName, EntityCondition condition, List<String> orderBy) {
         return entityListCache.get(entityName, condition, orderBy);
     }
 
@@ -65,7 +66,7 @@
         return entityObjectCache.get(entityName, condition, name);
     }
 
-    public List put(String entityName, EntityCondition condition, List orderBy, List entities) {
+    public List<GenericValue> put(String entityName, EntityCondition condition, List<String> orderBy, List<GenericValue> entities) {
         return entityListCache.put(entityName, condition, orderBy, entities);
     }
 
@@ -73,8 +74,8 @@
         return entityObjectCache.put(entityName, condition, name, value);
     }
 
-    public GenericEntity put(GenericEntity entity) {
-        GenericEntity oldEntity = entityCache.put(entity.getPrimaryKey(), entity);
+    public GenericValue put(GenericValue entity) {
+        GenericValue oldEntity = entityCache.put(entity.getPrimaryKey(), entity);
         if (entity.getModelEntity().getAutoClearCache()) {
             entityListCache.storeHook(entity);
             entityObjectCache.storeHook(entity);
@@ -82,8 +83,8 @@
         return oldEntity;
     }
     
-    public GenericEntity put(GenericPK pk, GenericEntity entity) {
-        GenericEntity oldEntity = entityCache.put(pk, entity);
+    public GenericValue put(GenericPK pk, GenericValue entity) {
+        GenericValue oldEntity = entityCache.put(pk, entity);
         if (pk.getModelEntity().getAutoClearCache()) {
             entityListCache.storeHook(pk, entity);
             entityObjectCache.storeHook(pk, entity);
@@ -91,7 +92,7 @@
         return oldEntity;
     }
 
-    public List remove(String entityName, EntityCondition condition, List orderBy) {
+    public List<GenericValue> remove(String entityName, EntityCondition condition, List<String> orderBy) {
         entityCache.remove(entityName, condition);
         entityObjectCache.remove(entityName, condition);
         return entityListCache.remove(entityName, condition, orderBy);
@@ -107,17 +108,17 @@
         return entityObjectCache.remove(entityName, condition, name);
     }
 
-    public GenericEntity remove(GenericEntity entity) {
+    public GenericValue remove(GenericEntity entity) {
         if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericEntity: " + entity, module);
-        GenericEntity oldEntity = entityCache.remove(entity.getPrimaryKey());
+        GenericValue oldEntity = entityCache.remove(entity.getPrimaryKey());
         entityListCache.storeHook(entity, null);
         entityObjectCache.storeHook(entity, null);
         return oldEntity;
     }
 
-    public GenericEntity remove(GenericPK pk) {
+    public GenericValue remove(GenericPK pk) {
         if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericPK: " + pk, module);
-        GenericEntity oldEntity = entityCache.remove(pk);
+        GenericValue oldEntity = entityCache.remove(pk);
         entityListCache.storeHook(pk, null);
         entityObjectCache.storeHook(pk, null);
         return oldEntity;

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java Wed Oct 17 20:13:00 2007
@@ -23,66 +23,66 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.base.util.cache.CacheLine;
-import org.ofbiz.entity.GenericEntity;
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.condition.EntityCondition;
 
-public class EntityCache extends AbstractCache {
+public class EntityCache extends AbstractCache<GenericPK, GenericValue> {
     public static final String module = EntityCache.class.getName();
 
     public EntityCache(String delegatorName) {
         super(delegatorName, "entity");
     }
 
-    public GenericEntity get(GenericPK pk) {
-        UtilCache entityCache = getCache(pk.getEntityName());
+    public GenericValue get(GenericPK pk) {
+        UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
         if (entityCache == null) return null;
-        return (GenericEntity) entityCache.get(pk);
+        return entityCache.get(pk);
     }
 
-    public GenericEntity put(GenericEntity entity) {
+    public GenericValue put(GenericValue entity) {
         if (entity == null) return null;
         return put(entity.getPrimaryKey(), entity);
     }
 
-    public GenericEntity put(GenericPK pk, GenericEntity entity) {
+    public GenericValue put(GenericPK pk, GenericValue entity) {
         if (pk.getModelEntity().getNeverCache()) {
             Debug.logWarning("Tried to put a value of the " + pk.getEntityName() + " entity in the BY PRIMARY KEY cache but this entity has never-cache set to true, not caching.", module);
             return null;
         }
 
         if (entity == null) {
-            entity = GenericEntity.NULL_ENTITY;
+            entity = GenericValue.NULL_VALUE;
         } else {
             // before going into the cache, make this value immutable
             entity.setImmutable();
         }
-        UtilCache entityCache = getOrCreateCache(pk.getEntityName());
-        return (GenericEntity)entityCache.put(pk, entity);
+        UtilCache<GenericPK, GenericValue> entityCache = getOrCreateCache(pk.getEntityName());
+        return entityCache.put(pk, entity);
     }
 
     public void remove(String entityName, EntityCondition condition) {
-        UtilCache entityCache = getCache(entityName);
+        UtilCache<GenericPK, GenericValue> entityCache = getCache(entityName);
         if (entityCache == null) return;
-        Iterator it = entityCache.getCacheLineValues().iterator();
+        Iterator<? extends CacheLine<GenericValue>> it = entityCache.getCacheLineValues().iterator();
         while (it.hasNext()) {
-            CacheLine line = (CacheLine) it.next();
+            CacheLine<GenericValue> line = it.next();
             if (line.hasExpired()) continue;
-            GenericEntity entity = (GenericEntity) line.getValue();
+            GenericValue entity = line.getValue();
             if (entity == null) continue;
             if (condition.entityMatches(entity)) it.remove();
         }
     }
 
-    public GenericEntity remove(GenericEntity entity) {
+    public GenericValue remove(GenericValue entity) {
         return remove(entity.getPrimaryKey());
     }
 
-    public GenericEntity remove(GenericPK pk) {
-        UtilCache entityCache = getCache(pk.getEntityName());
+    public GenericValue remove(GenericPK pk) {
+        UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
         if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], will remove from this cache: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
         if (entityCache == null) return null;
-        GenericEntity retVal = (GenericEntity) entityCache.remove(pk);
+        GenericValue retVal = entityCache.remove(pk);
         if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
         return retVal;
     }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityListCache.java Wed Oct 17 20:13:00 2007
@@ -22,10 +22,11 @@
 import java.util.List;
 import java.util.Map;
 
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.util.EntityUtil;
 
-public class EntityListCache extends AbstractEntityConditionCache {
+public class EntityListCache extends AbstractEntityConditionCache<Object, List<GenericValue>> {
 
     public static final String module = EntityListCache.class.getName();
 
@@ -33,19 +34,19 @@
         super(delegatorName, "entity-list");
     }
 
-    public List get(String entityName, EntityCondition condition) {
+    public List<GenericValue> get(String entityName, EntityCondition condition) {
         return this.get(entityName, condition, null);
     }
 
-    public List get(String entityName, EntityCondition condition, List orderBy) {
-        Map conditionCache = getConditionCache(entityName, condition);
+    public List<GenericValue> get(String entityName, EntityCondition condition, List<String> orderBy) {
+        Map<Object, List<GenericValue>> conditionCache = getConditionCache(entityName, condition);
         if (conditionCache == null) return null;
         Object orderByKey = getOrderByKey(orderBy);
-        List valueList = (List) conditionCache.get(orderByKey);
+        List<GenericValue> valueList = conditionCache.get(orderByKey);
         if (valueList == null) {
             // the valueList was not found for the given ordering, so grab the first one and order it in memory
-            Iterator it = conditionCache.values().iterator();
-            if (it.hasNext()) valueList = (List) it.next();
+            Iterator<List<GenericValue>> it = conditionCache.values().iterator();
+            if (it.hasNext()) valueList = it.next();
             
             synchronized (conditionCache) {
                 if (valueList != null) {
@@ -57,19 +58,19 @@
         return valueList;
     }
 
-    public void put(String entityName, EntityCondition condition, List entities) {
+    public void put(String entityName, EntityCondition condition, List<GenericValue> entities) {
         this.put(entityName, condition, null, entities);
     }
 
-    public List put(String entityName, EntityCondition condition, List orderBy, List entities) {
-        return (List) super.put(entityName, getFrozenConditionKey(condition), getOrderByKey(orderBy), entities);
+    public List<GenericValue> put(String entityName, EntityCondition condition, List<String> orderBy, List<GenericValue> entities) {
+        return super.put(entityName, getFrozenConditionKey(condition), getOrderByKey(orderBy), entities);
     }
 
-    public List remove(String entityName, EntityCondition condition, List orderBy) {
-        return (List) super.remove(entityName, condition, getOrderByKey(orderBy));
+    public List<GenericValue> remove(String entityName, EntityCondition condition, List<String> orderBy) {
+        return super.remove(entityName, condition, getOrderByKey(orderBy));
     }
 
-    public static final Object getOrderByKey(List orderBy) {
+    public static final Object getOrderByKey(List<String> orderBy) {
         return orderBy != null ? (Object) orderBy : "{null}";
     }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityObjectCache.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityObjectCache.java?rev=585814&r1=585813&r2=585814&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityObjectCache.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/EntityObjectCache.java Wed Oct 17 20:13:00 2007
@@ -21,7 +21,7 @@
 
 import org.ofbiz.entity.condition.EntityCondition;
 
-public class EntityObjectCache extends AbstractEntityConditionCache {
+public class EntityObjectCache extends AbstractEntityConditionCache<String, Object> {
 
     public static final String module = EntityObjectCache.class.getName();