ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [1/2] incubator-ignite git commit: # IGNITE-330 Reworked code generator to generate cache config. Added check for empty tables list. Started to change Demo.java to show read/write through.
Date Mon, 23 Mar 2015 18:00:22 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 27c54acbc -> 57db52481


# IGNITE-330 Reworked code generator to generate cache config. Added check for empty tables
list. Started to change Demo.java to show read/write through.


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

Branch: refs/heads/ignite-45
Commit: acf0c6bfbd9a7c0534b56d5aea62e8bbf51e947b
Parents: 861ce5e
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Tue Mar 24 00:56:21 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Tue Mar 24 00:56:21 2015 +0700

----------------------------------------------------------------------
 .../org/apache/ignite/schema/CacheConfig.java   | 14 ++----
 .../java/org/apache/ignite/schema/Demo.java     | 50 +++++++++++-------
 .../ignite/schema/generator/CodeGenerator.java  | 53 ++++++++++++++------
 .../ignite/schema/ui/SchemaImportApp.java       | 42 ++++++++++------
 4 files changed, 99 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/acf0c6bf/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java
b/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java
index e5af72a..b57d75e 100644
--- a/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java
+++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/CacheConfig.java
@@ -17,22 +17,16 @@
 
 package org.apache.ignite.schema;
 
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.store.*;
+import org.apache.ignite.configuration.*;
 
