ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [4/6] incubator-ignite git commit: # IGNITE-865 Fixed code generation logic.
Date Wed, 06 May 2015 09:20:30 GMT
# IGNITE-865 Fixed code generation logic.


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

Branch: refs/heads/ignite-gg-10221
Commit: 4a096d95874f1585dcb5c2fdb6c9d09db4fa45d9
Parents: 07a4258
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed May 6 13:04:57 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed May 6 13:04:57 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 41 ++++++++++++--------
 1 file changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a096d95/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 f8901d2..f04aa01 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
@@ -550,21 +550,25 @@ public class CodeGenerator {
      * @param mtdName Method name to generate.
      * @param comment Commentary text.
      * @param first {@code true} if variable should be declared.
+     * @return {@code false} if variable was declared.
      */
-    private static void addQueryFields(Collection<String> src, Collection<PojoField>
fields, String varName,
+    private static boolean addQueryFields(Collection<String> src, Collection<PojoField>
fields, String varName,
         String mtdName, String comment, boolean first) {
-        if (!fields.isEmpty()) {
-            add2(src, comment);
-            add2(src, (first ? "Map<String, Class<?>> " : "") + varName + " =
new LinkedHashMap<>();");
-            add0(src, "");
+        if (fields.isEmpty())
+            return true;
 
-            for (PojoField field : fields)
-                add2(src, varName + ".put(\"" + field.javaName() + "\", " + javaTypeName(field)
+ ".class);");
+        add2(src, comment);
+        add2(src, (first ? "Map<String, Class<?>> " : "") + varName + " = new
LinkedHashMap<>();");
+        add0(src, "");
 
-            add0(src, "");
-            add2(src, "type." + mtdName + "(" + varName + ");");
-            add0(src, "");
-        }
+        for (PojoField field : fields)
+            add2(src, varName + ".put(\"" + field.javaName() + "\", " + javaTypeName(field)
+ ".class);");
+
+        add0(src, "");
+        add2(src, "type." + mtdName + "(" + varName + ");");
+        add0(src, "");
+
+        return false;
     }
 
     /**
@@ -623,6 +627,9 @@ public class CodeGenerator {
         add0(src, "");
 
         boolean first = true;
+        boolean firstAsc = true;
+        boolean firstDesc = true;
+        boolean firstGrps = true;
         boolean firstGrp = true;
 
         for (PojoDescriptor pojo : pojos) {
@@ -661,22 +668,24 @@ public class CodeGenerator {
             addQueryFields(src, pojo.fields(), "qryFlds", "setQueryFields", "// Query fields
for " + tbl + ".", first);
 
             // Ascending fields.
-            addQueryFields(src, pojo.ascendingFields(), "ascFlds", "setAscendingFields",
-                "// Ascending fields for " + tbl + ".", first);
+            firstAsc = addQueryFields(src, pojo.ascendingFields(), "ascFlds", "setAscendingFields",
+                "// Ascending fields for " + tbl + ".", firstAsc);
 
             // Descending fields.
-            addQueryFields(src, pojo.descendingFields(), "descFlds", "setDescendingFields",
-                "// Descending fields for " + tbl + ".", first);
+            firstDesc = addQueryFields(src, pojo.descendingFields(), "descFlds", "setDescendingFields",
+                "// Descending fields for " + tbl + ".", firstDesc);
 
             // Groups.
             Map<String, Map<String, IndexItem>> groups = pojo.groups();
 
             if (!groups.isEmpty()) {
                 add2(src, "// Groups for " + tbl + ".");
-                add2(src, (first ? "Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>,
Boolean>>> " : "") +
+                add2(src, (firstGrps ? "Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>,
Boolean>>> " : "") +
                     " grps = new LinkedHashMap<>();");
                 add0(src, "");
 
+                firstGrps = false;
+
                 for (Map.Entry<String, Map<String, IndexItem>> group : groups.entrySet())
{
                     add2(src, (firstGrp ? "LinkedHashMap<String, IgniteBiTuple<Class<?>,
Boolean>> " : "") +
                             "grpItems = new LinkedHashMap<>();");


Mime
View raw message