ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] incubator-ignite git commit: # ignite-32 WIP: First version of schema load utility.
Date Thu, 25 Dec 2014 18:45:24 GMT
# ignite-32 WIP: First version of schema load utility.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/162bed47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/162bed47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/162bed47

Branch: refs/heads/ignite-32
Commit: 162bed47de99b92cfd52ddc262af29ebc00cf29a
Parents: 7c6b87b
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Dec 26 01:44:41 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Dec 26 01:44:41 2014 +0700

----------------------------------------------------------------------
 .../ignite/schema/db/DbMetadataParser.java      |  69 +++--
 .../ignite/schema/pojo/PojoCodeGenerator.java   | 137 ++-------
 .../org/apache/ignite/schema/ui/GridPaneEx.java |  66 ++++-
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 293 +++++++++----------
 4 files changed, 261 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/162bed47/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbMetadataParser.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbMetadataParser.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbMetadataParser.java
index c285238..8d3bb9a 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbMetadataParser.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbMetadataParser.java
@@ -25,38 +25,11 @@ import static org.apache.ignite.schema.util.SchemaUtils.*;
  * Database metadata parser.
  */
 public class DbMetadataParser {
-    /** */
-    private final DatabaseMetaData meta;
-
-    /**
-     * @param conn Database connection.
-     * @throws SQLException If a database access error occurs.
-     */
-    public DbMetadataParser(Connection conn) throws SQLException {
-        meta = conn.getMetaData();
-    }
-
-    /**
-     * @return Schemas description.
-     * @throws SQLException If a database access error occurs.
-     */
-    public ResultSet schemas() throws SQLException {
-        return meta.getSchemas();
-    }
-
-    /**
-     * @return Tables description.
-     * @throws SQLException If a database access error occurs.
-     */
-    public ResultSet tables(String catalog, String schema) throws SQLException {
-        return meta.getTables(catalog, schema, "%", null);
-    }
-
     /**
      * @param type SQL data type.
      * @return Java data type.
      */
-    private Class<?> dataType(int type) {
+    private static Class<?> dataType(int type) {
         switch (type) {
             case BIT:
             case BOOLEAN:
@@ -126,13 +99,15 @@ public class DbMetadataParser {
     /**
      * Parse database metadata.
      *
+     * @param meta Database metadata.
      * @param catalog Catalog name.
      * @param schema Schema name.
      * @param tbl Table name.
      * @return New initialized instance of {@code GridCacheQueryTypeMetadata}.
      * @throws SQLException If parsing failed.
      */
-    public GridCacheQueryTypeMetadata parse(String catalog, String schema, String tbl) throws
SQLException {
+    private static GridCacheQueryTypeMetadata parse(DatabaseMetaData meta, String catalog,
String schema, String tbl)
+        throws SQLException {
         GridCacheQueryTypeMetadata res = new GridCacheQueryTypeMetadata();
 
         res.setSchema(schema);
@@ -206,4 +181,40 @@ public class DbMetadataParser {
 
         return res;
     }
+
+    /**
+     * Parse database metadata.
+     *
+     * @param conn Connection to database.
+     * @return Map with schemes and tables metadata.
+     * @throws SQLException If parsing failed.
+     */
+    public static LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
parse(Connection conn)
+        throws SQLException {
+        DatabaseMetaData meta = conn.getMetaData();
+
+        LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
res = new LinkedHashMap<>();
+
+        try (ResultSet schemas = meta.getSchemas()) {
+            while (schemas.next()) {
+                String schema = schemas.getString(1);
+                String catalog = schemas.getString(2);
+
+                LinkedHashMap<String, GridCacheQueryTypeMetadata> items = new LinkedHashMap<>();
+
+                try (ResultSet tbls = meta.getTables(catalog, schema, "%", null)) {
+                    while (tbls.next()) {
+                        String tbl = tbls.getString(3);
+
+                        items.put(tbl, parse(meta, catalog, schema, tbl));
+                    }
+                }
+
+                if (!items.isEmpty())
+                    res.put(schema, items);
+            }
+        }
+
+        return res;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/162bed47/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
index ab52387..164c012 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
@@ -23,19 +23,10 @@ public class PojoCodeGenerator {
     /** */
     private static final String TAB = "    ";
 
-    /** */
-    private final Collection<String> srcKey = new ArrayList<>(256);
-
-    /** */
-    private final Collection<String> srcVal = new ArrayList<>(256);
-
-    /** */
-    private int indent;
-
     /**
      * @return Current indent constructed from spaces.
      */
-    private String indent() {
+    private static String indent(int indent) {
         switch (indent) {
             case 0: return "";
             case 1: return TAB;
@@ -50,97 +41,50 @@ public class PojoCodeGenerator {
     }
 
     /**
-     * Add line to source code.
-     *
-     * @param src Collection with source code lines.
-     * @param line Line to add.
-     */
-    private void line(Collection<String> src, String line) {
-        src.add(indent() + line);
-    }
-
-    /**
-     * Add empty line.
-     *
-     * @param src Collection with source code lines.
-     */
-    private void empty(Collection<String> src) {
-        src.add("");
-    }
-
-    /**
-     * Generate key declarations.
+     * Generate java class code.
      *
-     * @param src Source code.
      * @param pkg Package name.
      * @param type Type name.
+     * @param descs Type descriptors.
+     * @throws IOException If failed to write generated code into file.
      */
-    private void generateHeader(Collection<String> src, String pkg, String type) {
-        line(src, "package " + pkg + ";");
+    private static void generateCode(String pkg, String type, Collection<GridCacheQueryTypeDescriptor>
descs,
+        File pkgFolder) throws IOException {
+        Collection<String> src = new ArrayList<>(256);
 
-        empty(src);
+        int indent = 0;
 
-        line(src, "public class " + type + " {");
-    }
+        src.add("package " + pkg + ";");
+        src.add("");
+        src.add("public class " + type + " {");
 
-    /**
-     * Generate key declarations.
-     *
-     * @param src Source code.
-     * @param descs Type descriptor.
-     */
-    private void generateFields(Collection<String> src, Collection<GridCacheQueryTypeDescriptor>
descs) {
-        for (GridCacheQueryTypeDescriptor desc : descs) {
-            line(src, "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
+        indent++;
 
-            empty(src);
+        for (GridCacheQueryTypeDescriptor desc : descs) {
+            src.add(TAB + "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
+            src.add("");
         }
-    }
 
-    /**
-     * Generate key declarations.
-     *
-     * @param src Source code.
-     * @param descs Type descriptor.
-     */
-    private void generateMethods(Collection<String> src, Collection<GridCacheQueryTypeDescriptor>
descs) {
         for (GridCacheQueryTypeDescriptor desc : descs) {
             String fldName = desc.getJavaName();
             String fldType = desc.getJavaType().getSimpleName();
 
             String mtdName = capitalize(fldName);
 
-            empty(src);
-
-            line(src, "public " + fldType + " get" + mtdName + "() {");
+            src.add("");
 
-            indent++;
-            line(src, "return " + fldName + ";");
-            indent--;
+            src.add(TAB + "public " + fldType + " get" + mtdName + "() {");
+            src.add(TAB + TAB + "return " + fldName + ";");
+            src.add(TAB + "}");
 
-            line(src, "}");
+            src.add("");
 
-            empty(src);
-
-            line(src, "public void set" + mtdName + "(" + fldType + " " + fldName + ") {");
-
-            indent++;
-            line(src, "this." + fldName + " = " + fldName + ";");
-            indent--;
-
-            line(src, "}");
+            src.add(TAB + "public void set" + mtdName + "(" + fldType + " " + fldName + ")
{");
+            src.add(TAB + TAB + "this." + fldName + " = " + fldName + ";");
+            src.add(TAB + "}");
         }
-    }
 
-    /**
-     * Write source code to file.
-     *
-     * @param src Collection with source code lines.
-     * @param res Target file.
-     * @throws IOException
-     */
-    private void write(Collection<String> src, File res) throws IOException {
-        try (Writer writer = new BufferedWriter(new FileWriter(res))) {
+        try (Writer writer = new BufferedWriter(new FileWriter(new File(pkgFolder, type +
".java")))) {
             for (String line : src)
                 writer.write(line + '\n');
         }
@@ -152,41 +96,20 @@ public class PojoCodeGenerator {
      * @param meta Type metadata.
      * @param outFolder Output folder.
      * @param pkg Types package.
-     * @throws IOException If generation failed.
+     * @throws IOException If failed to write generated code into file.
      */
-    public void generate(GridCacheQueryTypeMetadata meta, String outFolder, String pkg) throws
IOException {
-        srcKey.clear();
-        srcVal.clear();
-
-        File res = new File(outFolder, pkg.replace('.', File.separatorChar));
+    public static void generate(GridCacheQueryTypeMetadata meta, String outFolder, String
pkg) throws IOException {
+        File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
 
-        if (!res.exists() && !res.mkdirs())
+        if (!pkgFolder.exists() && !pkgFolder.mkdirs())
             throw new IOException("Failed to create folders for package: " + pkg);
 
         String keyType = meta.getKeyType();
 
         String valType = meta.getType();
 
-        generateHeader(srcKey, pkg, keyType);
-
-        generateHeader(srcVal, pkg, valType);
-
-        indent++;
-
-        generateFields(srcKey, meta.getKeyDescriptors());
-
-        generateFields(srcVal, meta.getValueDescriptors());
-
-        generateMethods(srcKey, meta.getKeyDescriptors());
-
-        generateMethods(srcVal, meta.getValueDescriptors());
-
-        indent--;
-
-        line(srcKey, "}");
-        line(srcVal, "}");
+        generateCode(pkg, meta.getKeyType(), meta.getKeyDescriptors(), pkgFolder);
 
-        write(srcKey, new File(res, keyType + ".java"));
-        write(srcVal, new File(res, valType + ".java"));
+        generateCode(pkg, meta.getType(), meta.getValueDescriptors(), pkgFolder);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/162bed47/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
index 4aa8769..eb1a8b7 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/GridPaneEx.java
@@ -32,7 +32,7 @@ public class GridPaneEx extends GridPane {
     /**
      * Add percent columns.
      *
-     * @param cols Array of column percentages.
+     * @param cols Columns percentages.
      */
     public void addPercentColumns(double... cols) {
         ObservableList<ColumnConstraints> ccs = getColumnConstraints();
@@ -46,15 +46,67 @@ public class GridPaneEx extends GridPane {
     }
 
     /**
-     * Add percent columns.
+     * Add fixed width column.
      *
-     * @param cols Array of column percentages.
+     * @param width Column width.
      */
-    public void addColumns(double... cols) {
-        ObservableList<ColumnConstraints> ccs = getColumnConstraints();
+    public void addColumn(double width) {
+        getColumnConstraints().add(new ColumnConstraints(width));
+    }
+
+    /**
+     * Add default column.
+     */
+    public void addColumn() {
+        getColumnConstraints().add(new ColumnConstraints());
+    }
+
+    /**
+     * Add column with constraints and horizontal grow priority for the column.
+     *
+     * @param min Column minimum size.
+     * @param pref Column preffered size.
+     * @param max Column max size.
+     * @param hgrow Column horizontal grow priority.
+     */
+    public void addColumnn(double min, double pref, double max, Priority hgrow) {
+        ColumnConstraints cc = new ColumnConstraints(min, pref, max);
+
+        cc.setHgrow(hgrow);
+
+        getColumnConstraints().add(cc);
+    }
+
+    /**
+     * Add fixed height row.
+     *
+     * @param height Row height.
+     */
+    public void addRow(double height) {
+        getRowConstraints().add(new RowConstraints(height));
+    }
+
+    /**
+     * Add default row.
+     */
+    public void addRow() {
+        getRowConstraints().add(new RowConstraints());
+    }
+
+    /**
+     * Add row with constraints and verical grow priority for the row.
+     *
+     * @param min Row minimum size.
+     * @param pref Row preffered size.
+     * @param max Row max size.
+     * @param vgrow Row vertical grow priority.
+     */
+    public void addRow(double min, double pref, double max, Priority vgrow) {
+        RowConstraints rc = new RowConstraints(min, pref, max);
+
+        rc.setVgrow(vgrow);
 
-        for (double col : cols)
-            ccs.add(new ColumnConstraints(col));
+        getRowConstraints().add(rc);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/162bed47/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
index 91ae60b..a3279f9 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
@@ -18,7 +18,6 @@ import javafx.scene.control.cell.*;
 import javafx.scene.layout.*;
 import javafx.scene.text.*;
 import javafx.stage.*;
-import org.apache.ignite.lang.*;
 import org.apache.ignite.schema.db.*;
 import org.apache.ignite.schema.pojo.*;
 import org.apache.ignite.schema.xml.*;
@@ -36,15 +35,13 @@ import static org.apache.ignite.schema.util.SchemaUtils.*;
  * Schema load application.
  */
 public class SchemaLoadApp extends Application {
+    /** TODO: remove later */
     private static final String PATH = "C:/Temp/ignite";
 
     /** */
     private Stage owner;
 
     /** */
-    private int step;
-
-    /** */
     private BorderPane rootPane;
 
     /** */
@@ -69,116 +66,77 @@ public class SchemaLoadApp extends Application {
     private PasswordField pwdTf;
 
     /** */
-    private Collection<IgniteBiTuple<String, Collection<String>>> tables
= Collections.emptyList();
-
-    /** */
     private GridPaneEx connPnl;
 
     /** */
-    private TreeView<String> tree;
+    private CheckBoxTreeItem<String> rootItem;
 
     /** */
-    private CheckBoxTreeItem<String> rootItem;
+    private TextField pkgTf;
 
     /** */
-    private TextField packageTf;
+    private TextField outFolderTf;
 
     /** */
     private GridPaneEx genPnl;
 
+    /** */
+    private LinkedHashMap<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
schemas;
+
     /**
      * Create pane with controls to configure connection to database.
      */
     private Pane connectPane() {
         if (connPnl == null) {
-
             connPnl = new GridPaneEx(DFLT_PADDING);
 
-            connPnl.addPercentColumns(30, 70);
+            connPnl.addColumn();
+            connPnl.addColumnn(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
 
-            //  gp.addLabel("Alias:", 0, 0);
-            //
-            //  ObservableList<String> options = FXCollections.observableArrayList("My
Settings");
-            //  ComboBox<String> aliasCb = new ComboBox<>(options);
-            //  aliasCb.setPromptText("Schema load settings");
-            //  aliasCb.setEditable(true);
-            //  aliasCb.setMaxWidth(Double.MAX_VALUE);
-            //
-            //  gp.add(aliasCb, 1, 0);
-
-            jdbcTf = connPnl.addTextField("JDBC Driver:", 0, 2);
+            jdbcTf = connPnl.addTextField("JDBC Driver:", 0, 0);
             jdbcTf.setText("org.h2.Driver");
 
-            urlTf = connPnl.addTextField("URL:", 0, 3);
+            urlTf = connPnl.addTextField("URL:", 0, 1);
             urlTf.setText("jdbc:h2:mem:test");
 
-            userTf = connPnl.addTextField("User:", 0, 4);
+            userTf = connPnl.addTextField("User:", 0, 2);
             userTf.setText("sa");
 
-            pwdTf = connPnl.addLabeled("Password:", new PasswordField(), 0, 5);
+            pwdTf = connPnl.addLabeled("Password:", new PasswordField(), 0, 3);
         }
 
         return connPnl;
     }
 
-    private Collection<IgniteBiTuple<String, Collection<String>>> tables()
{
-        try {
-            Class.forName(jdbcTf.getText());
-
-            Connection conn = DriverManager.getConnection(urlTf.getText(), userTf.getText(),
pwdTf.getText());
-
-            DatabaseMetaData meta = conn.getMetaData();
-
-            try (ResultSet schemas = meta.getSchemas()) {
-                tables = new ArrayList<>();
-
-                while (schemas.next()) {
-                    String schema = schemas.getString(1);
-
-                    String cat = schemas.getString(2);
-
-                    try (ResultSet tbls = meta.getTables(cat, schema, "%", null)) {
-                        Collection<String> items = new ArrayList<>();
-
-                        while (tbls.next()) {
-                            String tbl = tbls.getString(3);
-
-                            System.out.println(tbl);
-
-                            items.add(tbl);
-                        }
-
-                        if (!items.isEmpty())
-                            tables.add(new IgniteBiTuple<>(schema, items));
-                    }
-                }
-            }
-        }
-        catch (Throwable e) {
-            MessageBox.showErrorDialog(owner, "Failed to get tables list: " + e.getMessage());
-        }
-
-        return tables;
-    }
-
+    /**
+     * Create pane with controls used to configure XML and code generation.
+     *
+     * @return Pane with controls.
+     */
     private Pane generatePane() {
         if (genPnl == null) {
             genPnl = new GridPaneEx(DFLT_PADDING);
 
-            genPnl.addPercentColumns(30, 60, 10);
+            genPnl.addColumn();
+            genPnl.addColumnn(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
+            genPnl.addColumn(30);
+
+            genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
+            genPnl.addRow();
+            genPnl.addRow();
 
             rootItem = new CheckBoxTreeItem<>("Database");
             rootItem.setExpanded(true);
 
-            tree = new TreeView<>(rootItem);
+            TreeView<String> tree = new TreeView<>(rootItem);
             tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
 
-            genPnl.add(tree, 0, 0, 3, 2);
+            genPnl.add(tree, 0, 0, 3, 1);
 
-            packageTf = genPnl.addTextField("Package:", 0, 3);
-            packageTf.setText("org.apache.ignite");
+            pkgTf = genPnl.addTextField("Package:", 0, 2);
+            pkgTf.setText("org.apache.ignite");
 
-            final TextField outFolderTf = genPnl.addTextField("Output folder:", 0, 4);
+            outFolderTf = genPnl.addTextField("Output folder:", 0, 3);
             outFolderTf.setText(PATH);
 
             Button btnFolder = new Button("...");
@@ -189,99 +147,91 @@ public class SchemaLoadApp extends Application {
                     File folder = dc.showDialog(owner);
 
                     if (folder != null)
-                        try {
-                            outFolderTf.setText(folder.getCanonicalPath());
-                        }
-                        catch (IOException ignore) {
-                            // No-op.
-                        }
-
+                        outFolderTf.setText(folder.getAbsolutePath());
                 }
             });
 
-            genPnl.add(btnFolder, 2, 4);
-
-            Button btnGenerate = new Button("Generate");
-            btnGenerate.setOnAction(new EventHandler<ActionEvent>() {
-                @Override public void handle(ActionEvent evt) {
-                    try {
-                        try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:test",
"sa", "")) {
-                            DbMetadataParser parser = new DbMetadataParser(conn);
-
-                            ResultSet schemas = parser.schemas();
-
-                            Collection<GridCacheQueryTypeMetadata> all = new ArrayList<>(30);
-
-                            while (schemas.next()) {
-                                String schema = schemas.getString(1);
-
-                                if (!"PUBLIC".equalsIgnoreCase(schema))
-                                    continue;
-
-                                String cat = schemas.getString(2);
+            genPnl.add(btnFolder, 2, 3);
+        }
 
-                                System.out.println("Schema:" + schema + " Catalog: " + cat);
+        return genPnl;
+    }
 
-                                ResultSet tbls = parser.tables(cat, schema);
+    /**
+     * Fill tree with database metadata.
+     */
+    private void fill() {
+        rootItem.getChildren().clear();
 
-                                File destFolder = new File(outFolderTf.getText());
+        try {
+            Class.forName(jdbcTf.getText());
 
-                                PojoCodeGenerator codeGen = new PojoCodeGenerator();
+            try (Connection conn = DriverManager.getConnection(urlTf.getText(), userTf.getText(),
pwdTf.getText())) {
+                schemas = DbMetadataParser.parse(conn);
 
-                                while (tbls.next()) {
-                                    String tbl = tbls.getString(3);
+                for (Map.Entry<String, LinkedHashMap<String, GridCacheQueryTypeMetadata>>
schema : schemas.entrySet()) {
+                    CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey());
 
-                                    System.out.println("   Table:" + tbl);
+                    rootItem.getChildren().add(schemaItem);
 
-                                    GridCacheQueryTypeMetadata meta = parser.parse(cat, schema,
tbl);
+                    for (String tbl : schema.getValue().keySet())
+                        schemaItem.getChildren().add(new CheckBoxTreeItem<>(tbl));
+                }
+            }
+        }
+        catch (Throwable e) {
+            MessageBox.showErrorDialog(owner, "Failed to get tables list: " + e.getMessage());
+        }
+    }
 
-                                    all.add(meta);
+    /**
+     * Generate XML and POJOs.
+     */
+    private void generate() {
+        try {
+            String outFolder = outFolderTf.getText();
+            String pkg = pkgTf.getText();
 
-                                    XmlTransformer transformer = new XmlTransformer(4);
+            File destFolder = new File(outFolder);
 
-                                    Result res = new StreamResult(new File(destFolder, tbl
+ ".xml"));
+            List<GridCacheQueryTypeMetadata> all = new ArrayList<>();
 
-                                    transformer.transform(packageTf.getText(), meta, res);
+            for (TreeItem<String> schemeItem : rootItem.getChildren()) {
+                if (((CheckBoxTreeItem)schemeItem).isSelected()) {
+                    for (TreeItem<String> tblItem : schemeItem.getChildren()) {
+                        if (((CheckBoxTreeItem)tblItem).isSelected()) {
+                            GridCacheQueryTypeMetadata meta = schemas.get(schemeItem.getValue())
+                                .get(tblItem.getValue());
 
-                                    codeGen.generate(meta, outFolderTf.getText(), packageTf.getText());
-                                }
-                            }
+                            all.add(meta);
 
                             XmlTransformer transformer = new XmlTransformer(4);
 
-                            Result res = new StreamResult(new File(outFolderTf.getText(),
"all.xml"));
+                            Result res = new StreamResult(new File(destFolder, meta.getType()
+ ".xml"));
 
-                            transformer.transform(packageTf.getText(), all, res);
+                            transformer.transform(pkg, meta, res);
 
-                            conn.close();
+                            PojoCodeGenerator.generate(meta, outFolder, pkg);
                         }
                     }
-                    catch (Throwable e) {
-                        MessageBox.showErrorDialog(owner, "Generation failed: " + e.getMessage());
-                    }
-
-                    System.exit(0);
                 }
-            });
-
-            genPnl.add(btnGenerate, 0, 5);
-        }
+            }
 
-        return genPnl;
-    }
+            if (all.isEmpty())
+                MessageBox.showInformationDialog(owner, "Warning", "Nothing selected");
+            else {
+                XmlTransformer transformer = new XmlTransformer(4);
 
-    private void fill(Collection<IgniteBiTuple<String, Collection<String>>>
tables) {
-        rootItem.getChildren().clear();
+                Result res = new StreamResult(new File(outFolder, "all.xml"));
 
-        for (IgniteBiTuple<String, Collection<String>> schema : tables) {
-            CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey());
-            rootItem.getChildren().add(schemaItem);
+                transformer.transform(pkg, all, res);
 
-            for (String table : schema.getValue())
-                schemaItem.getChildren().add(new CheckBoxTreeItem<>(table));
+                MessageBox.showInformationDialog(owner, "Information", "Generation complete!");
+            }
+        }
+        catch (Throwable e) {
+            MessageBox.showErrorDialog(owner, "Generation failed: " + e.getMessage());
         }
-
-        tree.setRoot(rootItem);
     }
 
     /**
@@ -305,14 +255,14 @@ public class SchemaLoadApp extends Application {
         prevBtn = new Button("Prev");
         prevBtn.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent evt) {
-                go(false);
+                prev();
             }
         });
 
         nextBtn = new Button("Next");
         nextBtn.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent evt) {
-                go(true);
+                next();
             }
         });
 
@@ -324,19 +274,33 @@ public class SchemaLoadApp extends Application {
     }
 
     /**
-     * Go to selected page.
-     *
-     * @param next If {@code true} then go to next page otherwise go to previous page.
+     * Go to &quot;Connect To Database&quot; panel.
      */
-    private void go(boolean next) {
-        Pane pane = next ? generatePane() : connectPane();
+    private void prev() {
+        titleLb.setText("Connect To Database");
 
-        rootPane.setCenter(pane);
+        rootPane.setCenter(connectPane());
+
+        prevBtn.setDisable(true);
+        nextBtn.setText("Next");
+    }
+
+    /**
+     * Go to &quot;Generate XML And POJOs&quot; panel or generate XML and POJOs.
+     */
+    private void next() {
+        if (rootPane.getCenter() == connPnl) {
+            titleLb.setText("Generate XML And POJOs");
 
-        titleLb.setText(next ? "Generate XML And POJOs" : "Connect To Database");
+            rootPane.setCenter(generatePane());
 
-        prevBtn.setDisable(!next);
-        nextBtn.setDisable(next);
+            prevBtn.setDisable(false);
+            nextBtn.setText("Generate");
+
+            fill();
+        }
+        else
+            generate();
     }
 
     /** {@inheritDoc} */
@@ -354,16 +318,21 @@ public class SchemaLoadApp extends Application {
         rootPane.setCenter(connectPane());
         rootPane.setBottom(createButtonsPane());
 
-        primaryStage.setMinWidth(400);
-        primaryStage.setMinHeight(500);
+        primaryStage.setScene(new Scene(rootPane));
 
-        primaryStage.setMaxWidth(700);
-        primaryStage.setMaxHeight(700);
+        int w = 400;
+        primaryStage.setWidth(w);
+        primaryStage.setMinWidth(w);
+        primaryStage.setMaxWidth(2 * w);
 
-        primaryStage.setScene(new Scene(rootPane, 400, 500));
-        primaryStage.show();
+        int h = 350;
+        primaryStage.setHeight(h);
+        primaryStage.setMinHeight(h);
+        primaryStage.setMaxHeight(2 * h);
 
-        go(false);
+        prev();
+
+        primaryStage.show();
     }
 
     /**
@@ -375,8 +344,10 @@ public class SchemaLoadApp extends Application {
 
             try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
"sa", "")) {
                 try (Statement stmt = conn.createStatement()) {
-                    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Organization (id integer
primary key, name varchar(50), city varchar(50))");
-                    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Person (id integer primary
key, org_id integer, name varchar(50))");
+                    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Organization(" +
+                        "id integer primary key, name varchar(50), city varchar(50))");
+                    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Person(" +
+                        "id integer primary key, org_id integer, name varchar(50))");
 
                     stmt.executeUpdate("CREATE INDEX IF NOT EXISTS Org_Name_IDX On Organization
(name)");
                     stmt.executeUpdate("CREATE INDEX IF NOT EXISTS Org_Name_City_IDX On Organization
(name, city)");
@@ -386,11 +357,11 @@ public class SchemaLoadApp extends Application {
                     conn.commit();
 
                     try {
-                        stmt.executeUpdate("INSERT INTO Organization(id, name, city) VALUES
(1, 'GridGain', 'Foster')");
-                        stmt.executeUpdate("INSERT INTO Organization(id, name, city) VALUES
(2, 'Apache'), 'New York'");
+                        stmt.executeUpdate("INSERT INTO Organization(id, name, city) VALUES
(1, 'Test1', 'Test2')");
+                        stmt.executeUpdate("INSERT INTO Organization(id, name, city) VALUES
(2, 'Test3'), 'Test4'");
 
-                        stmt.executeUpdate("INSERT INTO Person(id, org_id, name) VALUES (1,
1, 'Kuznetsov')");
-                        stmt.executeUpdate("INSERT INTO Person(id, org_id, name) VALUES (2,
2, 'Boudnik')");
+                        stmt.executeUpdate("INSERT INTO Person(id, org_id, name) VALUES (1,
1, 'Test5')");
+                        stmt.executeUpdate("INSERT INTO Person(id, org_id, name) VALUES (2,
2, 'Test6')");
 
                         conn.commit();
                     }


Mime
View raw message