ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [4/4] incubator-ignite git commit: # ignite-32 WIP: UI and POJO generation.
Date Mon, 22 Dec 2014 02:11:12 GMT
# ignite-32 WIP: UI and POJO generation.


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

Branch: refs/heads/ignite-32
Commit: e5e50db4bec96c1f3c90cec1d6cd08f98f80f566
Parents: f4b908c
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Mon Dec 22 09:10:56 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Mon Dec 22 09:10:56 2014 +0700

----------------------------------------------------------------------
 .../apache/ignite/schema/db/DbConnection.java   | 17 +++--
 .../ignite/schema/pojo/PojoCodeGenerator.java   | 76 ++++++++++++++++++++
 .../apache/ignite/schema/ui/SchemaLoadApp.java  | 69 ++++++++++++++++++
 3 files changed, 157 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5e50db4/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
index d6bce39..1d42eef 100644
--- 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
@@ -9,6 +9,7 @@
 
 package org.apache.ignite.schema.db;
 
+import org.apache.ignite.schema.pojo.*;
 import org.apache.ignite.schema.xml.*;
 import org.gridgain.grid.cache.query.*;
 
@@ -68,6 +69,10 @@ public class DbConnection {
 
                 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);
 
@@ -79,17 +84,19 @@ public class DbConnection {
 
                     XmlTransformer transformer = new XmlTransformer(4);
 
-                    Result res = new StreamResult(new File("C:/temp/ignite/" + tbl + ".xml"));
+                    Result res = new StreamResult(new File(destFolder, tbl + ".xml"));
 
                     transformer.transform(meta, res);
+
+                    codeGen.generate(meta, destFolder);
                 }
+            }
 
-                XmlTransformer transformer = new XmlTransformer(4);
+            XmlTransformer transformer = new XmlTransformer(4);
 
-                Result res = new StreamResult(new File("C:/temp/ignite/all.xml"));
+            Result res = new StreamResult(new File("C:/temp/ignite/all.xml"));
 
-                transformer.transform(all, res);
-            }
+            transformer.transform(all, res);
 
             conn.close();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5e50db4/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
new file mode 100644
index 0000000..2ec5708
--- /dev/null
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/pojo/PojoCodeGenerator.java
@@ -0,0 +1,76 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.schema.pojo;
+
+import org.gridgain.grid.cache.query.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * TODO: Add class description.
+ */
+public class PojoCodeGenerator {
+    /** */
+    private static final String TAB = "    ";
+
+    private final StringBuilder sb = new StringBuilder(4096);
+
+    private int indent = 0;
+
+    private PojoCodeGenerator append(String s) {
+        sb.append(s);
+
+        return this;
+    }
+
+    private PojoCodeGenerator line(String s) {
+        for (int i = 0; i < indent; i++)
+            sb.append(TAB);
+
+        append(s).nl();
+
+        return this;
+    }
+
+    private PojoCodeGenerator empty() {
+        return line("");
+    }
+
+    private PojoCodeGenerator nl() {
+        return append("\n");
+    }
+
+    public void generate(GridCacheQueryTypeMetadata meta, File outFolder) throws IOException
{
+        sb.setLength(0);
+
+        File res = new File(outFolder, meta.getType() + ".java");
+
+        line("package some.pakage;");
+
+        empty();
+
+        line("public class " + meta.getType() + " {");
+
+        indent++;
+
+        for(Map.Entry<String, Class<?>> field : meta.getQueryFields().entrySet())
{
+            line("private " + field.getValue().getSimpleName() + " " + field.getKey() + ";");
+        }
+
+        indent--;
+
+        line("}");
+
+        try (FileWriter writer = new FileWriter(res)) {
+            writer.write(sb.toString());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5e50db4/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
new file mode 100644
index 0000000..ae9d30e
--- /dev/null
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/SchemaLoadApp.java
@@ -0,0 +1,69 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.schema.ui;
+
+import javafx.application.*;
+import javafx.event.*;
+import javafx.geometry.*;
+import javafx.scene.*;
+import javafx.scene.control.*;
+import javafx.scene.layout.*;
+import javafx.stage.*;
+import org.apache.ignite.schema.db.*;
+
+/**
+ * Schema load application.
+ */
+public class SchemaLoadApp extends Application {
+    /**
+     *
+     * @param args
+     */
+    public static void main(String[] args) {
+        launch(args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start(Stage primaryStage) {
+        primaryStage.setTitle("Schema Load");
+
+        Button btn1 = new Button();
+        btn1.setText("Parse DB metadata...");
+        btn1.setOnAction(new EventHandler<ActionEvent>() {
+            @Override
+            public void handle(ActionEvent event) {
+                DbConnection.main(null);
+            }
+        });
+
+        Button btn2 = new Button();
+        btn2.setText("Generate POJOs...");
+        btn2.setOnAction(new EventHandler<ActionEvent>() {
+            @Override
+            public void handle(ActionEvent event) {
+                DbConnection.main(null);
+            }
+        });
+
+        GridPane grid = new GridPane();
+        grid.setAlignment(Pos.CENTER);
+        grid.setHgap(10);
+        grid.setVgap(10);
+        grid.setPadding(new Insets(25, 25, 25, 25));
+
+        grid.add(btn1, 0, 0);
+        grid.add(btn2, 0, 1);
+
+        grid.setGridLinesVisible(true);
+
+        primaryStage.setScene(new Scene(grid, 300, 250));
+        primaryStage.show();
+    }
+}


Mime
View raw message