ref #6359 improve partition handling
authorAndreas Müller <a.mueller@bgbm.org>
Thu, 6 May 2021 21:22:49 +0000 (23:22 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 6 May 2021 21:22:49 +0000 (23:22 +0200)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java

index 1face7f1f9e1d7fc37fa585372422f21cf5cb0d4..ec86ec2478b2b1bdb50cece62f7fdcc073dcfcb2 100755 (executable)
@@ -70,6 +70,8 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
 \r
        private static final Logger logger = Logger.getLogger(TaxonNodeDaoHibernateImpl.class);\r
 \r
+    private static final int DEFAULT_SET_SUBTREE_PARTITION_SIZE = 100;\r
+\r
        @Autowired\r
        private ITaxonDao taxonDao;\r
        @Autowired\r
@@ -751,7 +753,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
     private <T extends TaxonBase<?>> Set<T> setSecundum(Reference newSec, boolean emptyDetail, String queryStr, IProgressMonitor monitor) {\r
         Set<T> result = new HashSet<>();\r
         Query query = getSession().createQuery(queryStr);\r
-        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_PARTITION_SIZE);\r
+        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_SET_SUBTREE_PARTITION_SIZE);\r
         for (List<Integer> taxonIdList : partitionList){\r
             List<TaxonBase> taxonList = taxonDao.loadList(taxonIdList, null, null);\r
             for (TaxonBase<?> taxonBase : taxonList){\r
@@ -775,10 +777,17 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
                     }\r
                 }\r
             }\r
+            commitAndRestartTransaction(newSec);\r
         }\r
         return result;\r
     }\r
 \r
+    private void commitAndRestartTransaction(CdmBase... cdmBaseToUpdate) {\r
+        getSession().getTransaction().commit();\r
+        getSession().beginTransaction();\r
+        getSession().update(cdmBaseToUpdate);\r
+    }\r
+\r
     @Override\r
     public Set<TaxonRelationship> setSecundumForSubtreeRelations(TreeIndex subTreeIndex, Reference newRef,\r
             Set<UUID> relationTypes,  boolean overwriteExisting, boolean includeSharedTaxa, boolean emptyDetail, IProgressMonitor monitor) {\r
@@ -788,7 +797,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
         Set<TaxonRelationship> result = new HashSet<>();\r
         Query query = getSession().createQuery(queryStr);\r
         @SuppressWarnings("unchecked")\r
-        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_PARTITION_SIZE);\r
+        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_SET_SUBTREE_PARTITION_SIZE);\r
         for (List<Integer> relIdList : partitionList){\r
             List<TaxonRelationship> relList = taxonRelDao.loadList(relIdList, null, null);\r
             for (TaxonRelationship rel : relList){\r
@@ -812,6 +821,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
                     }\r
                 }\r
             }\r
+            commitAndRestartTransaction();\r
         }\r
 \r
         return result;\r
@@ -880,8 +890,6 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
         return setPublish(publish, queryStr, relationTypes, monitor);\r
     }\r
 \r
-    private static final int DEFAULT_PARTITION_SIZE = 100;\r
-\r
     private <T extends TaxonBase<?>> Set<T> setPublish(boolean publish, String queryStr, Set<UUID> relTypeUuids, IProgressMonitor monitor) {\r
         Set<T> result = new HashSet<>();\r
         Query query = getSession().createQuery(queryStr);\r
@@ -890,7 +898,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
             query.setParameterList("relTypeUuid", relTypeUuids);\r
         }\r
         @SuppressWarnings("unchecked")\r
-        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_PARTITION_SIZE);\r
+        List<List<Integer>> partitionList = splitIdList(query.list(), DEFAULT_SET_SUBTREE_PARTITION_SIZE);\r
         for (List<Integer> taxonIdList : partitionList){\r
             List<TaxonBase> taxonList = taxonDao.loadList(taxonIdList, null, null);\r
             for (TaxonBase<?> taxonBase : taxonList){\r
@@ -905,6 +913,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
                     }\r
                 }\r
             }\r
+            commitAndRestartTransaction();\r
         }\r
         return result;\r
     }\r