-import java.util.*;
+import javax.sql.*;
 
 /**
  * CacheConfig stub. Will be generated by Ignite Schema Import Utility.
  */
 public class CacheConfig {
-    /** Configure cache store. */
-    public static CacheStore store() {
-        throw new IllegalStateException("CacheConfig should be generated by Ignite Schema
Import Utility");
-    }
-
-    /** Configure cache types metadata. */
-    public static Collection<CacheTypeMetadata> typeMetadata() {
+    /** Configure cache. */
+    public static CacheConfiguration cache(String name, final DataSource dataSource) {
         throw new IllegalStateException("CacheConfig should be generated by Ignite Schema
Import Utility");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/acf0c6bf/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
index a58176d..d5356f1 100644
--- a/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
+++ b/examples/schema-import/src/main/java/org/apache/ignite/schema/Demo.java
@@ -18,12 +18,10 @@
 package org.apache.ignite.schema;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.store.*;
 import org.apache.ignite.cache.store.jdbc.*;
 import org.apache.ignite.configuration.*;
 
 import javax.cache.*;
-import javax.cache.configuration.*;
 
 /**
  * Demo for CacheJdbcPojoStore.
@@ -33,6 +31,9 @@ import javax.cache.configuration.*;
  * Custom SQL will be executed to populate cache with data from database.
  */
 public class Demo {
+    /** */
+    private static final String CACHE_NAME = "Person";
+
     /**
      * Executes demo.
      *
@@ -44,29 +45,15 @@ public class Demo {
 
         IgniteConfiguration cfg = new IgniteConfiguration();
 
-        CacheConfiguration ccfg = new CacheConfiguration<>();
-
         // Configure cache store.
-        ccfg.setCacheStoreFactory(new Factory<CacheStore>() {
-            @Override public CacheStore create() {
-                return CacheConfig.store();
-            }
-        });
-
-        ccfg.setReadThrough(true);
-        ccfg.setWriteThrough(true);
-
-        // Enable database batching.
-        ccfg.setWriteBehindEnabled(true);
-
-        // Configure cache types metadata.
-        ccfg.setTypeMetadata(CacheConfig.typeMetadata());
+        CacheConfiguration ccfg = CacheConfig.cache(CACHE_NAME,
+            org.h2.jdbcx.JdbcConnectionPool.create("jdbc:h2:tcp://localhost/~/schema-import/demo",
"sa", ""));
 
         cfg.setCacheConfiguration(ccfg);
 
         // Start Ignite node.
         try (Ignite ignite = Ignition.start(cfg)) {
-            IgniteCache<PersonKey, Person> cache = ignite.jcache(null);
+            IgniteCache<PersonKey, Person> cache = ignite.jcache(CACHE_NAME);
 
             // Demo for load cache with custom SQL.
             cache.loadCache(null, "org.apache.ignite.schema.PersonKey",
@@ -76,4 +63,29 @@ public class Demo {
                 System.out.println(">>> Loaded Person: " + person);
         }
     }
+
+    /** Demonstrates cache preload from database.  */
+    private static void preload() {
+        // TODO
+    }
+
+    /** Demonstrates cache wright through to database.  */
+    private static void writeThrough() {
+        // TODO
+    }
+
+    /** Demonstrates cache read through from database.  */
+    private static void readThrough() {
+        // TODO
+    }
+
+    /** Demonstrates cache remove from database.  */
+    private static void remove() {
+        // TODO
+    }
+
+    /** Demonstrates cache transaction from database.  */
+    private static void transaction() {
+        // TODO
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/acf0c6bf/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
index a10bea7..6782d38 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -36,6 +36,8 @@ public class CodeGenerator {
     private static final String TAB2 = TAB + TAB;
     /** */
     private static final String TAB3 = TAB + TAB + TAB;
+    /** */
+    private static final String TAB4 = TAB + TAB + TAB + TAB;
 
     /**
      * Add line to source code without indent.
@@ -89,6 +91,16 @@ public class CodeGenerator {
     }
 
     /**
+     * Add line to source code with four indents.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add4(Collection<String> src, String line) {
+        src.add(TAB4 + line);
+    }
+
+    /**
      * @param str Source string.
      * @return String with first letters in upper case.
      */
@@ -479,10 +491,10 @@ public class CodeGenerator {
         String outFolder, ConfirmCallable askOverwrite) throws IOException {
         File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
 
-        File cacheConfig = new File(pkgFolder, "CacheConfig.java");
+        File cacheCfg = new File(pkgFolder, "CacheConfig.java");
 
-        if (cacheConfig.exists()) {
-            MessageBox.Result choice = askOverwrite.confirm(cacheConfig.getName());
+        if (cacheCfg.exists()) {
+            MessageBox.Result choice = askOverwrite.confirm(cacheCfg.getName());
 
             if (CANCEL == choice)
                 throw new IllegalStateException("Java snippet generation was canceled!");
@@ -494,22 +506,31 @@ public class CodeGenerator {
         Collection<String> src = new ArrayList<>(256);
 
         header(src, pkg, "org.apache.ignite.cache.*;org.apache.ignite.cache.store.*;" +
-            "org.apache.ignite.cache.store.jdbc.*;;javax.sql.*;java.sql.Types;java.util.*;",
+                "org.apache.ignite.cache.store.jdbc.*;org.apache.ignite.configuration.*;;"
+
+                "javax.cache.configuration.*;javax.sql.*;java.sql.*;java.util.*",
             "CacheConfig", "CacheConfig");
 
-        add1(src, "/** Configure cache store. */");
-        add1(src, "public static CacheStore store() {");
-        add2(src, "DataSource dataSource = null; // TODO create data source.");
+        add1(src, "/** Configure cache. */");
+        add1(src, "public static CacheConfiguration cache(String name, final DataSource dataSource)
{");
+        add2(src, "if (dataSource == null)");
+        add3(src, "throw new NullPointerException(\"Datasource cannot be null.\");");
         add0(src, "");
-        add2(src, "CacheJdbcPojoStore store = new CacheJdbcPojoStore();");
-        add2(src, "store.setDataSource(dataSource);");
+        add2(src, "CacheConfiguration ccfg = new CacheConfiguration(name);");
         add0(src, "");
-        add2(src, "return store;");
-        add1(src, "}");
+        add2(src, "ccfg.setCacheStoreFactory(new Factory<CacheStore>() {");
+        add3(src, "@Override public CacheStore create () {");
+        add4(src, "final CacheJdbcPojoStore store = new CacheJdbcPojoStore();");
+        add0(src, "");
+        add4(src, "store.setDataSource(dataSource);");
+        add0(src, "");
+        add4(src, "return store;");
+        add3(src, "}");
+        add2(src, "});");
         add0(src, "");
 
-        add1(src, "/** Configure cache types metadata. */");
-        add1(src, "public static Collection<CacheTypeMetadata> typeMetadata() {");
+        add2(src, "ccfg.setReadThrough(true);");
+        add2(src, "ccfg.setWriteThrough(true);");
+        add0(src, "");
 
         add2(src, "// Configure cache types. ");
         add2(src, "Collection<CacheTypeMetadata> meta = new ArrayList<>();");
@@ -545,12 +566,14 @@ public class CodeGenerator {
 
             first = false;
         }
+
+        add2(src, "ccfg.setTypeMetadata(meta);");
         add0(src, "");
-        add2(src, "return meta;");
+        add2(src, "return ccfg;");
         add1(src, "}");
 
         add0(src, "}");
 
-        write(src, cacheConfig);
+        write(src, cacheCfg);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/acf0c6bf/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
index 1b1ba48..cdd3cec 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
@@ -359,29 +359,39 @@ public class SchemaImportApp extends Application {
 
             /** {@inheritDoc} */
             @Override protected void succeeded() {
-                super.succeeded();
+                try {
+                    super.succeeded();
 
-                pojosTbl.setItems(pojos);
+                    pojosTbl.setItems(pojos);
 
-                if (!pojos.isEmpty())
-                    pojosTbl.getSelectionModel().clearAndSelect(0);
+                    if (pojos.isEmpty()) {
+                        MessageBox.warningDialog(owner, "No tables found in database. Recheck
JDBC URL.\n" +
+                            "JDBC URL: " +  jdbcUrl);
 
-                curTbl = pojosTbl;
+                        return;
+                    }
+                    else
+                        pojosTbl.getSelectionModel().clearAndSelect(0);
 
-                pojosTbl.requestFocus();
+                    curTbl = pojosTbl;
+
+                    pojosTbl.requestFocus();
 
-                unlockUI(connLayerPnl, connPnl, nextBtn);
 
-                hdrPane.setLeft(genIcon);
+                    hdrPane.setLeft(genIcon);
 
-                titleLb.setText("Generate XML And POJOs");
-                subTitleLb.setText(jdbcUrlTf.getText());
+                    titleLb.setText("Generate XML And POJOs");
+                    subTitleLb.setText(jdbcUrlTf.getText());
 
-                rootPane.setCenter(genLayerPnl);
+                    rootPane.setCenter(genLayerPnl);
 
-                prevBtn.setDisable(false);
-                nextBtn.setText("Generate");
-                tooltip(nextBtn, "Generate XML and POJO files");
+                    prevBtn.setDisable(false);
+                    nextBtn.setText("Generate");
+                    tooltip(nextBtn, "Generate XML and POJO files");
+                }
+                finally {
+                    unlockUI(connLayerPnl, connPnl, nextBtn);
+                }
             }
 
             /** {@inheritDoc} */
@@ -481,7 +491,7 @@ public class SchemaImportApp extends Application {
                 }
 
                 if (singleXml)
-                    XmlGenerator.generate(pkg, all, includeKeys, new File(outFolder, "Ignite.xml"),
askOverwrite);
+                    XmlGenerator.generate(pkg, all, includeKeys, new File(outFolder, "ignite-type-metadata.xml"),
askOverwrite);
 
                 CodeGenerator.snippet(all, pkg, includeKeys, outFolder, askOverwrite);
 
@@ -950,7 +960,7 @@ public class SchemaImportApp extends Application {
             "If selected then generate empty and full constructors for POJOs", false), 3);
 
         xmlSingleFileCh = genPnl.add(checkBox("Write all configurations to a single XML file",
-            "If selected then all configurations will be saved into the file 'Ignite.xml'",
true), 3);
+            "If selected then all configurations will be saved into the file 'ignite-type-metadata.xml'",
true), 3);
 
         GridPaneEx regexPnl = paneEx(5, 5, 5, 5);
         regexPnl.addColumn();


Mime
View raw message