ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [2/3] incubator-ignite git commit: # IGNITE-330 Reworked snippet generation and create demo sources.
Date Sat, 21 Mar 2015 16:30:09 GMT
# IGNITE-330 Reworked snippet generation and create demo sources.


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

Branch: refs/heads/ignite-45
Commit: e292069832dcf220ca356c8f46516d187f8be45d
Parents: 533c0e4
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Sat Mar 21 23:28:19 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Sat Mar 21 23:28:19 2015 +0700

----------------------------------------------------------------------
 examples/schema-import/pom.xml                  | 91 ++++++++++++++++++++
 .../org/apache/ignite/ConfigurationSnippet.java | 38 ++++++++
 .../src/main/java/org/apache/ignite/Demo.java   | 56 ++++++++++++
 .../src/main/java/org/apache/ignite/Person.java | 33 +++++++
 .../main/java/org/apache/ignite/PersonKey.java  | 31 +++++++
 .../ignite/schema/generator/CodeGenerator.java  | 59 ++++---------
 .../ignite/schema/ui/SchemaImportApp.java       |  2 +-
 7 files changed, 267 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/examples/schema-import/pom.xml
----------------------------------------------------------------------
diff --git a/examples/schema-import/pom.xml b/examples/schema-import/pom.xml
new file mode 100644
index 0000000..5f335c3
--- /dev/null
+++ b/examples/schema-import/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<!--
+    POM file.
+-->
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <ignite.version>1.0.0</ignite.version>
+    </properties>
+
+    <groupId>org.apache.ignite</groupId>
+    <artifactId>ignite-schema-import-demo</artifactId>
+    <version>${ignite.version}</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.cache</groupId>
+            <artifactId>cache-api</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-spring</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-log4j</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-indexing</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/examples/schema-import/src/main/java/org/apache/ignite/ConfigurationSnippet.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/ConfigurationSnippet.java
b/examples/schema-import/src/main/java/org/apache/ignite/ConfigurationSnippet.java
new file mode 100644
index 0000000..640beb1
--- /dev/null
+++ b/examples/schema-import/src/main/java/org/apache/ignite/ConfigurationSnippet.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.store.*;
+
+import java.util.*;
+
+/**
+ * ConfigurationSnippet stub. Will be generated by Ignite Schema Import Utility.
+ */
+public class ConfigurationSnippet {
+    /** Configure cache store. */
+    public static CacheStore store() {
+        throw new IllegalStateException("ConfigurationSnippet should be generated by Ignite
Schema Import Utility");
+    }
+
+    /** Configure cache types metadata. */
+    public static Collection<CacheTypeMetadata> typeMetadata() {
+        throw new IllegalStateException("ConfigurationSnippet should be generated by Ignite
Schema Import Utility");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/examples/schema-import/src/main/java/org/apache/ignite/Demo.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/Demo.java b/examples/schema-import/src/main/java/org/apache/ignite/Demo.java
new file mode 100644
index 0000000..10ed54e
--- /dev/null
+++ b/examples/schema-import/src/main/java/org/apache/ignite/Demo.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+import org.apache.ignite.configuration.*;
+
+import javax.cache.configuration.*;
+
+/**
+ * Demo for CacheJdbcPojoStore.
+ */
+public class Demo {
+    public static void main(String[] args) throws IgniteException {
+        System.out.println(">>> Start demo...");
+
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        CacheConfiguration ccfg = new CacheConfiguration<>();
+
+        // Configure cache store.
+        ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(ConfigurationSnippet.store()));
+        ccfg.setReadThrough(true);
+        ccfg.setWriteThrough(true);
+
+        // Configure cache types metadata.
+        ccfg.setTypeMetadata(ConfigurationSnippet.typeMetadata());
+
+        cfg.setCacheConfiguration(ccfg);
+
+        // Start Ignite node.
+        try (Ignite ignite = Ignition.start(cfg)) {
+            IgniteCache<PersonKey, Person> cache = ignite.jcache(null);
+
+            // Demo for load cache with custom SQL.
+            cache.loadCache(null, "org.apache.ignite.examples.demo.PersonKey",
+                "select * from PERSON where ID = 3");
+
+            System.out.println(">>> Loaded Person: " + cache.get(new PersonKey(3)));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/examples/schema-import/src/main/java/org/apache/ignite/Person.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/Person.java b/examples/schema-import/src/main/java/org/apache/ignite/Person.java
new file mode 100644
index 0000000..36a0128
--- /dev/null
+++ b/examples/schema-import/src/main/java/org/apache/ignite/Person.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+import java.io.*;
+
+/**
+ * Person stub.  Will be generated by Ignite Schema Import Utility.
+ */
+public class Person {
+    /**
+     * Empty constructor.
+     */
+    public Person() {
+        throw new IllegalStateException("Person should be generated by Ignite Schema Import
Utility");
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/examples/schema-import/src/main/java/org/apache/ignite/PersonKey.java
----------------------------------------------------------------------
diff --git a/examples/schema-import/src/main/java/org/apache/ignite/PersonKey.java b/examples/schema-import/src/main/java/org/apache/ignite/PersonKey.java
new file mode 100644
index 0000000..948f974
--- /dev/null
+++ b/examples/schema-import/src/main/java/org/apache/ignite/PersonKey.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite;
+
+/**
+ * PersonKey definition.
+ */
+public class PersonKey implements Serializable {
+    /**
+     * Full constructor.
+     */
+    public PersonKey(int id) {
+        throw new IllegalStateException("PersonKey should be generated by Ignite Schema Import
Utility");
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/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 29e0824..5d26ec8 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
@@ -27,7 +27,7 @@ import java.util.*;
 import static org.apache.ignite.schema.ui.MessageBox.Result.*;
 
 /**
- * Code generator of POJOs for key and value classes and configuration snippets.
+ * Code generator of POJOs for key and value classes and configuration snippet.
  */
 public class CodeGenerator {
     /** */
@@ -459,14 +459,14 @@ public class CodeGenerator {
             if (javaTypeName.startsWith("java.lang."))
                 javaTypeName = javaTypeName.substring(10);
 
-            src.add(owner + ".add(new CacheTypeFieldMetadata(\"" + field.dbName() + "\",
" +
+            add2(src, owner + ".add(new CacheTypeFieldMetadata(\"" + field.dbName() + "\",
" +
                 "Types." + field.dbTypeName() + ", \"" +
                 field.javaName() + "\", " + javaTypeName + ".class));");
         }
     }
 
     /**
-     * Generate java snippets for cache configuration with JDBC store and types metadata.
+     * Generate java snippet for cache configuration with JDBC store and types metadata.
      *
      * @param pojos POJO descriptors.
      * @param pkg Types package.
@@ -475,17 +475,17 @@ public class CodeGenerator {
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      * @throws IOException If generation failed.
      */
-    public static void snippets(Collection<PojoDescriptor> pojos, String pkg, boolean
includeKeys,
+    public static void snippet(Collection<PojoDescriptor> pojos, String pkg, boolean
includeKeys,
         String outFolder, ConfirmCallable askOverwrite) throws IOException {
         File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
 
-        File cacheStoreSnippet = new File(pkgFolder, "CacheStoreSnippet.java");
+        File configurationSnippet = new File(pkgFolder, "ConfigurationSnippet.java");
 
-        if (cacheStoreSnippet.exists()) {
-            MessageBox.Result choice = askOverwrite.confirm(cacheStoreSnippet.getName());
+        if (configurationSnippet.exists()) {
+            MessageBox.Result choice = askOverwrite.confirm(configurationSnippet.getName());
 
             if (CANCEL == choice)
-                throw new IllegalStateException("Java snippets generation was canceled!");
+                throw new IllegalStateException("Java snippet generation was canceled!");
 
             if (NO == choice || NO_TO_ALL == choice)
                 return;
@@ -493,48 +493,23 @@ public class CodeGenerator {
 
         Collection<String> src = new ArrayList<>(256);
 
-        header(src, pkg, "org.apache.ignite.cache.store.jdbc.*;org.apache.ignite.configuration.*;;"
+
-            "javax.cache.configuration.*;javax.sql.*", "CacheStoreSnippet", "CacheStoreSnippet");
+        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.*;",
+            "ConfigurationSnippet", "ConfigurationSnippet");
 
         add1(src, "/** Configure cache store. */");
-        add1(src, "public static void configure(CacheConfiguration ccfg) {");
+        add1(src, "public static CacheStore store() {");
         add2(src, "DataSource dataSource = null; // TODO create data source.");
         add0(src, "");
-        add2(src, "// Create store. ");
         add2(src, "CacheJdbcPojoStore store = new CacheJdbcPojoStore();");
         add2(src, "store.setDataSource(dataSource);");
         add0(src, "");
-        add2(src, "// Create store factory. ");
-        add2(src, "ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<>(store));");
-        add0(src, "");
-        add2(src, "// Configure cache to use store. ");
-        add2(src, "ccfg.setReadThrough(true);");
-        add2(src, "ccfg.setWriteThrough(true);");
+        add2(src, "return store;");
         add1(src, "}");
-
-        add0(src, "}");
-
-        write(src, cacheStoreSnippet);
-
-        File cacheTypeMetadataSnippet = new File(pkgFolder, "CacheTypeMetadataSnippet.java");
-
-        if (cacheTypeMetadataSnippet.exists()) {
-            MessageBox.Result choice = askOverwrite.confirm(cacheTypeMetadataSnippet.getName());
-
-            if (CANCEL == choice)
-                throw new IllegalStateException("Java snippets generation was canceled!");
-
-            if (NO == choice || NO_TO_ALL == choice)
-                return;
-        }
-
-        src.clear();
-
-        header(src, pkg, "org.apache.ignite.cache.*;;org.apache.ignite.configuration.*;java.sql.Types;java.util.*",
-            "CacheTypeMetadataSnippet", "CacheTypeMetadataSnippet");
+        add0(src, "");
 
         add1(src, "/** Configure cache types metadata. */");
-        add1(src, "public static void configure(CacheConfiguration ccfg) {");
+        add1(src, "public static Collection<CacheTypeMetadata> typeMetadata() {");
 
         add2(src, "// Configure cache types. ");
         add2(src, "Collection<CacheTypeMetadata> meta = new ArrayList<>();");
@@ -571,11 +546,11 @@ public class CodeGenerator {
             first = false;
         }
         add0(src, "");
-        add2(src, "ccfg.setTypeMetadata(meta);");
+        add2(src, "return meta;");
         add1(src, "}");
 
         add0(src, "}");
 
-        write(src, cacheTypeMetadataSnippet);
+        write(src, configurationSnippet);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e2920698/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 ca63772..6096adb 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
@@ -484,7 +484,7 @@ public class SchemaImportApp extends Application {
                 if (singleXml)
                     XmlGenerator.generate(pkg, all, includeKeys, new File(outFolder, "Ignite.xml"),
askOverwrite);
 
-                CodeGenerator.snippets(all, pkg, includeKeys, outFolder, askOverwrite);
+                CodeGenerator.snippet(all, pkg, includeKeys, outFolder, askOverwrite);
 
                 perceptualDelay(started);
 


Mime
View raw message