From aad5777c6d36535f545e87c1fb1db5ea296873b7 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 3 Aug 2011 09:11:12 +0000
Subject: [PATCH] Completed implementation of
 IDataSetRegistrationTransaction.getDatabaseQuery()

SVN: 22312
---
 .../api/v1/impl/AbstractTransactionState.java    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java
index 5cae0002ad7..6654248f8af 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/AbstractTransactionState.java
@@ -120,8 +120,8 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
 
         private final List<Material> materialsToBeRegistered = new ArrayList<Material>();
 
-        private final List<DynamicTransactionQuery> queriesToCommit =
-                new ArrayList<DynamicTransactionQuery>();
+        private final Map<String, DynamicTransactionQuery> queriesToCommit =
+                new HashMap<String, DynamicTransactionQuery>();
 
         private String userIdOrNull = null;
 
@@ -441,8 +441,12 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
 
         public DynamicTransactionQuery getDatabaseQuery(String dataSourceName)
         {
-            DynamicTransactionQuery query = QueryTool.getQuery(DynamicTransactionQuery.class);
-            queriesToCommit.add(query);
+            DynamicTransactionQuery query = queriesToCommit.get(dataSourceName);
+            if (null == query)
+            {
+                query = QueryTool.getQuery(DynamicTransactionQuery.class);
+                queriesToCommit.put(dataSourceName, query);
+            }
             return query;
         }
 
@@ -480,7 +484,7 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
             DataSetStorageAlgorithmRunner<T> runner =
                     new DataSetStorageAlgorithmRunner<T>(algorithms, parent, parent);
             List<DataSetInformation> datasets = runner.prepareAndRunStorageAlgorithms();
-            for (DynamicTransactionQuery query : queriesToCommit)
+            for (DynamicTransactionQuery query : queriesToCommit.values())
             {
                 query.commit();
                 query.close(false);
@@ -497,7 +501,7 @@ abstract class AbstractTransactionState<T extends DataSetInformation>
         {
             rollbackStack.rollbackAll();
             registeredDataSets.clear();
-            for (DynamicTransactionQuery query : queriesToCommit)
+            for (DynamicTransactionQuery query : queriesToCommit.values())
             {
                 query.rollback();
                 query.close(false);
-- 
GitLab