fixes bug 40235: Avoid delay per exported module in export.database 3.0PR19Q1
authorCarlos Aristu <carlos.aristu@openbravo.com>
Mon, 18 Feb 2019 16:51:51 +0100
changeset 1182 57cfaa7f043b
parent 1167 8d2733ae1b70
child 1183 3d9a52e2d766
fixes bug 40235: Avoid delay per exported module in export.database

Before exporting the source data of the modules in "in development" status, the model is reloaded from the previously exported XML model files. This is done to ensure that the source data is exported using the same order of the columns which is defined in the XML files, instead of using the order in the database because this can be different.

For example, the order can be different in the database when adding a new column to a table. The new column will be added at the last position, because the table will not be recreated. But if this new column is not the last one in the XML file that defines the table, then under this scenario the order of the columns in the database will be different from the order in the XML file.

This model reloading was being done per every module being exported. This is not needed as the model does not change at this point, so it can be reloaded just once, right before starting the exportation of the source data.
src/org/openbravo/ddlutils/task/ExportDatabase.java
--- a/src/org/openbravo/ddlutils/task/ExportDatabase.java	Wed Nov 07 17:49:35 2018 +0100
+++ b/src/org/openbravo/ddlutils/task/ExportDatabase.java	Mon Feb 18 16:51:51 2019 +0100
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2018 Openbravo S.L.U.
+ * Copyright (C) 2001-2019 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -173,6 +173,13 @@
       for (String dataset : datasetArray)
         datasets.add(dataset);
 
+      // once model is exported, reload it from files to guarantee data is exported in a fixed
+      // manner, other case column position could be different
+      // we just need to reload it once before exporting the source data because the model
+      // information is the same for all the modules about to be exported
+      Database dbXML = DatabaseUtils.readDatabaseModel(platform, model,
+          moduledir.getAbsolutePath(), "*/src-db/database/model");
+
       int datasetI = 0;
       for (final String dataSetCode : datasets) {
         if (dataSetCode.equalsIgnoreCase("ADRD") && !rd)
@@ -232,11 +239,6 @@
           final DatabaseDataIO dbdio = new DatabaseDataIO();
           dbdio.setEnsureFKOrder(false);
 
-          // once model is exported, reload it from files to guarantee data is exported in a fixed
-          // manner, other case column position could be different
-          Database dbXML = DatabaseUtils.readDatabaseModel(platform, model,
-              moduledir.getAbsolutePath(), "*/src-db/database/model");
-
           if (util.getActiveModule(i).name.equalsIgnoreCase("CORE") || dataSetCode.equals("AD")) {
             getLog().info("Path: " + path);
             DatabaseData dataToExport = new DatabaseData(db);