ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # ignite-32 WIP: Working on UI.
Date Wed, 24 Dec 2014 13:54:57 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 1dfc3fbd9 -> 15d4c0512


# ignite-32 WIP: Working on UI.


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

Branch: refs/heads/ignite-32
Commit: 15d4c0512488809f8cab591ff425e2021bba4a40
Parents: 1dfc3fb
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed Dec 24 20:54:55 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed Dec 24 20:54:55 2014 +0700

----------------------------------------------------------------------
 .../apache/ignite/schema/db/DbConnection.java   | 109 --------
 .../ignite/schema/db/DbMetadataParser.java      |  38 +--
 .../org/apache/ignite/schema/ui/GridPaneEx.java |   2 +-
 .../org/apache/ignite/schema/ui/MessageBox.java |  21 +-
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 258 +++++++++++++++----
 .../apache/ignite/schema/util/SchemaUtils.java  |   6 +-
 6 files changed, 236 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbConnection.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbConnection.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbConnection.java
deleted file mode 100644
index d62f98d..0000000
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/db/DbConnection.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* @java.file.header */
-
-/*  _________        _____ __________________        _____
- *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
- *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
- *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
- *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
- */
-
-package org.apache.ignite.schema.db;
-
-import org.apache.ignite.schema.pojo.*;
-import org.apache.ignite.schema.xml.*;
-import org.gridgain.grid.cache.query.*;
-
-import javax.xml.transform.*;
-import javax.xml.transform.stream.*;
-import java.io.*;
-import java.sql.*;
-import java.util.*;
-
-/**
- * TODO: Add class description.
- */
-public class DbConnection {
-    /**
-     * TODO Temporary test.
-     *
-     * @param args App args...
-     */
-    public static void main(String[] args) {
-        try {
-            Class.forName("org.h2.Driver");
-            Connection conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "");
-
-            Statement stmt = conn.createStatement();
-
-            stmt.executeUpdate("CREATE TABLE Organization (id integer PRIMARY KEY, name varchar(50),
city varchar(50))");
-            stmt.executeUpdate("CREATE TABLE Person (id integer PRIMARY KEY, org_id integer,
name varchar(50))");
-
-            stmt.executeUpdate("CREATE INDEX Org_Name_IDX On Organization (name)");
-            stmt.executeUpdate("CREATE INDEX Org_Name_City_IDX On Organization (name, city)");
-            stmt.executeUpdate("CREATE INDEX Person_Name_IDX1 On Person (name)");
-            stmt.executeUpdate("CREATE INDEX Person_Name_IDX2 On Person (name desc)");
-
-            conn.commit();
-
-            stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (1, 'GridGain')"
);
-            stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (2, 'Apache')"
);
-
-            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')");
-
-            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);
-
-                System.out.println("Schema:" + schema + " Catalog: " + cat);
-
-                ResultSet tbls = parser.tables(cat, schema);
-
-                File destFolder = new File("C:/temp/ignite");
-
-                PojoCodeGenerator codeGen = new PojoCodeGenerator();
-
-                while(tbls.next()) {
-                    String tbl = tbls.getString(3);
-
-                    System.out.println("   Table:" + tbl);
-
-                    GridCacheQueryTypeMetadata meta = parser.parse(cat, schema, tbl);
-
-                    all.add(meta);
-
-                    XmlTransformer transformer = new XmlTransformer(4);
-
-                    Result res = new StreamResult(new File(destFolder, tbl + ".xml"));
-
-                    transformer.transform(meta, res);
-
-                    codeGen.generate(meta, "C:/temp/ignite", "org.apache.ignite");
-                }
-            }
-
-            XmlTransformer transformer = new XmlTransformer(4);
-
-            Result res = new StreamResult(new File("C:/temp/ignite/all.xml"));
-
-            transformer.transform(all, res);
-
-            conn.close();
-
-           System.out.println("Done!");
-        }
-        catch(Throwable ex) {
-            ex.printStackTrace();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/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 c27d200..c285238 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
@@ -175,33 +175,33 @@ public class DbMetadataParser {
             }
         }
 
