cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [02/10] cayenne git commit: Refactoring.
Date Mon, 05 Nov 2018 13:28:59 GMT
Refactoring.


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

Branch: refs/heads/master
Commit: 98541384b35f5a70d9eaf8e8d50d312cb9d77098
Parents: 65d76d9
Author: kkomyak <const1993@gmail.com>
Authored: Mon Oct 29 10:16:36 2018 +0300
Committer: kkomyak <const1993@gmail.com>
Committed: Mon Oct 29 10:50:33 2018 +0300

----------------------------------------------------------------------
 .../modeler/action/LoadDbSchemaAction.java      |  12 +-
 .../editor/dbimport/DatabaseSchemaLoader.java   |  21 ++--
 .../editor/dbimport/DbImportNodeHandler.java    |  12 +-
 .../modeler/editor/dbimport/DbImportTree.java   | 124 +++++++++----------
 4 files changed, 86 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/98541384/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/LoadDbSchemaAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/LoadDbSchemaAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/LoadDbSchemaAction.java
index 406dc64..da0c659 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/LoadDbSchemaAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/LoadDbSchemaAction.java
@@ -22,7 +22,6 @@ package org.apache.cayenne.modeler.action;
 import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.dialog.db.DataSourceWizard;
-import org.apache.cayenne.modeler.dialog.db.load.TransferableNode;
 import org.apache.cayenne.modeler.editor.dbimport.DatabaseSchemaLoader;
 import org.apache.cayenne.modeler.editor.dbimport.DbImportModel;
 import org.apache.cayenne.modeler.editor.dbimport.DbImportView;
