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: POJO generation: added generation of toString() + minor code cleanup.
Date Fri, 26 Dec 2014 06:47:17 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-32 76408a4c5 -> 29e70d523


# IGNITE-32 WIP: POJO generation: added generation of toString() + minor code cleanup.


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

Branch: refs/heads/ignite-32
Commit: 29e70d523a486d29602df79242385f65105772e3
Parents: 76408a4
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Dec 26 13:47:18 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Dec 26 13:47:18 2014 +0700

----------------------------------------------------------------------
 .../ignite/schema/pojo/PojoCodeGenerator.java   | 145 +++++++++++++------
 .../org/apache/ignite/schema/ui/MessageBox.java |   2 +-
 .../apache/ignite/schema/util/SchemaUtils.java  |  18 ++-
 .../java/org/apache/ignite/Organization.java    |  21 ++-
 .../java/org/apache/ignite/OrganizationKey.java |  11 ++
 .../src/test/java/org/apache/ignite/Person.java |  17 ++-
 .../test/java/org/apache/ignite/PersonKey.java  |  11 ++
 .../auto/AbstractAutoCacheStoreSelfTest.java    |   2 +-
 .../store/auto/AutoCacheStoreSelfTest.java      |   2 +-
 9 files changed, 171 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/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 79dff5a..aacdab9 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
