This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 6a4c15a96cd8e84e9b18986a54c5fdc6431284fe
Author: Nikita Timofeev <[email protected]>
AuthorDate: Wed Sep 25 13:22:52 2019 +0300

    Sort tables and columns in DBImport DB schema view
---
 .../dbsync/reverse/dbimport/FilterContainer.java   | 37 +++++++++++-----------
 .../dbsync/reverse/dbimport/IncludeTable.java      | 15 +++++----
 .../reverse/dbimport/ReverseEngineering.java       |  9 +++---
 .../dbsync/reverse/dbimport/SchemaContainer.java   |  8 ++---
 .../editor/dbimport/DatabaseSchemaLoader.java      | 20 ++++++++++++
 5 files changed, 55 insertions(+), 34 deletions(-)

diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java
index b897efc..becd72b 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java
@@ -21,9 +21,8 @@ package org.apache.cayenne.dbsync.reverse.dbimport;
 
 import org.apache.cayenne.util.Util;
 
-import java.util.Collection;
-import java.util.LinkedList;
-
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @since 4.0.
@@ -32,19 +31,19 @@ public abstract class FilterContainer {
 
     private String name;
 
-    private final Collection<IncludeTable> includeTableCollection = new 
LinkedList<>();
+    private final List<IncludeTable> includeTableCollection = new 
ArrayList<>();
 
-    private final Collection<ExcludeTable> excludeTableCollection = new 
LinkedList<>();
+    private final List<ExcludeTable> excludeTableCollection = new 
ArrayList<>();
 
-    private final Collection<IncludeColumn> includeColumnCollection = new 
LinkedList<>();
+    private final List<IncludeColumn> includeColumnCollection = new 
ArrayList<>();
 
-    private final Collection<ExcludeColumn> excludeColumnCollection = new 
LinkedList<>();
+    private final List<ExcludeColumn> excludeColumnCollection = new 
ArrayList<>();
 
-    private final Collection<IncludeProcedure> includeProcedureCollection = 
new LinkedList<>();
+    private final List<IncludeProcedure> includeProcedureCollection = new 
ArrayList<>();
 
-    private final Collection<ExcludeProcedure> excludeProcedureCollection = 
new LinkedList<>();
+    private final List<ExcludeProcedure> excludeProcedureCollection = new 
ArrayList<>();
 
-    private final Collection<ExcludeRelationship> 
excludeRelationshipCollection = new LinkedList<>();
+    private final List<ExcludeRelationship> excludeRelationshipCollection = 
new ArrayList<>();
 
     public FilterContainer() {
     }
@@ -71,34 +70,34 @@ public abstract class FilterContainer {
         }
     }
 