@@ -49,7 +48,6 @@ public class LoadDbSchemaAction extends CayenneAction {
 
     private static final String ICON_NAME = "icon-dbi-refresh.png";
     private static final String ACTION_NAME = "Refresh Db Schema";
-    public static final String LOAD_COLUMN_COMMAND = "load-columns";
     private DraggableTreePanel draggableTreePanel;
 
     LoadDbSchemaAction(Application application) {
@@ -62,6 +60,10 @@ public class LoadDbSchemaAction extends CayenneAction {
 
     @Override
     public void performAction(ActionEvent e) {
+        performAction(e, null);
+    }
+
+    public void performAction(ActionEvent e, TreePath tablePath) {
         final DbImportView rootParent = ((DbImportView) draggableTreePanel.getParent().getParent());
         rootParent.getLoadDbSchemaProgress().setVisible(true);
         rootParent.getLoadDbSchemaButton().setEnabled(false);
@@ -83,12 +85,10 @@ public class LoadDbSchemaAction extends CayenneAction {
                     connectionInfo = getConnectionInfoFromPreferences();
                 }
 
-                if (LOAD_COLUMN_COMMAND.equals(e.getActionCommand())) {
-                    TreePath source = (TreePath) e.getSource();
+                if (tablePath != null) {
                     ReverseEngineering databaseReverseEngineering = new DatabaseSchemaLoader()
-                            .loadColumns(connectionInfo, getApplication().getClassLoadingService(),
source);
+                            .loadColumns(connectionInfo, getApplication().getClassLoadingService(),
tablePath);
                     draggableTreePanel.getSourceTree().updateTableColumns(databaseReverseEngineering);
-
                 } else {
                     ReverseEngineering databaseReverseEngineering = new DatabaseSchemaLoader()
                             .load(connectionInfo, getApplication().getClassLoadingService());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/98541384/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DatabaseSchemaLoader.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DatabaseSchemaLoader.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DatabaseSchemaLoader.java
index 6c2ee45..43dc96c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DatabaseSchemaLoader.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DatabaseSchemaLoader.java
@@ -19,7 +19,12 @@
 
 package org.apache.cayenne.modeler.editor.dbimport;
 
-import org.apache.cayenne.dbsync.reverse.dbimport.*;
+import org.apache.cayenne.dbsync.reverse.dbimport.Catalog;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
+import org.apache.cayenne.dbsync.reverse.dbimport.Schema;
 import org.apache.cayenne.modeler.ClassLoadingService;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 
@@ -44,7 +49,6 @@ public class DatabaseSchemaLoader {
     }
 
     public ReverseEngineering load(DBConnectionInfo connectionInfo, ClassLoadingService loadingService)
throws SQLException {
-        String columnName = "Loading...";
         try (Connection connection = connectionInfo.makeDataSource(loadingService).getConnection())
{
             String[] types = {"TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL
TEMPORARY", "ALIAS", "SYNONYM"};
             try (ResultSet rs = connection.getMetaData().getCatalogs()) {
@@ -65,10 +69,9 @@ public class DatabaseSchemaLoader {
                         tableName = resultSet.getString(TABLE_INDEX);
                         schemaName = resultSet.getString(SCHEMA_INDEX);
                         catalogName = resultSet.getString(CATALOG_INDEX);
-                        packTable(tableName, catalogName, schemaName, columnName);
+                        packTable(tableName, catalogName, schemaName, null);
                     }
                     packFunctions(connection);
-                    columnName = null;
                 }
             }
         }
@@ -81,10 +84,7 @@ public class DatabaseSchemaLoader {
         String tableName = path.getPathComponent(2).toString();
 
         try (Connection connection = connectionInfo.makeDataSource(loadingService).getConnection())
{
-            String[] types = {"TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL
TEMPORARY", "ALIAS", "SYNONYM"};
-            try (ResultSet rs = connection.getMetaData().getColumns(catalogName, schemaName,
tableName, "");) {
-                String defaultCatalog = connection.getCatalog();
-
+            try (ResultSet rs = connection.getMetaData().getColumns(catalogName, schemaName,
tableName, "")) {
                 while (rs.next()) {
                     String column = rs.getString(4);
                     packTable(tableName, catalogName, schemaName, column);
@@ -95,7 +95,6 @@ public class DatabaseSchemaLoader {
         return databaseReverseEngineering;
     }
 
-
     private void packFunctions(Connection connection) throws SQLException {
         Collection<Catalog> catalogs = databaseReverseEngineering.getCatalogs();
         for (Catalog catalog : catalogs) {
@@ -135,10 +134,6 @@ public class DatabaseSchemaLoader {
         }
     }
 
-    private void packTable(String tableName, String catalogName, String schemaName) {
-        packTable(tableName,catalogName, schemaName, null);
-    }
-
     private void packTable(String tableName, String catalogName, String schemaName, String
columnName) {
         IncludeTable table = new IncludeTable();
         table.setPattern(tableName);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/98541384/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportNodeHandler.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportNodeHandler.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportNodeHandler.java
index 0b26c62..df25634 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportNodeHandler.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportNodeHandler.java
@@ -19,7 +19,15 @@
 
 package org.apache.cayenne.modeler.editor.dbimport;
 
-import org.apache.cayenne.dbsync.reverse.dbimport.*;
+import org.apache.cayenne.dbsync.reverse.dbimport.Catalog;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
+import org.apache.cayenne.dbsync.reverse.dbimport.Schema;
 import org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode;
 
 import javax.swing.tree.TreePath;
@@ -325,7 +333,7 @@ class DbImportNodeHandler {
     }
 
     public boolean getHasEntitiesInEmptyContainer() {
-        return true;
+        return hasEntitiesInEmptyContainer;
     }
 
     public void setHasEntitiesInEmptyContainer(boolean newFlag) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/98541384/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportTree.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportTree.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportTree.java
index b4a3ec6..6019968 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportTree.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportTree.java
@@ -19,7 +19,14 @@
 
 package org.apache.cayenne.modeler.editor.dbimport;
 
-import org.apache.cayenne.dbsync.reverse.dbimport.*;
+import org.apache.cayenne.dbsync.reverse.dbimport.Catalog;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.FilterContainer;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.PatternParam;
+import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
+import org.apache.cayenne.dbsync.reverse.dbimport.Schema;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.action.LoadDbSchemaAction;
 import org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode;
@@ -30,13 +37,10 @@ import javax.swing.event.TreeExpansionEvent;
 import javax.swing.event.TreeExpansionListener;
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.awt.event.ActionEvent;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
 
-import static org.apache.cayenne.modeler.action.LoadDbSchemaAction.LOAD_COLUMN_COMMAND;
 
 /**
  * @since 4.1
@@ -73,77 +77,70 @@ public class DbImportTree extends JTree {
         DbImportModel model = (DbImportModel) this.getModel();
 
         DbImportTreeNode root = (DbImportTreeNode) model.getRoot();
-        Iterator<Catalog> catalogs = reverseEngineering.getCatalogs().iterator();
-        while (catalogs.hasNext()) {
-            Catalog newCatalog = catalogs.next();
+        reverseEngineering.getCatalogs().forEach(newCatalog -> {
             DbImportTreeNode catalog = findNodeInParent(root, newCatalog);
 
             if (catalog == null) {
-                continue;
+                return;
             }
 
-            Iterator<IncludeTable> includeTables = newCatalog.getIncludeTables().iterator();
-            while (includeTables.hasNext()) {
-                IncludeTable newTable = includeTables.next();
+            newCatalog.getIncludeTables().forEach(newTable -> {
                 DbImportTreeNode table = findNodeInParent(catalog, newTable);
                 if (table == null) {
-                    continue;
+                    return;
                 }
                 table.removeAllChildren();
                 newTable.getIncludeColumns().forEach(column ->
-                    table.add(new DbImportTreeNode(column)));
+                        table.add(new DbImportTreeNode(column)));
                 table.setLoaded(true);
                 model.reload(table);
+            });
+        });
+    }
+
+    private DbImportTreeNode findNodeInParent(DbImportTreeNode parent, Object object) {
+        for (int i = 0; i <= parent.getChildCount(); i++) {
+            DbImportTreeNode node = (DbImportTreeNode) parent.getChildAt(i);
+            Object userObject = node.getUserObject();
+
+            if (object instanceof Catalog) {
+                Catalog catalog = (Catalog) object;
+                if (!(userObject instanceof Catalog)) {
+                    continue;
+                }
+
+                Catalog currentCatalog = (Catalog) userObject;
+                if (currentCatalog.getName().equals(catalog.getName())) {
+                    return node;
+                }
             }
-        }
 
-    }
+            if (object instanceof IncludeTable) {
+                IncludeTable table = (IncludeTable) object;
+                if (!(userObject instanceof IncludeTable)) {
+                    continue;
+                }
 
+                IncludeTable currentTable = (IncludeTable) userObject;
+                if (currentTable.getPattern().equals(table.getPattern())) {
+                    return node;
+                }
+            }
 
+            if (object instanceof ExcludeTable) {
+                ExcludeTable table = (ExcludeTable) object;
+                if (!(userObject instanceof ExcludeTable)) {
+                    continue;
+                }
 
-    private DbImportTreeNode findNodeInParent(DbImportTreeNode parent, Object object) {
-       for(int i = 0; i<= parent.getChildCount(); i++) {
-           DbImportTreeNode node = (DbImportTreeNode) parent.getChildAt(i);
-           Object userObject = node.getUserObject();
-
-           if (object instanceof Catalog) {
-               Catalog catalog = (Catalog) object;
-               if (!(userObject instanceof Catalog)) {
-                   continue;
-               }
-
-               Catalog currentCatalog = (Catalog) userObject;
-               if(currentCatalog.getName().equals(catalog.getName())  ) {
-                   return node;
-               }
-           }
-
-           if (object instanceof IncludeTable) {
-               IncludeTable table = (IncludeTable) object;
-               if (!(userObject instanceof IncludeTable)) {
-                   continue;
-               }
-
-               IncludeTable currentTable = (IncludeTable) userObject;
-               if (currentTable.getPattern().equals(table.getPattern())) {
-                   return node;
-               }
-           }
-
-           if (object instanceof ExcludeTable) {
-               ExcludeTable table = (ExcludeTable) object;
-               if (!(userObject instanceof ExcludeTable)) {
-                   continue;
-               }
-
-               ExcludeTable currentTable = (ExcludeTable) userObject;
-               if (currentTable.getPattern().equals(table.getPattern())) {
-                   return node;
-               }
-           }
-       }
-
-       return null;
+                ExcludeTable currentTable = (ExcludeTable) userObject;
+                if (currentTable.getPattern().equals(table.getPattern())) {
+                    return node;
+                }
+            }
+        }
+
+        return null;
     }
 
     public DbImportTreeNode findNodeByParentsChain(DbImportTreeNode rootNode, DbImportTreeNode
movedNode, int depth) {
@@ -230,6 +227,11 @@ public class DbImportTree extends JTree {
         for (IncludeTable includeTable : collection) {
             DbImportTreeNode node = !isTransferable ? new DbImportTreeNode(includeTable)
: new TransferableNode(includeTable);
             if (!node.getSimpleNodeName().equals("")) {
+
+                if (includeTable.getIncludeColumns().isEmpty() || includeTable.getExcludeColumns().isEmpty())
{
+                    printParams(Collections.singletonList(new IncludeColumn("Loading...")),
node);
+                }
+
                 printParams(includeTable.getIncludeColumns(), node);
                 printParams(includeTable.getExcludeColumns(), node);
                 parent.add(node);
@@ -284,10 +286,8 @@ public class DbImportTree extends JTree {
                     //reload columns action.
 
                     LoadDbSchemaAction action = Application.getInstance().getActionManager().getAction(LoadDbSchemaAction.class);
-                    action.performAction(new ActionEvent(path, 1000, LOAD_COLUMN_COMMAND
));
+                    action.performAction(null, path);
                 }
-
-
             }
 
             @Override


Mime
View raw message