further performance improvements: - better autoinitialization of collection items...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 19 May 2015 14:54:28 +0000 (16:54 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 19 May 2015 14:54:28 +0000 (16:54 +0200)
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoService.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoImpl.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/initializer/AdvancedBeanInitializer.java

index b530a34b4ba50635adb4bd36c580b83d0abec48a..de2603e8a8c688df37aa045db49f1fc5c87a8675 100644 (file)
@@ -306,7 +306,7 @@ public class EditGeoService implements IEditGeoService {
         DistributionInfoDTO dto = new DistributionInfoDTO();\r
 \r
         // Adding default initStrategies to improve the performance of this method\r
-        // adding 'status' and 'area.parentOf' has a good positive effect:\r
+        // adding 'status' and 'area' has a good positive effect:\r
         // filterDistributions() only takes 21% of the total method time (before it was 46%)\r
         // at the same time the cost of the getDescriptionElementForTaxon is not increased at all!\r
         //\r
@@ -318,8 +318,8 @@ public class EditGeoService implements IEditGeoService {
         if(!initStrategy.contains("status")) {\r
             initStrategy.add("status");\r
         }\r
-        if(!initStrategy.contains("area.parentOf")) {\r
-            initStrategy.add("area.parentOf");\r
+        if(!initStrategy.contains("area")) {\r
+            initStrategy.add("area");\r
         }\r
         if(!initStrategy.contains("markers.markerType")) {\r
             initStrategy.add("markers.markerType");\r
index 14d6862a7aee792cf3b3a457131cb7380335439b..820e262f729835b90bd5bbcf401e3bea3efbaffc 100644 (file)
@@ -698,6 +698,8 @@ public class DescriptionDaoImpl extends IdentifiableDaoBase<DescriptionBase> imp
             Class<T> type, Integer pageSize,\r
             Integer pageNumber, List<String> propertyPaths) {\r
 \r
+//        Logger.getLogger("org.hibernate.SQL").setLevel(Level.TRACE);\r
+\r
         Query query = prepareGetDescriptionElementForTaxon(taxonUuid, features, type, pageSize, pageNumber, false);\r
 \r
         if (logger.isDebugEnabled()){logger.debug(" dao: get list ...");}\r
@@ -705,6 +707,8 @@ public class DescriptionDaoImpl extends IdentifiableDaoBase<DescriptionBase> imp
         if (logger.isDebugEnabled()){logger.debug(" dao: initialize ...");}\r
         defaultBeanInitializer.initializeAll(results, propertyPaths);\r
         if (logger.isDebugEnabled()){logger.debug(" dao: initialize - DONE");}\r
+\r
+//        Logger.getLogger("org.hibernate.SQL").setLevel(Level.WARN);\r
         return results;\r
     }\r
 \r
index 5e75c9dbd9dc90ad89c112d6df6670cab129529d..aefa3340de14451c5751ea1d5ced08fdda4ca5aa 100644 (file)
@@ -6,6 +6,8 @@ package eu.etaxonomy.cdm.persistence.dao.initializer;
 import java.beans.PropertyDescriptor;\r
 import java.io.Serializable;\r
 import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.ParameterizedType;\r
+import java.lang.reflect.Type;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.Collections;\r
@@ -221,15 +223,16 @@ public class AdvancedBeanInitializer extends HibernateBeanInitializer {
                 }\r
                 //new\r
                 for (Object parentBean : parentBeans){\r
+                    String propertyName = mapFieldToPropertyName(property, parentBean.getClass().getSimpleName());\r
                     try{\r
-                        Object propertyValue = PropertyUtils.getProperty(parentBean, mapFieldToPropertyName(property, parentBean.getClass().getSimpleName()));\r
+                        Object propertyValue = PropertyUtils.getProperty(parentBean, propertyName);\r
                         preparePropertyValueForBulkLoadOrStore(node, parentBean, property, propertyValue);\r
                     } catch (IllegalAccessException e) {\r
                         logger.error("Illegal access on property " + property);\r
                     } catch (InvocationTargetException e) {\r
                         logger.error("Cannot invoke property " + property + " not found");\r
                     } catch (NoSuchMethodException e) {\r
-                        if (logger.isDebugEnabled()){logger.debug("Property " + property + " not found for class " + parentClazz);}\r
+                        if (logger.isDebugEnabled()){logger.debug("Property " + propertyName + " not found for class " + parentClazz);}\r
                     }\r
                 }\r
 \r
@@ -384,23 +387,31 @@ public class AdvancedBeanInitializer extends HibernateBeanInitializer {
                                        if (idSet != null && ! idSet.isEmpty()){\r
                                                if (logger.isTraceEnabled()){logger.trace("bulk load " + node + " collections ; ownerClass=" +  ownerClazz.getSimpleName() + " ; param = " + param);}\r
 \r
+                                               Type collectionEntitiyType = null;\r
+                                               PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(ownerClazz);\r
+                                               for(PropertyDescriptor d : descriptors) {\r
+                                                   if(d.getName().equals(param)) {\r
+                                ParameterizedType pt = (ParameterizedType) d.getReadMethod().getGenericReturnType();\r
+                                collectionEntitiyType = pt.getActualTypeArguments()[0];\r
+                                                   }\r
+                                               }\r
+\r
                                                //TODO use entity name ??\r
                                                //get from repository\r
                                                List<Object[]> list;\r
                                                String hql = "SELECT oc " +\r
-                                                               " FROM %s as oc JOIN FETCH oc.%s as col %s " +\r
+                                                               " FROM %s as oc LEFT JOIN FETCH oc.%s as col %s" +\r
                                                                " WHERE oc.id IN (:idSet) ";\r
 \r
-//                                             String hql = "SELECT oc.%s " +\r
-//                                                             " FROM %s as oc WHERE oc.id IN (:idSet) ";\r
                                                hql = String.format(hql, ownerClazz.getSimpleName(), param,\r
-                                                               "" /*addAutoinitFetchLoading(clazz, "col")*/);\r
+                                                       addAutoinitFetchLoading((Class)collectionEntitiyType, "col"));\r
 \r
                                                try {\r
                                                        if (logger.isTraceEnabled()){logger.trace(hql);}\r
                                                        Query query = genericDao.getHqlQuery(hql);\r
                                                        query.setParameterList("idSet", idSet);\r
                                                        list = query.list();\r
+                                                       if (logger.isTraceEnabled()){logger.trace("size of retrieved list is " + list.size());}\r
                                                } catch (HibernateException e) {\r
                                                        e.printStackTrace();\r
                                                        throw e;\r
@@ -422,7 +433,8 @@ public class AdvancedBeanInitializer extends HibernateBeanInitializer {
                                                                if (newBean instanceof HibernateProxy){\r
                                                                    newBean = initializeInstance(newBean);\r
                                                                }\r
-                                                               autoinitializeBean(newBean);\r
+                                                               // no longer needed since the hql is getting the AutoinitFetchLoading statements\r
+//                                                             autoinitializeBean(newBean);\r
                                                                node.addBean(newBean);\r
                                                            }\r
                                                        }\r
@@ -438,6 +450,9 @@ public class AdvancedBeanInitializer extends HibernateBeanInitializer {
                        for (AbstractPersistentCollection collection : node.getUninitializedCollections()){\r
                                if (! collection.wasInitialized()){  //should not happen anymore\r
                                        collection.forceInitialization();\r
+                                       if (logger.isTraceEnabled()){logger.trace("forceInitialization of collection " + collection);}\r
+                               } else {\r
+                                   if (logger.isTraceEnabled()){logger.trace("collection " + collection + " is initialized - OK!");}\r
                                }\r
                        }\r
 \r