-    public Collection<IncludeTable> getIncludeTables() {
+    public List<IncludeTable> getIncludeTables() {
         return includeTableCollection;
     }
 
-    public Collection<ExcludeTable> getExcludeTables() {
+    public List<ExcludeTable> getExcludeTables() {
         return excludeTableCollection;
     }
 
-    public Collection<IncludeColumn> getIncludeColumns() {
+    public List<IncludeColumn> getIncludeColumns() {
         return includeColumnCollection;
     }
 
-    public Collection<ExcludeColumn> getExcludeColumns() {
+    public List<ExcludeColumn> getExcludeColumns() {
         return excludeColumnCollection;
     }
 
-    public Collection<IncludeProcedure> getIncludeProcedures() {
+    public List<IncludeProcedure> getIncludeProcedures() {
         return includeProcedureCollection;
     }
 
-    public Collection<ExcludeProcedure> getExcludeProcedures() {
+    public List<ExcludeProcedure> getExcludeProcedures() {
         return excludeProcedureCollection;
     }
 
     /**
      * @since 4.1
      */
-    public Collection<ExcludeRelationship> getExcludeRelationship() {
+    public List<ExcludeRelationship> getExcludeRelationship() {
         return excludeRelationshipCollection;
     }
 
@@ -193,7 +192,7 @@ public abstract class FilterContainer {
             && includeProcedureCollection.isEmpty() && 
excludeProcedureCollection.isEmpty() && excludeRelationshipCollection.isEmpty();
     }
 
-    static boolean isBlank(Collection<?> collection) {
+    static boolean isBlank(List<?> collection) {
         return collection == null || collection.isEmpty();
     }
 
@@ -214,7 +213,7 @@ public abstract class FilterContainer {
         return res;
     }
 
-    protected void appendCollection(StringBuilder res, String prefix, 
Collection<? extends PatternParam> collection) {
+    protected void appendCollection(StringBuilder res, String prefix, List<? 
extends PatternParam> collection) {
         if (!isBlank(collection)) {
             for (PatternParam item : collection) {
                 item.toString(res, prefix);
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java
index 94706c6..a1f0b4a 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java
@@ -23,19 +23,20 @@ import 
org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.util.XMLEncoder;
 import org.apache.cayenne.util.XMLSerializable;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
+import java.util.List;
 
 /**
  * @since 4.0.
  */
 public class IncludeTable extends PatternParam implements XMLSerializable {
 
-    private final Collection<IncludeColumn> includeColumns = new 
LinkedList<>();
+    private final List<IncludeColumn> includeColumns = new ArrayList<>();
 
-    private final Collection<ExcludeColumn> excludeColumns = new 
LinkedList<>();
+    private final List<ExcludeColumn> excludeColumns = new ArrayList<>();
 
-    private final Collection<ExcludeRelationship> excludeRelationship = new 
LinkedList<>();
+    private final List<ExcludeRelationship> excludeRelationship = new 
ArrayList<>();
 
     public IncludeTable() {
     }
@@ -54,7 +55,7 @@ public class IncludeTable extends PatternParam implements 
XMLSerializable {
         }
     }
 
-    public Collection<IncludeColumn> getIncludeColumns() {
+    public List<IncludeColumn> getIncludeColumns() {
         return includeColumns;
     }
 
@@ -62,7 +63,7 @@ public class IncludeTable extends PatternParam implements 
XMLSerializable {
         this.includeColumns.addAll(includeColumns);
     }
 
-    public Collection<ExcludeColumn> getExcludeColumns() {
+    public List<ExcludeColumn> getExcludeColumns() {
         return excludeColumns;
     }
 
@@ -73,7 +74,7 @@ public class IncludeTable extends PatternParam implements 
XMLSerializable {
     /**
      * @since 4.1
      */
-    public Collection<ExcludeRelationship> getExcludeRelationship() {
+    public List<ExcludeRelationship> getExcludeRelationship() {
         return excludeRelationship;
     }
 
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ReverseEngineering.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ReverseEngineering.java
index b9059f3..e1eb23c 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ReverseEngineering.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ReverseEngineering.java
@@ -20,9 +20,10 @@
 package org.apache.cayenne.dbsync.reverse.dbimport;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.LinkedList;
+import java.util.List;
 
 import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.dbsync.xml.DbImportExtension;
@@ -118,9 +119,9 @@ public class ReverseEngineering extends SchemaContainer 
implements Serializable,
      * <li> "SYNONYM"
      * </ul>
      */
-    private final Collection<String> tableTypes = new LinkedList<>();
+    private final List<String> tableTypes = new ArrayList<>();
 
-    private final Collection<Catalog> catalogCollection = new LinkedList<>();
+    private final List<Catalog> catalogCollection = new ArrayList<>();
 
     public ReverseEngineering() {
     }
@@ -160,7 +161,7 @@ public class ReverseEngineering extends SchemaContainer 
implements Serializable,
         this.skipPrimaryKeyLoading = skipPrimaryKeyLoading;
     }
 
-    public Collection<Catalog> getCatalogs() {
+    public List<Catalog> getCatalogs() {
         return catalogCollection;
     }
 
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/SchemaContainer.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/SchemaContainer.java
index 05b8388..6c90767 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/SchemaContainer.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/SchemaContainer.java
@@ -19,17 +19,17 @@
 
 package org.apache.cayenne.dbsync.reverse.dbimport;
 
-import java.util.Collection;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @since 4.0
  */
 public abstract class SchemaContainer extends FilterContainer {
 
-    private final Collection<Schema> schemaCollection = new LinkedList<>();
+    private final List<Schema> schemaCollection = new ArrayList<>();
 
-    public Collection<Schema> getSchemas() {
+    public List<Schema> getSchemas() {
         return schemaCollection;
     }
 
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 91aa219..31d7aa7 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
@@ -25,6 +25,7 @@ import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.List;
 
 import org.apache.cayenne.dba.DbAdapter;
@@ -33,6 +34,7 @@ import 
org.apache.cayenne.dbsync.reverse.dbimport.FilterContainer;
 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.PatternParam;
 import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
 import org.apache.cayenne.dbsync.reverse.dbimport.Schema;
 import org.apache.cayenne.modeler.ClassLoadingService;
@@ -55,9 +57,26 @@ public class DatabaseSchemaLoader {
         try (Connection connection = 
connectionInfo.makeDataSource(loadingService).getConnection()) {
             processCatalogs(connection, dbAdapter);
         }
+
+        sort();
         return databaseReverseEngineering;
     }
 
+    private void sort() {
+        databaseReverseEngineering.getCatalogs().forEach(catalog -> {
+            catalog.getSchemas().forEach(this::sort);
+            sort(catalog);
+        });
+        sort(databaseReverseEngineering);
+    }
+
+    private void sort(FilterContainer filterContainer) {
+        Comparator<PatternParam> comparator = 
Comparator.comparing(PatternParam::getPattern);
+        filterContainer.getIncludeTables().sort(comparator);
+        filterContainer.getIncludeTables().forEach(table -> 
table.getIncludeColumns().sort(comparator));
+        filterContainer.getIncludeProcedures().sort(comparator);
+    }
+
     private void processCatalogs(Connection connection, DbAdapter dbAdapter) 
throws SQLException {
         try (ResultSet rsCatalog = connection.getMetaData().getCatalogs()) {
             boolean hasCatalogs = false;
@@ -168,6 +187,7 @@ public class DatabaseSchemaLoader {
                 }
             }
         }
+        sort();
         return databaseReverseEngineering;
     }
 

Reply via email to