-        ResultSet idxs = meta.getIndexInfo(catalog, schema, tbl, false, true);
+        try (ResultSet idxs = meta.getIndexInfo(catalog, schema, tbl, false, true)) {
+            while (idxs.next()) {
+                String idx = toJavaFieldName(idxs.getString(6));
+                String col = toJavaFieldName(idxs.getString(9));
+                String askOrDesc = idxs.getString(10);
 
-        while (idxs.next()) {
-            String idx = toJavaFieldName(idxs.getString(6));
-            String col = toJavaFieldName(idxs.getString(9));
-            String askOrDesc = idxs.getString(10);
+                LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>
idxCols = groups.get(idx);
 
-            LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> idxCols
= groups.get(idx);
+                if (idxCols == null) {
+                    idxCols = new LinkedHashMap<>();
 
-            if (idxCols == null) {
-                idxCols = new LinkedHashMap<>();
+                    groups.put(idx, idxCols);
+                }
 
-                groups.put(idx, idxCols);
-            }
+                Class<?> dataType = qryFields.get(col);
 
-            Class<?> dataType = qryFields.get(col);
+                Boolean desc = askOrDesc != null ? "D".equals(askOrDesc) : null;
 
-            Boolean desc = askOrDesc != null ? "D".equals(askOrDesc) : null;
+                if (desc != null) {
+                    if (desc)
+                        descFields.put(col, dataType);
+                    else
+                        ascFields.put(col, dataType);
+                }
 
-            if (desc != null) {
-                if (desc)
-                    descFields.put(col, dataType);
-                else
-                    ascFields.put(col, dataType);
+                idxCols.put(col, new IgniteBiTuple<Class<?>, Boolean>(dataType,
desc));
             }
-
-            idxCols.put(col, new IgniteBiTuple<Class<?>, Boolean>(dataType, desc));
         }
 
         return res;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/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 7b0da41..aa400d7 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
@@ -22,7 +22,7 @@ public class GridPaneEx extends GridPane {
      * @param padding Pane padding.
      */
     public GridPaneEx(Insets padding) {
-        setAlignment(Pos.CENTER);
+        setAlignment(Pos.TOP_LEFT);
         setPadding(padding);
         setHgap(10);
         setVgap(10);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
index 5d58e22..501fbd2 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java
@@ -24,7 +24,7 @@ import static org.apache.ignite.schema.util.SchemaUtils.*;
  * TODO: Add class description.
  */
 public class MessageBox {
-
+    /** */
     public enum Option {NO, YES, CANCEL}
 
     private static Option result = Option.CANCEL;
@@ -94,7 +94,7 @@ public class MessageBox {
         return result;
     }
 
-    private static void showDialog(Stage owner, String title, String message, String iconFile)
{
+    private static void showDialog(Stage owner, String title, String msg, String iconFile)
{
         VBox vb = newVBox(10);
         Scene scene = new Scene(vb);
 
@@ -110,19 +110,20 @@ public class MessageBox {
 
         BorderPane bp = new BorderPane();
         bp.setCenter(okButton);
-        HBox msg = new HBox();
-        msg.setSpacing(5);
-        msg.getChildren().addAll(icon, new Message(message));
-        vb.getChildren().addAll(msg, bp);
+
+        HBox hb = new HBox();
+        hb.setSpacing(5);
+        hb.getChildren().addAll(icon, new Message(msg));
+        vb.getChildren().addAll(hb, bp);
 
         dial.showDialog();
     }
 
-    public static void showInformationDialog(Stage owner, String title, String message) {
-        showDialog(owner, title, message, "information");
+    public static void showInformationDialog(Stage owner, String title, String msg) {
+        showDialog(owner, title, msg, "information");
     }
 
-    public static void showErrorDialog(Stage owner, String title, String message) {
-        showDialog(owner, title, message, "error");
+    public static void showErrorDialog(Stage owner, String msg) {
+        showDialog(owner, "Error", msg, "error");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/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 7d429e8..7a4fcfa 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,8 +18,14 @@ 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.*;
+import org.gridgain.grid.cache.query.*;
 
+import javax.xml.transform.*;
+import javax.xml.transform.stream.*;
 import java.io.*;
 import java.sql.*;
 import java.util.*;
@@ -30,11 +36,12 @@ import static org.apache.ignite.schema.util.SchemaUtils.*;
  * Schema load application.
  */
 public class SchemaLoadApp extends Application {
+    private static final String PATH = "C:/Temp/ignite";
     /** */
     private int step;
 
     /** */
-    private BorderPane contentPane;
+    private BorderPane rootPane;
 
     /** */
     private Label titleLb;
@@ -46,7 +53,20 @@ public class SchemaLoadApp extends Application {
     private Button nextBtn;
 
     /** */
-    private List<WizardPage> pages;
+    private WizardPage[] pages;
+
+    /** */
+    private WizardPage0 page0;
+
+    /** */
+    private WizardPage1 page1;
+
+    /** */
+    private WizardPage2 page2;
+
+    /** */
+    private WizardPage3 page3;
+
 
     /**
      * Base class for wizard pages.
@@ -98,7 +118,7 @@ public class SchemaLoadApp extends Application {
     /**
      * Wizard page for selecting DB settings.
      */
-    private static class DbChooserPage extends WizardPage {
+    private static class WizardPage0 extends WizardPage {
         private TextField jdbcTf;
 
         private TextField urlTf;
@@ -107,10 +127,12 @@ public class SchemaLoadApp extends Application {
 
         private PasswordField pwdTf;
 
+        private Collection<IgniteBiTuple<String, Collection<String>>> tables
= Collections.emptyList();
+
         /**
          * Create page.
          */
-        private DbChooserPage(Stage owner) {
+        private WizardPage0(Stage owner) {
             super(owner, "Choose Database");
         }
 
@@ -143,16 +165,67 @@ public class SchemaLoadApp extends Application {
 
             return gp;
         }
+
+        private boolean changed() {
+            return true;
+        }
+
+
+        public Collection<IgniteBiTuple<String, Collection<String>>> tables()
{
+            if (changed()) {
+                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;
+        }
     }
 
     /**
      * Wizard page for selecting tables to import.
      */
-    private static class SelectTablesPage extends WizardPage {
+    private static class WizardPage1 extends WizardPage {
+        private TreeView<String> tree;
+
+        private CheckBoxTreeItem<String> rootItem;
+
         /**
          * Create page.
          */
-        private SelectTablesPage(Stage owner) {
+        private WizardPage1(Stage owner) {
             super(owner, "Select tables");
         }
 
@@ -160,32 +233,42 @@ public class SchemaLoadApp extends Application {
         @Override protected Pane createContent() {
             GridPaneEx gp = new GridPaneEx(DFLT_PADDING);
 
-            CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>("Scheme1");
+            rootItem = new CheckBoxTreeItem<>("Database");
             rootItem.setExpanded(true);
 
-            TreeView<String> tree = new TreeView<>(rootItem);
-
+            tree = new TreeView<>(rootItem);
             tree.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
-            for (int i = 0; i < 100; i++) {
-                final CheckBoxTreeItem<String> checkBoxTreeItem =
-                    new CheckBoxTreeItem<>("Table" + (i+1));
-                rootItem.getChildren().add(checkBoxTreeItem);
-            }
 
             gp.add(tree, 0, 0);
 
             return gp;
         }
+
+        public void fill(Collection<IgniteBiTuple<String, Collection<String>>>
tables) {
+            rootItem.getChildren().clear();
+
+            for (IgniteBiTuple<String, Collection<String>> schema : tables) {
+                CheckBoxTreeItem<String> schemaItem = new CheckBoxTreeItem<>(schema.getKey());
+                rootItem.getChildren().add(schemaItem);
+
+                for(String table : schema.getValue())
+                    schemaItem.getChildren().add(new CheckBoxTreeItem<>(table));
+            }
+
+            tree.setRoot(rootItem);
+        }
     }
 
     /**
      * Wizard page for configure generation settings.
      */
-    private static class ImportDbSchemaPage extends WizardPage {
+    private static class WizardPage2 extends WizardPage {
+        private TextField packageTf;
+
         /**
          * Create page.
          */
-        private ImportDbSchemaPage(Stage owner) {
+        private WizardPage2(Stage owner) {
             super(owner, "Import Database Schema");
         }
 
@@ -195,20 +278,25 @@ public class SchemaLoadApp extends Application {
 
             gp.addPercentColumns(30, 70);
 
-            gp.addTextField("Package:", 0, 0);
+            packageTf = gp.addTextField("Package:", 0, 0);
+            packageTf.setText("org.apache.ignite");
 
             return gp;
         }
+
+        public String getPackage() {
+            return packageTf.getText();
+        }
     }
 
     /**
      * Final wizard page with selecting output folder.
      */
-    private static class GeneratePage extends WizardPage {
+    private static class WizardPage3 extends WizardPage {
         /**
          * Create page.
          */
-        private GeneratePage(Stage owner) {
+        private WizardPage3(Stage owner) {
             super(owner, "Generate");
         }
 
@@ -217,6 +305,7 @@ public class SchemaLoadApp extends Application {
             GridPaneEx gp = new GridPaneEx(DFLT_PADDING);
 
             final TextField outFolderTf = gp.addTextField("Output folder:", 0, 0);
+            outFolderTf.setText(PATH);
 
             Button btnFolder = new Button("...");
             btnFolder.setOnAction(new EventHandler<ActionEvent>() {
@@ -241,7 +330,61 @@ public class SchemaLoadApp extends Application {
             Button btnGenerate = new Button("Generate");
             btnGenerate.setOnAction(new EventHandler<ActionEvent>() {
                 @Override public void handle(ActionEvent evt) {
-                    DbConnection.main(null);
+                    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);
+
+                                System.out.println("Schema:" + schema + " Catalog: " + cat);
+
+                                ResultSet tbls = parser.tables(cat, schema);
+
+                                File destFolder = new File(outFolderTf.getText());
+
+                                PojoCodeGenerator codeGen = new PojoCodeGenerator();
+
+                                while(tbls.next()) {
+                                    String tbl = tbls.getString(3);
+
+                                    System.out.println("   Table:" + tbl);
+
+                                    GridCacheQueryTypeMetadata meta = parser.parse(cat, schema,
tbl);
+
+                                    all.add(meta);
+
+                                    XmlTransformer transformer = new XmlTransformer(4);
+
+                                    Result res = new StreamResult(new File(destFolder, tbl
+ ".xml"));
+
+                                    transformer.transform(meta, res);
+
+                                    codeGen.generate(meta, outFolderTf.getText(), "org.apache.ignite");
+                                }
+                            }
+
+                            XmlTransformer transformer = new XmlTransformer(4);
+
+                            Result res = new StreamResult(new File(outFolderTf.getText(),
"all.xml"));
+
+                            transformer.transform(all, res);
+
+                            conn.close();
+                        }
+                    }
+                    catch(Throwable e) {
+                        MessageBox.showErrorDialog(owner, "Generation failed: " + e.getMessage());
+                    }
 
                     System.exit(0);
                 }
@@ -299,43 +442,42 @@ public class SchemaLoadApp extends Application {
      */
     private void go(boolean next) {
         if (next) {
-            if (step < pages.size())
+            if (step < pages.length)
                 step++;
         } else if (step > 0)
             step--;
 
-        WizardPage page = pages.get(step);
+        WizardPage page = pages[step];
 
-        contentPane.setCenter(page.createContent());
+        rootPane.setCenter(page.createContent());
 
         titleLb.setText(page.title);
 
         prevBtn.setDisable(step == 0);
-        nextBtn.setDisable(step == pages.size() - 1);
+        nextBtn.setDisable(step == pages.length - 1);
+
+        if (step == 1)
+            page1.fill(page0.tables());
     }
 
     /** {@inheritDoc} */
     @Override public void start(Stage primaryStage) {
+        primaryStage.setTitle("Schema Load");
+
         primaryStage.getIcons()
             .addAll(image("branch", 16), image("branch", 32), image("branch", 48), image("branch",
128));
 
-        pages = new ArrayList<>();
-
-        pages.add(new DbChooserPage(primaryStage));
-        pages.add(new SelectTablesPage(primaryStage));
-        pages.add(new ImportDbSchemaPage(primaryStage));
-        pages.add(new GeneratePage(primaryStage));
-
-        primaryStage.setTitle("Schema Load");
+        page0 = new WizardPage0(primaryStage);
+        page1 = new WizardPage1(primaryStage);
+        page2 = new WizardPage2(primaryStage);
+        page3 = new WizardPage3(primaryStage);
 
-        contentPane = new BorderPane();
-        contentPane.setStyle("-fx-border-color: red;");
+        pages = new WizardPage[]{page0, page1, page2, page3};
 
-        BorderPane layerPnl = new BorderPane();
+        rootPane = new BorderPane();
 
-        layerPnl.setTop(createHeaderPane());
-        layerPnl.setCenter(contentPane);
-        layerPnl.setBottom(createButtonsPane());
+        rootPane.setTop(createHeaderPane());
+        rootPane.setBottom(createButtonsPane());
 
         primaryStage.setMinWidth(300);
         primaryStage.setMinHeight(310);
@@ -343,7 +485,7 @@ public class SchemaLoadApp extends Application {
         primaryStage.setMaxWidth(600);
         primaryStage.setMaxHeight(500);
 
-        primaryStage.setScene(new Scene(layerPnl, 300, 310));
+        primaryStage.setScene(new Scene(rootPane, 300, 310));
         primaryStage.show();
 
         go(false);
@@ -355,29 +497,33 @@ public class SchemaLoadApp extends Application {
     private static void sampleDb() {
         try {
             Class.forName("org.h2.Driver");
-            Connection conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "");
 
-            Statement stmt = conn.createStatement();
+            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 Organization (id integer, name varchar(50),
city varchar(50))");
-            stmt.executeUpdate("CREATE TABLE Person (id integer, 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)");
+                    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS Person_Name_IDX1 On Person
(name)");
+                    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS Person_Name_IDX2 On Person
(name desc)");
 
-            stmt.executeUpdate("CREATE INDEX Org_Name_IDX On Organization (name)");
-            stmt.executeUpdate("CREATE INDEX Org_Name_City_IDX On Organization (name, city)");
-            stmt.executeUpdate("CREATE INDEX Person_Name_IDX1 On Person (name)");
-            stmt.executeUpdate("CREATE INDEX Person_Name_IDX2 On Person (name desc)");
+                    conn.commit();
 
-            conn.commit();
+                    try {
+                        stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (1,
'GridGain')");
+                        stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (2,
'Apache')");
 
-            stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (1, 'GridGain')");
-            stmt.executeUpdate("INSERT INTO Organization(id, name) VALUES (2, 'Apache')");
+                        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, 'Kuznetsov')");
-            stmt.executeUpdate("INSERT INTO Person(id, org_id, name) VALUES (2, 2, 'Boudnik')");
-
-            conn.commit();
-
-            conn.close();
+                        conn.commit();
+                    }
+                    catch (SQLException ignore) {
+                        // No-op.
+                    }
+                }
+            }
         }
         catch(Throwable e) {
             e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/15d4c051/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java
index 3f30158..6de6430 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/util/SchemaUtils.java
@@ -75,11 +75,11 @@ public class SchemaUtils {
     /**
      * Gets image by its filename.
      *
-     * @param fname Image filename.
+     * @param imgFileName Image filename.
      */
-    public static Image image(String fname, int sz) {
+    public static Image image(String imgFileName, int sz) {
         return new Image(SchemaUtils.class.getClassLoader()
-            .getResourceAsStream(String.format("media/%1$s_%2$dx%2$d.png", fname, sz)));
+            .getResourceAsStream(String.format("media/%1$s_%2$dx%2$d.png", imgFileName, sz)));
     }
 
     /**


Mime
View raw message