cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject cayenne git commit: Fix dbImport result dialog.
Date Wed, 12 Dec 2018 10:36:06 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 82d1c06d5 -> 89be0cdff


Fix dbImport result dialog.


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/89be0cdf
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/89be0cdf
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/89be0cdf

Branch: refs/heads/master
Commit: 89be0cdff8655ff2583105e829a3c66c4aa76426
Parents: 82d1c06
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Wed Dec 12 13:35:55 2018 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Wed Dec 12 13:35:55 2018 +0300

----------------------------------------------------------------------
 .../action/ReverseEngineeringAction.java        | 41 ++++++++++++++++----
 .../modeler/dialog/db/load/DbLoaderContext.java | 15 ++++---
 .../dialog/db/load/ModelerDbImportAction.java   |  6 ++-
 .../dbimport/domain/DbImportTabController.java  |  5 +--
 4 files changed, 48 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/89be0cdf/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ReverseEngineeringAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ReverseEngineeringAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ReverseEngineeringAction.java
index 331bd54..de786ab 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ReverseEngineeringAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ReverseEngineeringAction.java
@@ -19,7 +19,9 @@
 
 package org.apache.cayenne.modeler.action;
 
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.db.DataSourceWizard;
 import org.apache.cayenne.modeler.dialog.db.DbActionOptionsDialog;
 import org.apache.cayenne.modeler.dialog.db.load.DbLoadResultDialog;
@@ -35,6 +37,8 @@ import javax.swing.SwingUtilities;
 import java.awt.event.ActionEvent;
 import java.sql.SQLException;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
 import static org.apache.cayenne.modeler.pref.DBConnectionInfo.*;
 
@@ -48,6 +52,8 @@ public class ReverseEngineeringAction extends DBWizardAction<DbActionOptionsDial
     private static final String DIALOG_TITLE = "Reengineer DB Schema: Connect to Database";
 
     private DbImportView view;
+    private int dataMapCount = 0;
+    protected Set<DataMap> dataMaps;
 
     public String getIconName() {
         return ICON_NAME;
@@ -61,7 +67,17 @@ public class ReverseEngineeringAction extends DBWizardAction<DbActionOptionsDial
         return ACTION_NAME;
     }
 
-    public void performAction() {
+    public void performAction(Set<DataMap> dataMapSet) {
+        resetParams();
+        dataMaps.addAll(dataMapSet);
+        ProjectController projectController = Application.getInstance().getFrameController().getProjectController();
+        for(DataMap dataMap : dataMapSet) {
+            projectController.setCurrentDataMap(dataMap);
+            startImport();
+        }
+    }
+
+    private void startImport(){
         final DbLoaderContext context = new DbLoaderContext(application.getMetaData());
         DBConnectionInfo connectionInfo;
         if (!datamapPreferencesExist()) {
@@ -86,12 +102,6 @@ public class ReverseEngineeringAction extends DBWizardAction<DbActionOptionsDial
             return;
         }
 
-        DbImportController dbImportController = Application.getInstance().getFrameController().getDbImportController();
-        DbLoadResultDialog dbLoadResultDialog = dbImportController.createDialog();
-        if(!dbLoadResultDialog.isVisible()) {
-            dbImportController.showDialog();
-        }
-
         if(!context.buildConfig(connectionInfo, view)) {
             try {
                 context.getConnection().close();
@@ -103,6 +113,14 @@ public class ReverseEngineeringAction extends DBWizardAction<DbActionOptionsDial
             application.getUndoManager().discardAllEdits();
             try {
                 context.getConnection().close();
+                dataMapCount++;
+                if(dataMapCount == dataMaps.size() && !context.isInterrupted()) {
+                    DbImportController dbImportController = Application.getInstance().getFrameController().getDbImportController();
+                    DbLoadResultDialog dbLoadResultDialog = dbImportController.createDialog();
+                    if (!dbLoadResultDialog.isVisible()) {
+                        dbImportController.showDialog();
+                    }
+                }
             } catch (SQLException ignored) {}
         });
     }
@@ -112,7 +130,14 @@ public class ReverseEngineeringAction extends DBWizardAction<DbActionOptionsDial
      */
     @Override
     public void performAction(ActionEvent event) {
-        performAction();
+        resetParams();
+        dataMaps.add(Application.getInstance().getFrameController().getProjectController().getCurrentDataMap());
+        startImport();
+    }
+
+    private void resetParams() {
+        dataMapCount = 0;
+        this.dataMaps = new HashSet<>();
     }
 
     private DBConnectionInfo getConnectionInfoFromPreferences() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/89be0cdf/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/DbLoaderContext.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/DbLoaderContext.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/DbLoaderContext.java
index 9ee8e8f..adec6d9 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/DbLoaderContext.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/DbLoaderContext.java
@@ -19,11 +19,6 @@
 
 package org.apache.cayenne.modeler.dialog.db.load;
 
-import java.io.File;
-import java.sql.Connection;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.dbsync.naming.NameBuilder;
@@ -40,6 +35,10 @@ import org.apache.cayenne.util.Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.swing.*;
+import java.io.File;
+import java.sql.Connection;
+
 /**
  * @since 4.0
  */
@@ -54,6 +53,7 @@ public class DbLoaderContext {
     private DataMap dataMap;
     private boolean stopping;
     private String loadStatusNote;
+    private boolean isInterrupted;
 
     private DataChannelMetaData metaData;
 
@@ -192,7 +192,12 @@ public class DbLoaderContext {
 
     public void processException(final Throwable th, final String message) {
         LOGGER.info("Exception on reverse engineering", Util.unwindException(th));
+        isInterrupted = true;
         SwingUtilities.invokeLater(() -> JOptionPane
                 .showMessageDialog(Application.getFrame(), th.getMessage(), message, JOptionPane.ERROR_MESSAGE));
     }
+
+    public boolean isInterrupted() {
+        return isInterrupted;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/89be0cdf/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
index b38fb8b..8be5309 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
@@ -104,8 +104,10 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
         logger.info("");
         resultDialog.getOkButton().addActionListener(e -> {
             try {
-                commit();
-                checkForUnusedImports();
+                if(resultDialog.getTableForMap().containsKey(targetMap)) {
+                    commit();
+                    checkForUnusedImports();
+                }
             } catch (Exception ex) {
                 throw new CayenneRuntimeException("Nothing to commit.");
             }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/89be0cdf/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/domain/DbImportTabController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/domain/DbImportTabController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/domain/DbImportTabController.java
index 04519ef..08b765c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/domain/DbImportTabController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/domain/DbImportTabController.java
@@ -47,10 +47,7 @@ public class DbImportTabController extends GeneratorsTabController {
         }
         Application.getInstance().getFrameController().getDbImportController().setGlobalImport(true);
         ReverseEngineeringAction reverseEngineeringAction = Application.getInstance().getActionManager().getAction(ReverseEngineeringAction.class);
-        for(DataMap dataMap : dataMaps) {
-            projectController.setCurrentDataMap(dataMap);
-            reverseEngineeringAction.performAction();
-        }
+        reverseEngineeringAction.performAction(dataMaps);
     }
 
     @Override


Mime
View raw message