cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/2] cayenne git commit: CAY-1977 | Add catalog selector to the "Reengineer Database Schema: Select Options" dialog
Date Tue, 09 Dec 2014 16:39:12 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master c9793921b -> 053b0c222


CAY-1977 | Add catalog selector to the "Reengineer Database Schema: Select Options" dialog


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

Branch: refs/heads/master
Commit: 20c3e9449b732e2af834227d5456358cbbcdea3a
Parents: 2d8ffba
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Fri Dec 5 14:49:23 2014 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Fri Dec 5 14:49:23 2014 +0300

----------------------------------------------------------------------
 .../access/loader/filters/EntityFilters.java    |  4 ++
 .../modeler/dialog/db/DbLoaderHelper.java       | 61 +++++++++++++----
 .../dialog/db/DbLoaderOptionsDialog.java        | 72 ++++++++++++++------
 3 files changed, 102 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/20c3e944/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
index 42321e2..3bca506 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/filters/EntityFilters.java
@@ -315,6 +315,10 @@ public class EntityFilters {
             return this;
         }
 
+        public String catalog() {
+            return catalog;
+        }
+
         public String schema() {
             return schema;
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/20c3e944/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
index 64fc8c6..f19e758 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
@@ -19,17 +19,6 @@
 
 package org.apache.cayenne.modeler.dialog.db;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DbLoader;
@@ -60,6 +49,16 @@ import org.apache.cayenne.util.Util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 import static org.apache.cayenne.access.loader.filters.FilterFactory.NULL;
 
 /**
@@ -84,10 +83,12 @@ public class DbLoaderHelper {
 
     protected ProjectController mediator;
     protected String dbUserName;
+    protected String dbCatalog;
     protected DbLoader loader;
     protected DataMap dataMap;
     protected boolean meaningfulPk;
     protected List<String> schemas;
+    protected List<String> catalogs;
 
     private final EntityFilters.Builder filterBuilder = new EntityFilters.Builder();
 
@@ -109,6 +110,11 @@ public class DbLoaderHelper {
     public DbLoaderHelper(ProjectController mediator, Connection connection, DbAdapter adapter,
String dbUserName) {
         this.dbUserName = dbUserName;
         this.mediator = mediator;
+        try {
+            this.dbCatalog = connection.getCatalog();
+        } catch (SQLException e) {
+            logObj.warn("Error getting catalog.", e);
+        }
         this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
     }
 
@@ -144,19 +150,26 @@ public class DbLoaderHelper {
     public void execute() {
         stoppingReverseEngineering = false;
 
+        // load catalogs...
+        LongRunningTask loadCatalogsTask = new LoadCatalogsTask(Application.getFrame(), "Loading
Catalogs");
+        loadCatalogsTask.startAndWait();
+
+        if (stoppingReverseEngineering) {
+            return;
+        }
+
         // load schemas...
         LongRunningTask loadSchemasTask = new LoadSchemasTask(Application.getFrame(), "Loading
Schemas");
-
         loadSchemasTask.startAndWait();
 
         if (stoppingReverseEngineering) {
             return;
         }
 
-        final DbLoaderOptionsDialog dialog = new DbLoaderOptionsDialog(schemas, dbUserName,
false);
+        final DbLoaderOptionsDialog dialog = new DbLoaderOptionsDialog(schemas, catalogs,
dbUserName, dbCatalog, false);
 
         try {
-            // since we are not inside EventDisptahcer Thread, must run it via
+            // since we are not inside EventDispatcher Thread, must run it via
             // SwingUtilities
             SwingUtilities.invokeAndWait(new Runnable() {
 
@@ -174,6 +187,7 @@ public class DbLoaderHelper {
             return;
         }
 
+        this.filterBuilder.catalog(dialog.getSelectedCatalog());
         this.filterBuilder.schema(dialog.getSelectedSchema());
         this.filterBuilder.includeTables(dialog.getTableNamePattern());
         this.filterBuilder.setProceduresFilters(dialog.isLoadingProcedures() ? FilterFactory.TRUE
: FilterFactory.NULL);
@@ -337,6 +351,24 @@ public class DbLoaderHelper {
         }
     }
 
+    final class LoadCatalogsTask extends DbLoaderTask {
+
+        public LoadCatalogsTask(JFrame frame, String title) {
+            super(frame, title);
+        }
+
+        @Override
+        protected void execute() {
+            loadStatusNote = "Loading available catalogs...";
+
+            try {
+                catalogs = loader.getCatalogs();
+            } catch (Throwable th) {
+                processException(th, "Error Loading Catalogs");
+            }
+        }
+    }
+
     final class LoadDataMapTask extends DbLoaderTask {
 
         public LoadDataMapTask(JFrame frame, String title) {
@@ -354,6 +386,7 @@ public class DbLoaderHelper {
             if (!existingMap) {
                 dataMap = new DataMap(DefaultUniqueNameGenerator.generate(NameCheckers.dataMap));
                 dataMap.setName(DefaultUniqueNameGenerator.generate(NameCheckers.dataMap,
mediator.getProject().getRootNode()));
+                dataMap.setDefaultCatalog(filterBuilder.catalog());
                 dataMap.setDefaultSchema(filterBuilder.schema());
             }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/20c3e944/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderOptionsDialog.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderOptionsDialog.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderOptionsDialog.java
index fe24b30..713e459 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderOptionsDialog.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderOptionsDialog.java
@@ -19,12 +19,16 @@
 
 package org.apache.cayenne.modeler.dialog.db;
 
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.Collection;
-import java.util.Vector;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+import org.apache.cayenne.access.DbLoader;
+import org.apache.cayenne.map.naming.ObjectNameGenerator;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.ClassLoadingService;
+import org.apache.cayenne.modeler.util.CayenneDialog;
+import org.apache.cayenne.modeler.util.NameGeneratorPreferences;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
@@ -37,18 +41,12 @@ import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
-
-import org.apache.cayenne.access.DbLoader;
-import org.apache.cayenne.map.naming.ObjectNameGenerator;
-import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.ClassLoadingService;
-import org.apache.cayenne.modeler.util.CayenneDialog;
-import org.apache.cayenne.modeler.util.NameGeneratorPreferences;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Collection;
+import java.util.Vector;
 
 /**
  * Dialog for selecting database reverse-engineering parameters.
@@ -60,6 +58,8 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
     public static final int CANCEL = 0;
     public static final int SELECT = 1;
 
+    protected JLabel catalogLabel;
+    protected JComboBox catalogSelector;
     protected JLabel schemaLabel;
     protected JComboBox schemaSelector;
     protected JTextField tableNamePatternField;
@@ -82,13 +82,13 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
     /**
      * Creates and initializes new ChooseSchemaDialog.
      */
-    public DbLoaderOptionsDialog(Collection<String> schemas, String dbUserName,
-            boolean loadProcedures) {
+    public DbLoaderOptionsDialog(Collection<String> schemas, Collection<String>
catalogs, String dbUserName,
+            String dbCatalog, boolean loadProcedures) {
         super(Application.getFrame(), "Reengineer DB Schema: Select Options");
 
         init();
         initController();
-        initFromModel(schemas, dbUserName, loadProcedures);
+        initFromModel(schemas, catalogs, dbUserName, dbCatalog, loadProcedures);
 
         pack();
         setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
@@ -102,6 +102,7 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
         // create widgets...
         selectButton = new JButton("Continue");
         cancelButton = new JButton("Cancel");
+        catalogSelector = new JComboBox();
         schemaSelector = new JComboBox();
         tableNamePatternField = new JTextField();
         procNamePatternField = new JTextField();
@@ -117,6 +118,7 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
         builder.setDefaultDialogBorder();
 
+        catalogLabel = builder.append("Select Catalog:", catalogSelector);
         schemaLabel = builder.append("Select Schema:", schemaSelector);
         builder.append("Table Name Pattern:", tableNamePatternField);
         builder.append("Load Procedures:", loadProcedures);
@@ -159,7 +161,9 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
 
     protected void initFromModel(
             Collection<String> schemas,
+            Collection<String> catalogs,
             String dbUserName,
+            String dbCatalog,
             boolean shouldLoadProcedures) {
 
         this.choice = CANCEL;
@@ -192,6 +196,24 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
                 }
             }
         }
+
+        boolean showCatalogSelector = catalogs != null && !catalogs.isEmpty();
+        catalogSelector.setVisible(showCatalogSelector);
+        catalogLabel.setVisible(showCatalogSelector);
+
+        if (showCatalogSelector) {
+            catalogSelector.setModel(new DefaultComboBoxModel(catalogs.toArray()));
+
+            if (dbCatalog != null && !dbCatalog.isEmpty()) {
+                for (String catalog : catalogs) {
+                    if (dbCatalog.equalsIgnoreCase(catalog)) {
+                        catalogSelector.setSelectedItem(catalog);
+                        break;
+                    }
+                }
+            }
+        }
+
     }
 
     public int getChoice() {
@@ -238,6 +260,14 @@ public class DbLoaderOptionsDialog extends CayenneDialog {
     }
 
     /**
+     * Returns selected catalog.
+     */
+    public String getSelectedCatalog() {
+        String catalog = (String) catalogSelector.getSelectedItem();
+        return "".equals(catalog) ? null : catalog;
+    }
+
+    /**
      * Returns selected schema.
      */
     public String getSelectedSchema() {


Mime
View raw message