CacheLoader : added strict check in recurive loop for same (not only equal) objects
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 22 May 2015 17:10:55 +0000 (19:10 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 22 May 2015 17:10:55 +0000 (19:10 +0200)
EntityCacherDebugResult : removed deproxy of objects
ProxyUtils : refactoring
httpInvokerServiceClients.xml : corrected validation service class name
hibernate.cfg.xml, cdmTest.*.db : updated to latest

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CacheLoader.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/EntityCacherDebugResult.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/ProxyUtils.java
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicationContext.xml
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/log4j.properties
eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.h2.db
eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.trace.db
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNameEditorTest.java

index 57e7da8f2a460904ffc9c0ce4378ee5889550cea..ce25e48659255ebc14d5bb9d751737ec5f601aea 100644 (file)
 package eu.etaxonomy.taxeditor.remoting.cache;
 
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.Collection;
-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;
@@ -77,7 +76,7 @@ public class CacheLoader {
     }
 
     @SuppressWarnings("unchecked")
-    private <T extends Object> T loadRecursive(T obj, Set<Object> alreadyVisitedEntities, boolean update) {
+    private <T extends Object> T loadRecursive(T obj, List<Object> alreadyVisitedEntities, boolean update) {
         if(obj == null) {
             return null;
         }
@@ -100,7 +99,7 @@ public class CacheLoader {
 
         if(isRecursiveEnabled && recursive) {
             logger.info("---- starting recursive load for cdm entity map");
-            Set<Object> alreadyVisitedEntities = new HashSet<Object>();
+            List<Object> alreadyVisitedEntities = new ArrayList<Object>();
             Map<T,T> cachedMap = load(map, alreadyVisitedEntities, update);
             alreadyVisitedEntities.clear();
             logger.info("---- ending recursive load for cdm entity map \n");
@@ -111,7 +110,7 @@ public class CacheLoader {
     }
 
 
-    private <T extends Object> Map<T,T> load(Map<T,T> map, Set<Object> alreadyVisitedEntities, boolean update){
+    private <T extends Object> Map<T,T> load(Map<T,T> map, List<Object> alreadyVisitedEntities, boolean update){
         //map = (Map<T,T>)deproxy(map);
 
         if(map == null || map.isEmpty()) {
@@ -152,7 +151,7 @@ public class CacheLoader {
         Collection<T> loadedCollection;
         if(isRecursiveEnabled && recursive) {
             logger.info("---- starting recursive load for cdm entity collection");
-            Set<Object> alreadyVisitedEntities = new HashSet<Object>();
+            List<Object> alreadyVisitedEntities = new ArrayList<Object>();
             Collection<T> cachedCollection = load(collection, alreadyVisitedEntities, update);
             alreadyVisitedEntities.clear();
             logger.info("---- ending recursive load for cdm entity collection \n");
@@ -164,7 +163,7 @@ public class CacheLoader {
     }
 
     @SuppressWarnings("unchecked")
-    private <T extends Object> Collection<T> load(Collection<T> collection, Set<Object> alreadyVisitedEntities, boolean update) {
+    private <T extends Object> Collection<T> load(Collection<T> collection, List<Object> alreadyVisitedEntities, boolean update) {
 
 
 
@@ -226,7 +225,7 @@ public class CacheLoader {
         CdmBase loadedCdmBase;
         if(isRecursiveEnabled && recursive) {
             logger.info("---- starting recursive load for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
-            Set<Object> alreadyVisitedEntities = new HashSet<Object>();
+            List<Object> alreadyVisitedEntities = new ArrayList<Object>();
             CdmBase cb =  loadRecursive(cdmEntity, alreadyVisitedEntities, update);
             alreadyVisitedEntities.clear();
             logger.info("---- ending recursive load for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + "\n");
@@ -241,17 +240,12 @@ public class CacheLoader {
 
     protected CdmBase load(CdmBase cdmEntity) {
         logger.info("loading object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
-
-        cdmEntity = (CdmBase)ProxyUtils.deproxy(cdmEntity);
-
-        cdmCacher.put(cdmEntity);
-
+        cdmCacher.put((CdmBase)ProxyUtils.deproxy(cdmEntity));
         return cdmCacher.getFromCache(cdmEntity);
-
     }
 
 
-    private CdmBase loadRecursive(CdmBase cdmEntity,  Set<Object> alreadyVisitedEntities, boolean update) {
+    private CdmBase loadRecursive(CdmBase cdmEntity,  List<Object> alreadyVisitedEntities, boolean update) {
 
         CdmBase cachedCdmEntity = load(cdmEntity);
 
@@ -273,7 +267,7 @@ public class CacheLoader {
                 CdmBase cdmEntityInSubGraph = getCdmBaseTypeFieldValue(cdmEntity, cachedCdmEntity, field, alreadyVisitedEntities, update);
                 if(cdmEntityInSubGraph != null) {
                     //checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph);
-                    if(!alreadyVisitedEntities.contains(cdmEntityInSubGraph)) {
+                    if(!checkForIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph)) {
                         logger.info("recursive loading object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
                         loadRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, update);
                     } else {
@@ -293,7 +287,7 @@ public class CacheLoader {
     private CdmBase getCdmBaseTypeFieldValue(CdmBase cdmEntity,
             CdmBase cachedCdmEntity,
             String fieldName,
-            Set<Object> alreadyVisitedEntities,
+            List<Object> alreadyVisitedEntities,
             boolean update) {
 
         // this method attempts to make sure that for any two objects found in
@@ -324,7 +318,8 @@ public class CacheLoader {
             if(update) {
                 // if we are in update mode we have to make the field of the cached entity
                 // up-to-date by setting it to the value of the cdm entity being loaded
-                // NOTE : two exceptions to this are found below
+                // NOTE : the filed is overridden in the case of two exceptions
+                // found below
                 field.set(cachedCdmEntity, o);
 
             }
@@ -369,9 +364,9 @@ public class CacheLoader {
                             return null;
                         }
                     }
-                } else if(o instanceof Map && !alreadyVisitedEntities.contains(o)) {
+                } else if(o instanceof Map && !checkForIdenticalCdmEntity(alreadyVisitedEntities, o)) {
                     loadRecursive((Map)o, alreadyVisitedEntities, update);
-                } else if(o instanceof Collection && !alreadyVisitedEntities.contains(o)) {
+                } else if(o instanceof Collection && !checkForIdenticalCdmEntity(alreadyVisitedEntities, o)) {
                     loadRecursive((Collection)o, alreadyVisitedEntities, update);
                 }
             }
@@ -388,16 +383,11 @@ public class CacheLoader {
         }
     }
 
-    private boolean checkForIdenticalCdmEntity(Set<CdmBase> cbSet, CdmBase cbToCompare) {
-        if(cbToCompare != null) {
-            for(CdmBase cb : cbSet) {
-
-                if(cb == cbToCompare) {
+    private boolean checkForIdenticalCdmEntity(List<Object> objList, Object objToCompare) {
+        if(objToCompare != null) {
+            for(Object obj : objList) {
+                if(obj == objToCompare) {
                     return true;
-                } else {
-                    if(cb.equals(cbToCompare)) {
-                        logger.info("equal but non identical object found of type " + cbToCompare.getUserFriendlyTypeName() + " with id " + cbToCompare.getId());
-                    }
                 }
             }
         }
index 56e099729049c301a3ad29e2f1d6e31f2947f630..436711dbb88a03b3f5f79139e2aa2422bfdc1e46 100644 (file)
@@ -351,21 +351,11 @@ public class EntityCacherDebugResult {
             if(o != null) {
 
                 if(o instanceof HibernateProxy) {
-                    LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
-                    if(!hli.isUninitialized()) {
-                        o = hli.getImplementation();
-                    } else {
-                        isHibernateProxy = true;
-                    }
+                    isHibernateProxy = true;
                 }
 
                 if(o instanceof PersistentCollection) {
-                    PersistentCollection pc = ((PersistentCollection)o);
-                    if(pc.wasInitialized()) {
-                        o = ProxyUtils.getObject(pc);
-                    } else {
-                        isPersistentCollection = true;
-                    }
+                    isPersistentCollection = true;
                 }
                 childCei.setObject(o);
                 childCei.setProxy(isHibernateProxy || isPersistentCollection);
index c6c5032284ffbb4233b394d720cfd50a44c0f9dc..06a3f3e1e153ace0190d7477cde05781a8601714 100644 (file)
@@ -134,7 +134,7 @@ public class ProxyUtils {
         if(o != null && o instanceof HibernateProxy) {
             LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
             if(!hli.isUninitialized()) {
-                return ((HibernateProxy) o).getHibernateLazyInitializer().getImplementation();
+                return hli.getImplementation();
 
             }
         }
index 4efa1d39acb4a356dc567fe05f622ce383c4734d..a2b0a513e8e7ff2215c0466a4e6ff66af957d72c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<beans xmlns="http://www.springframework.org/schema/beans"\r
+<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans"\r
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"\r
   xmlns:tx="http://www.springframework.org/schema/tx"\r
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
@@ -7,7 +7,7 @@
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">\r
 \r
 \r
-  <bean id="agentService"\r
+  <bean id="agentService" \r
     class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
     <property name="serviceUrl">\r
       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/agent.service</value>\r
     </property>\r
   </bean>\r
 \r
-  <bean id="entityValidationResultService"\r
+  <bean id="entityValidationService"\r
     class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
     <property name="serviceUrl">\r
-      <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/entityvalidationresult.service</value>\r
+      <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/entityvalidation.service</value>\r
     </property>\r
     <property name="serviceInterface">\r
-      <value>eu.etaxonomy.cdm.api.service.IEntityValidationResultService\r
+      <value>eu.etaxonomy.cdm.api.service.IEntityValidationService\r
       </value>\r
     </property>\r
     <property name="httpInvokerRequestExecutor">\r
index 4a4f2ec46cd1e84dca584ab42c16e44d1a5e6a8f..f09d0c992267aad02f7cee2b7af1d28d7d9cb05e 100644 (file)
@@ -1,32 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:context="http://www.springframework.org/schema/context"
-       xmlns:tx="http://www.springframework.org/schema/tx"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
-       
-       
-    <!-- Default application context and term initializer -->
-  <import resource="classpath:/eu/etaxonomy/cdm/defaultApplicationContext.xml"/>
+
+  
+  <!-- Default application context and term initializer -->
+  <import resource="classpath:/eu/etaxonomy/cdm/defaultApplicationContext.xml" />
   <bean id="persistentTermInitializer" class="eu.etaxonomy.cdm.database.PersistentTermInitializer">
     <property name="omit" value="false" />
   </bean>
-    
-  <import resource="classpath:/eu/etaxonomy/cdm/remote.xml"/>
-  <import resource="classpath:eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml"/>
-  
-  <context:component-scan base-package="eu/etaxonomy/cdm/ext"/>
-  
+
+  <context:component-scan base-package="eu/etaxonomy/taxeditor/session" />
+  <import resource="classpath:/eu/etaxonomy/cdm/remote.xml" />
+  <import resource="classpath:eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml" />
+
+  <context:component-scan base-package="eu/etaxonomy/cdm/ext" />
+
   <context:component-scan base-package="eu/etaxonomy/cdm/remote">
-    <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.remote\.config\.DataSourceConfigurer" />
-    <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.remote\.config\.LoggingConfigurer" />
-    <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.remote\.view\.PatternViewResolver" />
-    <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.remote\.vaadin\..*" />
-    <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.remote\.controller\..*Portal.*" /> 
+    <context:exclude-filter type="regex"
+      expression="eu\.etaxonomy\.cdm\.remote\.config\.DataSourceConfigurer" />
+    <context:exclude-filter type="regex"
+      expression="eu\.etaxonomy\.cdm\.remote\.config\.LoggingConfigurer" />
+    <context:exclude-filter type="regex"
+      expression="eu\.etaxonomy\.cdm\.remote\.view\.PatternViewResolver" />
+    <context:exclude-filter type="regex"
+      expression="eu\.etaxonomy\.cdm\.remote\.vaadin\..*" />
+    <context:exclude-filter type="regex"
+      expression="eu\.etaxonomy\.cdm\.remote\.controller\..*Portal.*" />
   </context:component-scan>
-  
+
   <context:component-scan base-package="eu/etaxonomy/taxeditor/remoting/session/mock" />
 
 </beans>
index 9b9aea02c710e2683c44930c9c3c32a01915cc39..655d87e6e17bb7313b602229c5c7ab2c2d3e99ed 100644 (file)
@@ -7,9 +7,6 @@
     <session-factory>\r
 \r
       <property name="connection.release_mode">after_transaction</property>\r
-         <property name="show_sql">true</property>\r
-               <property name="format_sql">true</property>\r
-               <property name="use_sql_comments">true</property>\r
 \r
       <!-- Connection Pooling -->\r
 <!--       <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property> -->\r
@@ -67,6 +64,7 @@
       <mapping class="eu.etaxonomy.cdm.model.common.ExtensionType"/>\r
       <mapping class="eu.etaxonomy.cdm.model.common.IdentifiableSource"/>\r
       <mapping class="eu.etaxonomy.cdm.model.common.Identifier"/>\r
+      <mapping class="eu.etaxonomy.cdm.model.common.IntextReference"/>\r
       <mapping class="eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl"/>\r
       <mapping class="eu.etaxonomy.cdm.model.common.Group"/>\r
       <mapping class="eu.etaxonomy.cdm.model.common.Language"/>\r
       <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType"/>\r
       \r
       <!-- Validation Package -->\r
-      <mapping class="eu.etaxonomy.cdm.model.validation.EntityValidationResult"/>\r
+      <mapping class="eu.etaxonomy.cdm.model.validation.EntityValidation"/>\r
       <mapping class="eu.etaxonomy.cdm.model.validation.EntityConstraintViolation"/>\r
       \r
       <!-- View Package -->\r
index 6be7d0e585ccb6686f7218424ede6dfa9efeac1b..45680699262e637b473fffa97e2b68ce70b2a4fe 100644 (file)
@@ -6,8 +6,7 @@
 #\r
 #     java -Dlog4j.configDebug=true\r
 #\r
-\r
-log4j.rootLogger=WARN, stdout\r
+log4j.rootLogger=INFO, stdout\r
 \r
 \r
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
index 19893fb16c2e3d83451db87ff04c448633c85897..e59bba4e322ad780fc108970a0a88532933794a9 100644 (file)
Binary files a/eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.h2.db and b/eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.h2.db differ
index 7d3d1f8a9d4a53fb825370952d02cda78a4e7f65..ed16291f59256bfe8c8015e2052d6667078de2b1 100644 (file)
Binary files a/eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.trace.db and b/eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.trace.db differ
index f7976957db2c742368d5c4148336fcb66a32cd7d..86f622ea388a6dd352b1f9ffa51beb705b981844 100644 (file)
@@ -54,9 +54,6 @@ public class TaxonNameEditorTest extends OperationTestBase {
 
     private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
 
-
-
-
     ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
     ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
     IClassificationService classificationService = getRemoteApplicationController().getClassificationService();