Tweak performance for typeDesignation cache in label provider
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 1 Dec 2015 17:19:41 +0000 (18:19 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 2 Dec 2015 10:09:38 +0000 (11:09 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java

index 40481a9..d859b70 100644 (file)
@@ -928,12 +928,6 @@ public class TransientOccurenceService implements IOccurrenceService {
     }
 
     @Override
-    public Collection<SpecimenTypeDesignation> listTypeDesignations(SpecimenOrObservationBase<?> specimen,
-            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
-        return defaultService.listTypeDesignations(specimen, limit, start, orderHints, propertyPaths);
-    }
-
-    @Override
     public Collection<DescriptionBase<?>> listDescriptionsWithDescriptionSpecimen(
             SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints,
             List<String> propertyPaths) {
@@ -1081,12 +1075,6 @@ public class TransientOccurenceService implements IOccurrenceService {
         return defaultService.listIndividualsAssociationTaxa(arg0, arg1, arg2, arg3, arg4);
     }
 
-    @Override
-    public Collection<TaxonBase<?>> listTypeDesignationTaxa(SpecimenOrObservationBase<?> arg0, Integer arg1,
-            Integer arg2, List<OrderHint> arg3, List<String> arg4) {
-        return defaultService.listTypeDesignationTaxa(arg0, arg1, arg2, arg3, arg4);
-    }
-
      /**
      * {@inheritDoc}
      */
@@ -1095,4 +1083,23 @@ public class TransientOccurenceService implements IOccurrenceService {
         return defaultService.load(arg0, arg1);
     }
 
+    @Override
+    public Collection<TaxonBase<?>> listTypeDesignationTaxa(DerivedUnit arg0, Integer arg1, Integer arg2,
+            List<OrderHint> arg3, List<String> arg4) {
+        return defaultService.listTypeDesignationTaxa(arg0, arg1, arg2, arg3, arg4);
+    }
+
+    @Override
+    public Map<DerivedUnit, Collection<SpecimenTypeDesignation>> listTypeDesignations(Collection<DerivedUnit> arg0,
+            Integer arg1, Integer arg2, List<OrderHint> arg3, List<String> arg4) {
+        return defaultService.listTypeDesignations(arg0, arg1, arg2, arg3, arg4);
+    }
+
+    @Override
+    public Collection<SpecimenTypeDesignation> listTypeDesignations(DerivedUnit arg0, Integer arg1, Integer arg2,
+            List<OrderHint> arg3, List<String> arg4) {
+        return defaultService.listTypeDesignations(arg0, arg1, arg2, arg3, arg4);
+    }
+
+
 }
index 811c1e3..25ebd89 100644 (file)
@@ -238,7 +238,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
                 derivates = CdmStore.getService(IOccurrenceService.class).load(new ArrayList(derivativeUuids), SPECIMEN_INIT_STRATEGY);
             }
             updateRootEntities(derivates);
-            refreshTree(false);
+            labelProvider.initCache(derivates);
             previousCdmEntitySession.bind();
         }
     }
@@ -390,22 +390,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
      * Refreshes the derivate hierarchy tree
      */
     public void refreshTree(){
-        refreshTree(true);
-    }
-
-    /**
-     * Refreshes the derivate hierarchy tree
-     * @param refreshViewer if <code>true</code> then also the
-     * viewer will be refreshed. This was implemented due to
-     * performance reasons. If passing <code>false</code>
-     * does what was expected use <code>false</code> preferably.
-     */
-    public void refreshTree(boolean refreshViewer){
-        //refresh typedesignations
-        labelProvider.refresh();
-        if(refreshViewer){
-            viewer.refresh();
-        }
+        viewer.refresh();
     }
 
     //FIXME:Remoting hack to make this work for remoting
index 888a18e..d7cbfdd 100644 (file)
@@ -61,7 +61,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
 
     private static Set<SingleRead> multiLinkSingleReads;
 
-    private static Map<DerivedUnit, List<SpecimenTypeDesignation>> typeDesignations;
+    private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations;
 
     private ConversationHolder conversation;
 
@@ -421,22 +421,8 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return null;
     }
 
-    /**
-     * Refreshes cached label extensions
-     * @param multiLinkSingleReads
-     */
-    public void refresh() {
-        DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
-        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
-            if(entry.getValue().size()>1){
-                multiLinkSingleReads.add(entry.getKey());
-            }
-        }
-        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, List<SpecimenTypeDesignation>>();
-    }
-
     private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
-        List<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
+        Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
         if(list==null){
             list = new ArrayList<SpecimenTypeDesignation>();
         }
@@ -448,4 +434,21 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return multiLinkSingleReads;
     }
 
+    public void initCache(List<SpecimenOrObservationBase> derivates) {
+        DerivateLabelProvider.multiLinkSingleReads = new HashSet<SingleRead>();
+        DerivateLabelProvider.typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
+        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
+            if(entry.getValue().size()>1){
+                multiLinkSingleReads.add(entry.getKey());
+            }
+        }
+        Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
+        for (SpecimenOrObservationBase specimenOrObservationBase : derivates) {
+            if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
+                derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
+            }
+        }
+        typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(derivedUnits, null, null, null, null);
+    }
+
 }