@@ -17,7 +17,7 @@ import java.util.*;
 import static org.apache.ignite.schema.util.SchemaUtils.*;
 
 /**
- * TODO: Add class description.
+ * POJO generator for key and value classes.
  */
 public class PojoCodeGenerator {
     /** */
@@ -28,6 +28,46 @@ public class PojoCodeGenerator {
     private static final String TAB3 = TAB + TAB + TAB;
 
     /**
+     * Add line to source code without indent.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add0(Collection<String> src, String line) {
+        src.add(line);
+    }
+
+    /**
+     * Add line to source code with one indent.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add1(Collection<String> src, String line) {
+        src.add(TAB + line);
+    }
+
+    /**
+     * Add line to source code with two indents.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add2(Collection<String> src, String line) {
+        src.add(TAB2 + line);
+    }
+
+    /**
+     * Add line to source code with three indents.
+     *
+     * @param src Source code.
+     * @param line Code line.
+     */
+    private static void add3(Collection<String> src, String line) {
+        src.add(TAB3 + line);
+    }
+    
+    /**
      * Generate java class code.
      *
      * @param pkg Package name.
@@ -37,85 +77,106 @@ public class PojoCodeGenerator {
      */
     private static void generateCode(String pkg, String type, Collection<GridCacheQueryTypeDescriptor>
descs,
         File pkgFolder) throws IOException {
+        if (descs.isEmpty())
+            return; // TODO IGNITE-32 UI should pass non metadata.
+
         Collection<String> src = new ArrayList<>(256);
 
-        src.add("package " + pkg + ";");
-        src.add("");
-        src.add("public class " + type + " {");
+        add0(src, "package " + pkg + ";");
+        add0(src, "");
+        add0(src, "/** Code generated by Apache Ignite Schema Load utility. */");
+        add0(src, "public class " + type + " {");
 
         for (GridCacheQueryTypeDescriptor desc : descs) {
-            src.add(TAB + "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
-            src.add("");
+            add1(src, "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
+            add0(src, "");
         }
 
         for (GridCacheQueryTypeDescriptor desc : descs) {
             String fldName = desc.getJavaName();
             String fldType = desc.getJavaType().getSimpleName();
 
-            String mtdName = capitalize(fldName);
+            String mtdName = capitalizeFirst(fldName);
 
-            src.add("");
+            add0(src, "");
 
-            src.add(TAB + "public " + fldType + " get" + mtdName + "() {");
-            src.add(TAB2 +"return " + fldName + ";");
-            src.add(TAB + "}");
+            add1(src, "public " + fldType + " get" + mtdName + "() {");
+            add2(src, "return " + fldName + ";");
+            add1(src, "}");
 
-            src.add("");
+            add0(src, "");
 
-            src.add(TAB + "public void set" + mtdName + "(" + fldType + " " + fldName + ")
{");
-            src.add(TAB2 +"this." + fldName + " = " + fldName + ";");
-            src.add(TAB + "}");
+            add1(src, "public void set" + mtdName + "(" + fldType + " " + fldName + ") {");
+            add2(src, "this." + fldName + " = " + fldName + ";");
+            add1(src, "}");
         }
 
-        src.add("");
+        add0(src, "");
 
-        src.add(TAB + "@Override public boolean equals(Object o) {");
-        src.add(TAB2 + "if (this == o)");
-        src.add(TAB3 + "return true;");
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public boolean equals(Object o) {");
+        add2(src, "if (this == o)");
+        add3(src, "return true;");
 
-        src.add("");
+        add0(src, "");
 
-        src.add(TAB2 + "if (!(o instanceof " + type + "))");
-        src.add(TAB3 + "return false;");
+        add2(src, "if (!(o instanceof " + type + "))");
+        add3(src, "return false;");
 
-        src.add("");
+        add0(src, "");
 
-        src.add(TAB2 + String.format("%1$s that = (%1$s)o;", type));
+        add2(src, String.format("%1$s that = (%1$s)o;", type));
 
         for (GridCacheQueryTypeDescriptor desc : descs) {
             String fldName = desc.getJavaName();
 
-            src.add("");
-            src.add(TAB2 + String.format("if (%1$s != null ? !%1$s.equals(that.%1$s) : that.%1$s
!= null)", fldName));
-            src.add(TAB3 + "return false;");
+            add0(src, "");
+            add2(src, String.format("if (%1$s != null ? !%1$s.equals(that.%1$s) : that.%1$s
!= null)", fldName));
+            add3(src, "return false;");
         }
 
-        src.add("");
-        src.add(TAB2 + "return true;");
-        src.add(TAB + "}");
+        add0(src, "");
+        add2(src, "return true;");
+        add1(src, "}");
 
-        src.add("");
+        add0(src, "");
 
-        src.add(TAB + "@Override public int hashCode() {");
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public int hashCode() {");
 
         Iterator<GridCacheQueryTypeDescriptor> it = descs.iterator();
 
-        GridCacheQueryTypeDescriptor first = it.next();
+        GridCacheQueryTypeDescriptor firstFld = it.next();
 
-        src.add(TAB2 + String.format("int result = %1$s != null ? %1$s.hashCode() : 0;",
first.getJavaName()));
+        add2(src, String.format("int res = %1$s != null ? %1$s.hashCode() : 0;", firstFld.getJavaName()));
 
         while(it.hasNext()) {
             String fldName = it.next().getJavaName();
 
-            src.add("");
-            src.add(TAB2 + String.format("result = 31 * result + (%1$s != null ? %1$s.hashCode()
: 0);", fldName));
+            add0(src, "");
+            add2(src, String.format("res = 31 * res + (%1$s != null ? %1$s.hashCode() : 0);",
fldName));
         }
 
-        src.add("");
-        src.add(TAB2 + "return result;");
-        src.add(TAB + "}");
+        add0(src, "");
+        add2(src, "return res;");
+        add1(src, "}");
+
+        add0(src, "");
 
-        src.add("}");
+        add1(src, "/** {@inheritDoc} */");
+        add1(src, "@Override public String toString() {");
+        add2(src, "return \"" + type + " [\"");
+
+        for (GridCacheQueryTypeDescriptor desc : descs) {
+            String fldName = desc.getJavaName();
+
+            add3(src, String.format("+ \" %1$s=\" + %1$s", fldName));
+        }
+
+        add2(src, " + \"]\";");
+        add1(src, "}");
+
+        add0(src, "}");
 
         try (Writer writer = new BufferedWriter(new FileWriter(new File(pkgFolder, type +
".java")))) {
             for (String line : src)
@@ -137,10 +198,6 @@ public class PojoCodeGenerator {
         if (!pkgFolder.exists() && !pkgFolder.mkdirs())
             throw new IOException("Failed to create folders for package: " + pkg);
 
-        String keyType = meta.getKeyType();
-
-        String valType = meta.getType();
-
         generateCode(pkg, meta.getKeyType(), meta.getKeyDescriptors(), pkgFolder);
 
         generateCode(pkg, meta.getType(), meta.getValueDescriptors(), pkgFolder);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/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 501fbd2..359f0af 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
@@ -21,7 +21,7 @@ import javafx.stage.*;
 import static org.apache.ignite.schema.util.SchemaUtils.*;
 
 /**
- * TODO: Add class description.
+ * Message box functionality.
  */
 public class MessageBox {
     /** */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/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 6de6430..a4e0d6a 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
@@ -14,7 +14,7 @@ import javafx.scene.image.*;
 import javafx.scene.layout.*;
 
 /**
- * TODO: Add class description.
+ * Utility class with common functions.
  */
 public class SchemaUtils {
     /** */
@@ -24,7 +24,7 @@ public class SchemaUtils {
      * @param str Source string.
      * @return String with each word first letters capitalized.
      */
-    public static String capitalize(String str) {
+    public static String capitalizeWords(String str) {
         int len = str.length();
 
         StringBuilder buf = new StringBuilder(len);
@@ -52,16 +52,24 @@ public class SchemaUtils {
      * @param str Source string.
      * @return String with first letters in lower case.
      */
-    public static String uncapitalize(String str) {
+    public static String uncapitalizeFirst(String str) {
         return Character.toLowerCase(str.charAt(0)) + str.substring(1);
     }
 
     /**
+     * @param str Source string.
+     * @return String with first letters in upper case.
+     */
+    public static String capitalizeFirst(String str) {
+        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
+    }
+
+    /**
      * @param name Source name.
      * @return String converted to java class name notation.
      */
     public static String toJavaClassName(String name) {
-        return capitalize(name.replace("_", " ")).replace(" ", "");
+        return capitalizeWords(name.replace("_", " ")).replace(" ", "");
     }
 
     /**
@@ -69,7 +77,7 @@ public class SchemaUtils {
      * @return String converted to java field name notation.
      */
     public static String toJavaFieldName(String name) {
-        return uncapitalize(toJavaClassName(name));
+        return uncapitalizeFirst(toJavaClassName(name));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/apache/ignite/Organization.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/apache/ignite/Organization.java b/modules/schema-load/src/test/java/org/apache/ignite/Organization.java
index 865f69c..b6acefa 100644
--- a/modules/schema-load/src/test/java/org/apache/ignite/Organization.java
+++ b/modules/schema-load/src/test/java/org/apache/ignite/Organization.java
@@ -1,5 +1,6 @@
 package org.apache.ignite;
 
+/** Code generated by Apache Ignite Schema Load utility. */
 public class Organization {
     private Integer id;
 
@@ -7,6 +8,7 @@ public class Organization {
 
     private String city;
 
+
     public Integer getId() {
         return id;
     }
@@ -31,6 +33,7 @@ public class Organization {
         this.city = city;
     }
 
+    /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
             return true;
@@ -52,13 +55,23 @@ public class Organization {
         return true;
     }
 
+    /** {@inheritDoc} */
     @Override public int hashCode() {
-        int result = id != null ? id.hashCode() : 0;
+        int res = id != null ? id.hashCode() : 0;
+
+        res = 31 * res + (name != null ? name.hashCode() : 0);
 
-        result = 31 * result + (name != null ? name.hashCode() : 0);
+        res = 31 * res + (city != null ? city.hashCode() : 0);
 
-        result = 31 * result + (city != null ? city.hashCode() : 0);
+        return res;
+    }
 
-        return result;
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return "Organization ["
+            + " id=" + id
+            + " name=" + name
+            + " city=" + city
+         + "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/apache/ignite/OrganizationKey.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/apache/ignite/OrganizationKey.java b/modules/schema-load/src/test/java/org/apache/ignite/OrganizationKey.java
index b5700b6..e2434f0 100644
--- a/modules/schema-load/src/test/java/org/apache/ignite/OrganizationKey.java
+++ b/modules/schema-load/src/test/java/org/apache/ignite/OrganizationKey.java
@@ -1,8 +1,10 @@
 package org.apache.ignite;
 
+/** Code generated by Apache Ignite Schema Load utility. */
 public class OrganizationKey {
     private Integer id;
 
+
     public Integer getId() {
         return id;
     }
@@ -11,6 +13,7 @@ public class OrganizationKey {
         this.id = id;
     }
 
+    /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
             return true;
@@ -26,9 +29,17 @@ public class OrganizationKey {
         return true;
     }
 
+    /** {@inheritDoc} */
     @Override public int hashCode() {
         int result = id != null ? id.hashCode() : 0;
 
         return result;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return "OrganizationKey ["
+            + " id=" + id
+         + "]";
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/apache/ignite/Person.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/apache/ignite/Person.java b/modules/schema-load/src/test/java/org/apache/ignite/Person.java
index e6f77a8..073f0d9 100644
--- a/modules/schema-load/src/test/java/org/apache/ignite/Person.java
+++ b/modules/schema-load/src/test/java/org/apache/ignite/Person.java
@@ -1,5 +1,6 @@
 package org.apache.ignite;
 
+/** Code generated by Apache Ignite Schema Load utility. */
 public class Person {
     private Integer id;
 
@@ -7,6 +8,7 @@ public class Person {
 
     private String name;
 
+
     public Integer getId() {
         return id;
     }
@@ -15,11 +17,11 @@ public class Person {
         this.id = id;
     }
 
-    public Integer getOrgid() {
+    public Integer getOrgId() {
         return orgId;
     }
 
-    public void setOrgid(Integer orgId) {
+    public void setOrgId(Integer orgId) {
         this.orgId = orgId;
     }
 
@@ -31,6 +33,7 @@ public class Person {
         this.name = name;
     }
 
+    /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
             return true;
@@ -52,6 +55,7 @@ public class Person {
         return true;
     }
 
+    /** {@inheritDoc} */
     @Override public int hashCode() {
         int result = id != null ? id.hashCode() : 0;
 
@@ -61,4 +65,13 @@ public class Person {
 
         return result;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return "Person ["
+            + " id=" + id
+            + " orgId=" + orgId
+            + " name=" + name
+         + "]";
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/apache/ignite/PersonKey.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/apache/ignite/PersonKey.java b/modules/schema-load/src/test/java/org/apache/ignite/PersonKey.java
index ac32b8f..755b0f7 100644
--- a/modules/schema-load/src/test/java/org/apache/ignite/PersonKey.java
+++ b/modules/schema-load/src/test/java/org/apache/ignite/PersonKey.java
@@ -1,8 +1,10 @@
 package org.apache.ignite;
 
+/** Code generated by Apache Ignite Schema Load utility. */
 public class PersonKey {
     private Integer id;
 
+
     public Integer getId() {
         return id;
     }
@@ -11,6 +13,7 @@ public class PersonKey {
         this.id = id;
     }
 
+    /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
             return true;
@@ -26,9 +29,17 @@ public class PersonKey {
         return true;
     }
 
+    /** {@inheritDoc} */
     @Override public int hashCode() {
         int result = id != null ? id.hashCode() : 0;
 
         return result;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return "PersonKey ["
+            + " id=" + id
+         + "]";
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AbstractAutoCacheStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AbstractAutoCacheStoreSelfTest.java
b/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AbstractAutoCacheStoreSelfTest.java
index ef1cd28..fcb9786 100644
--- a/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AbstractAutoCacheStoreSelfTest.java
+++ b/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AbstractAutoCacheStoreSelfTest.java
@@ -21,7 +21,7 @@ import java.sql.*;
 import java.util.*;
 
 /**
- * Test for {@code AutoCacheStore}.
+ * Base class for {@code AutoCacheStore} tests.
  */
 abstract class AbstractAutoCacheStoreSelfTest extends GridCommonAbstractTest {
     /** */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/29e70d52/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AutoCacheStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AutoCacheStoreSelfTest.java
b/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AutoCacheStoreSelfTest.java
index fa1ac66..a0892d3 100644
--- a/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AutoCacheStoreSelfTest.java
+++ b/modules/schema-load/src/test/java/org/gridgain/grid/cache/store/auto/AutoCacheStoreSelfTest.java
@@ -12,7 +12,7 @@ package org.gridgain.grid.cache.store.auto;
 import org.gridgain.grid.util.typedef.*;
 
 /**
- * TODO: Add class description.
+ * Tests for {@code AutoCacheStore}.
  */
 public class AutoCacheStoreSelfTest extends AbstractAutoCacheStoreSelfTest {
     /**


Mime
View raw message