CdmTransientEntityCacher : adding cache to default cache manager
authorCherian Mathew <c.mathew@bgbm.org>
Wed, 20 May 2015 12:00:29 +0000 (12:00 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Wed, 20 May 2015 12:00:29 +0000 (12:00 +0000)
EntityCacherDebugResult : corrections
cdmlib-remote-webapp.war : new version

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmTransientEntityCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/EntityCacherDebugResult.java
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war

index 4c80ad7942e35d9fb135c1047f9b39daa485335d..52f18ca40f9e47d7372224998b33ffe5ca6258bf 100644 (file)
@@ -63,6 +63,8 @@ public class CdmTransientEntityCacher implements ICdmCacher {
 
         cache = new Cache(getEntityCacheConfiguration(cacheId));
 
+        CdmRemoteCacheManager.getInstance().getDefaultCacheManager().addCache(cache);
+
         this.cdmEntitySessionManager = cdmEntitySessionManager;
 
         cacheLoader = new CacheLoader(this);
index 7c1ba5c0cc62a19ed04a09b23c288b0e219379d3..56e099729049c301a3ad29e2f1d6e31f2947f630 100644 (file)
@@ -13,11 +13,9 @@ import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
@@ -167,7 +165,11 @@ public class EntityCacherDebugResult {
 
                 sb.append(System.getProperty("line.separator"));
 
-                sb.append(" - "  + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
+                String fieldName = "";
+                if(cei.getField() != null) {
+                    fieldName = cei.getField().getName();
+                }
+                sb.append(" - "  + fieldName + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
 
                 if(cbParent instanceof CdmBase) {
                     sb.append(" of entity " + ((CdmBase)cbParent).getUserFriendlyTypeName());
@@ -201,7 +203,7 @@ public class EntityCacherDebugResult {
             return;
         }
         logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
-        Set<CdmEntityInfo> alreadyVisitedEntities = new HashSet<CdmEntityInfo>();
+        List<CdmEntityInfo> alreadyVisitedEntities = new ArrayList<CdmEntityInfo>();
         CdmEntityInfo cei = new CdmEntityInfo(cdmEntity);
         debugRecursive(cdmEntity, alreadyVisitedEntities, cei);
         rootElements.add(cei);
@@ -210,7 +212,7 @@ public class EntityCacherDebugResult {
     }
 
     private <T extends Object> void debugRecursive(T obj,
-            Set<CdmEntityInfo> alreadyVisitedEntities,
+            List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
         if(obj == null) {
             return;
@@ -229,7 +231,7 @@ public class EntityCacherDebugResult {
     }
 
     private <T extends Object> void debug(Map<T,T> map,
-            Set<CdmEntityInfo> alreadyVisitedEntities,
+            List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
         if(map == null || map.isEmpty()) {
             return;
@@ -249,7 +251,7 @@ public class EntityCacherDebugResult {
     }
 
     private <T extends Object> void debug(Collection<T> collection,
-            Set<CdmEntityInfo> alreadyVisitedEntities,
+            List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
         int length = collection.size();
         Object[] result = new Object[length];
@@ -266,9 +268,21 @@ public class EntityCacherDebugResult {
     }
 
     private void debugRecursive(CdmBase cdmEntity,
-            Set<CdmEntityInfo> alreadyVisitedEntities,
+            List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
 
+        CdmBase cachedCdmEntityInSubGraph = null;
+
+        if(cei.getObject() instanceof CdmBase) {
+           CdmBase cb =  (CdmBase)cei.getObject();
+           cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
+           if(cachedCdmEntityInSubGraph != cb) {
+               // found a cdm entity which is not in cache - need to record this
+               //logger.info("  - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
+               addEntityNotInCache(cei);
+           }
+        }
+
 
         // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
         // since there could be new or deleted objects in the cdmEntity sub-graph
@@ -283,7 +297,7 @@ public class EntityCacherDebugResult {
                 // retrieve the actual object corresponding to the field.
                 // this object will be either a CdmBase or a Collection / Map
                 // with CdmBase as the generic type
-
+                String f = field;
                 CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
                 if(!childCei.isProxy()) {
                     Object object = childCei.getObject();
@@ -308,7 +322,7 @@ public class EntityCacherDebugResult {
 
     private CdmEntityInfo getDebugCdmBaseTypeFieldValue(CdmBase cdmEntity,
             String fieldName,
-            Set<CdmEntityInfo> alreadyVisitedEntities,
+            List<CdmEntityInfo> alreadyVisitedEntities,
             CdmEntityInfo cei) {
 
         CdmEntityInfo childCei = null;
@@ -367,17 +381,6 @@ public class EntityCacherDebugResult {
                             addDuplicateEntity(childCei, dupCei);
                         }
 
-                        CdmBase cachedCdmEntityInSubGraph = cacher.getFromCache(cdmEntityInSubGraph);
-                        // the only exception to updating the field to the latest value
-                        // is the case where the field has been already initialised, cached and
-                        // is not the same as the one in the cache, in which case we set the value
-                        // of the field to the one found in the cache
-                        if(cachedCdmEntityInSubGraph == null) {
-                            // found a cdm entity which is not in cache - need to record this
-                            //logger.info("  - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
-                            addEntityNotInCache(childCei);
-                        }
-
                     } else if(o instanceof Map) {
                         debugRecursive((Map)o, alreadyVisitedEntities, childCei);
                     } else if(o instanceof Collection) {
@@ -401,7 +404,7 @@ public class EntityCacherDebugResult {
     }
 
 
-    private CdmEntityInfo getDuplicate(Set<CdmEntityInfo> alreadyVisitedEntities, Object objectToCompare) {
+    private CdmEntityInfo getDuplicate(List<CdmEntityInfo> alreadyVisitedEntities, Object objectToCompare) {
         if(objectToCompare != null ) {
             for(CdmEntityInfo cei: alreadyVisitedEntities) {
                 if(objectToCompare.equals(cei.getObject()) && objectToCompare != cei.getObject()) {
@@ -412,15 +415,18 @@ public class EntityCacherDebugResult {
         return null;
     }
 
-    private boolean containsIdenticalCdmEntity(Set<CdmEntityInfo> ceiSet, Object objectToCompare) {
+    private boolean containsIdenticalCdmEntity(List<CdmEntityInfo> ceiSet, Object objectToCompare) {
+        boolean foundIdentical = false;
         if(objectToCompare != null) {
             for(CdmEntityInfo cei : ceiSet) {
                 if(cei.getObject() == objectToCompare) {
-                    return true;
+                    foundIdentical = true;
+                } else if(objectToCompare.equals(cei.getObject())) {
+                    return false;
                 }
             }
         }
-        return false;
+        return foundIdentical;
     }
 
     public class CdmEntityInfo {
index 05b64a1ebc52476f1ac88356e557809d59b718d3..aba25ee56c4d5587261ad02921730c194a1e90e4 100644 (file)
Binary files a/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war and b/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war differ