ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [44/50] [abbrv] ignite git commit: ignite-1.5 Reworked code generation in order to avoid compiler error: "java: code too large".
Date Tue, 24 Nov 2015 09:18:55 GMT
ignite-1.5 Reworked code generation in order to avoid compiler error: "java: code too large".


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

Branch: refs/heads/master
Commit: fe53753368b001ea2c3d568f77b7f2b03c937bb9
Parents: d71f612
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Mon Nov 23 22:06:37 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Mon Nov 23 22:06:37 2015 +0700

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 185 +++++++++----------
 1 file changed, 91 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fe537533/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 283ccc1..92167e5 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
@@ -71,11 +71,11 @@ public class CodeGenerator {
         "void",         "volatile",      "while"
     ));
 
-    /** java.lang.*  */
-    private  static final String JAVA_LANG_PKG = "java.lang.";
+    /** java.lang.* */
+    private static final String JAVA_LANG_PKG = "java.lang.";
 
-    /** java.util.*  */
-    private  static final String JAVA_UTIL_PKG = "java.util.";
+    /** java.util.* */
+    private static final String JAVA_UTIL_PKG = "java.util.";
 
     /** Regexp to validate java identifier. */
     private static final Pattern VALID_JAVA_IDENTIFIER =
@@ -547,43 +547,15 @@ public class CodeGenerator {
 
             if (javaTypeName.startsWith(JAVA_LANG_PKG))
                 javaTypeName = javaTypeName.substring(JAVA_LANG_PKG.length());
-            else  if (javaTypeName.startsWith(JAVA_UTIL_PKG))
+            else if (javaTypeName.startsWith(JAVA_UTIL_PKG))
                 javaTypeName = javaTypeName.substring(JAVA_UTIL_PKG.length());
 
             add2(src, owner + ".add(new JdbcTypeField(Types." + field.dbTypeName() + ", \""
+ field.dbName() + "\", " +
-                    javaTypeName + ".class, \"" + field.javaName() + "\"));");
+                javaTypeName + ".class, \"" + field.javaName() + "\"));");
         }
     }
 
     /**
-     * Add query fields.
-     *
-     * @param src Source code lines.
-     * @param fields List of fields to add.
-     * @param comment Commentary text.
-     * @param first {@code true} if variable should be declared.
-     * @return {@code false} if variable was declared.
-     */
-    private static boolean addQueryFields(Collection<String> src, Collection<PojoField>
fields, String comment,
-        boolean first) {
-        if (fields.isEmpty())
-            return first;
-
-        add2(src, comment);
-        add2(src, (first ? "LinkedHashMap<String, String> " : "") + "fields = new LinkedHashMap<>();");
-        add0(src, "");
-
-        for (PojoField field : fields)
-            add2(src, "fields.put(\"" + field.javaName() + "\", \"" + javaTypeName(field)
+ "\");");
-
-        add0(src, "");
-        add2(src, "qryEntity.setFields(fields);");
-        add0(src, "");
-
-        return false;
-    }
-
-    /**
      * Generate java snippet for cache configuration with JDBC store and types metadata.
      *
      * @param pojos POJO descriptors.
@@ -612,39 +584,23 @@ public class CodeGenerator {
         Collection<String> src = new ArrayList<>(256);
 
         header(src, pkg, "java.sql.*;java.util.*;" +
-            "org.apache.ignite.cache.*;org.apache.ignite.cache.store.jdbc.*;" +
-            "org.apache.ignite.configuration.*;" + pkg + ".*",
+                "org.apache.ignite.cache.*;org.apache.ignite.cache.store.jdbc.*;" +
+                "org.apache.ignite.configuration.*",
             "CacheConfig", "CacheConfig");
 
-        add1(src, "/**");
-        add1(src, "* Configure cache.");
-        add1(src, "*");
-        add1(src, "* @param cacheName Cache name.");
-        add1(src, "* @param storeFactory Cache store factory.");
-        add1(src, "*/");
-        add1(src, "public static <K, V> CacheConfiguration<K, V> cache(String
cacheName," +
-            " CacheJdbcPojoStoreFactory<K, V> storeFactory) {");
-        add2(src, "if (storeFactory == null)");
-        add3(src, " throw new IllegalArgumentException(\"Cache store factory cannot be null.\");");
-        add0(src, "");
-        add2(src, "CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(cacheName);");
-        add0(src, "");
-        add2(src, "ccfg.setCacheStoreFactory(storeFactory);");
-        add2(src, "ccfg.setReadThrough(true);");
-        add2(src, "ccfg.setWriteThrough(true);");
-        add0(src, "");
-
-        add2(src, "// Configure JDBC types. ");
-        add2(src, "Collection<JdbcType> jdbcTypes = new ArrayList<>();");
-        add0(src, "");
-
-        boolean first = true;
-
+        // Generate methods for each type in order to avoid compiler error "java: code too
large".
         for (PojoDescriptor pojo : pojos) {
             String tbl = pojo.table();
+            String valClsName = pojo.valueClassName();
 
-            add2(src, "// " + tbl + ".");
-            add2(src, (first ? "JdbcType " : "") + "jdbcType = new JdbcType();");
+            add1(src, "/**");
+            add1(src, "* Create JDBC type for " + tbl + ".");
+            add1(src, "*");
+            add1(src, "* @param cacheName Cache name.");
+            add1(src, "*/");
+            add1(src, "private static JdbcType jdbcType" + valClsName + "(String cacheName)
{");
+
+            add2(src, "JdbcType jdbcType = new JdbcType();");
             add0(src, "");
 
             add2(src, "jdbcType.setCacheName(cacheName);");
@@ -654,70 +610,68 @@ public class CodeGenerator {
             add2(src, "jdbcType.setDatabaseTable(\"" + tbl + "\");");
 
             // Java info.
-            add2(src, "jdbcType.setKeyType(" + pojo.keyClassName() + ".class.getName());");
-            add2(src, "jdbcType.setValueType(" + pojo.valueClassName() + ".class.getName());");
+            add2(src, "jdbcType.setKeyType(\"" + pkg + "." + pojo.keyClassName() + "\");");
+            add2(src, "jdbcType.setValueType(\"" + pkg + "." + valClsName + "\");");
             add0(src, "");
 
             // Key fields.
             add2(src, "// Key fields for " + tbl + ".");
-            add2(src, (first ? "Collection<JdbcTypeField> " : "") + "keys = new ArrayList<>();");
+            add2(src, "Collection<JdbcTypeField> keys = new ArrayList<>();");
             addFields(src, "keys", pojo.keyFields());
             add2(src, "jdbcType.setKeyFields(keys.toArray(new JdbcTypeField[keys.size()]));");
             add0(src, "");
 
             // Value fields.
             add2(src, "// Value fields for " + tbl + ".");
-            add2(src, (first ? "Collection<JdbcTypeField> " : "") + "vals = new ArrayList<>();");
+            add2(src, "Collection<JdbcTypeField> vals = new ArrayList<>();");
             addFields(src, "vals", pojo.valueFields(includeKeys));
             add2(src, "jdbcType.setValueFields(vals.toArray(new JdbcTypeField[vals.size()]));");
             add0(src, "");
-
-            add2(src, "jdbcTypes.add(jdbcType);");
+            add2(src, "return jdbcType;");
+            add1(src, "}");
             add0(src, "");
 
-            first = false;
-        }
+            add1(src, "/**");
+            add1(src, "* Create SQL Query descriptor for " + tbl + ".");
+            add1(src, "*/");
+            add1(src, "private static QueryEntity queryEntity" + valClsName + "() {");
 
-        add2(src, "storeFactory.setTypes(jdbcTypes.toArray(new JdbcType[jdbcTypes.size()]));");
-        add0(src, "");
+            // Query entity.
+            add2(src, "QueryEntity qryEntity = new QueryEntity();");
+            add0(src, "");
+            add2(src, "qryEntity.setKeyType(\"" + pkg + "." + pojo.keyClassName() + "\");");
+            add2(src, "qryEntity.setValueType(\"" + pkg + "." + valClsName + "\");");
 
-        // Queries entities.
-        add2(src, "// Configure query entities. ");
-        add2(src, "Collection<QueryEntity> qryEntities = new ArrayList<>();");
-        add0(src, "");
+            add0(src, "");
 
-        first = true;
-        boolean firstIdxs = true;
-        boolean firstIdx = true;
+            // Query fields.
+            add2(src, "// Query fields for " + tbl + ".");
+            add2(src, "LinkedHashMap<String, String> fields = new LinkedHashMap<>();");
+            add0(src, "");
 
-        for (PojoDescriptor pojo : pojos) {
-            String tbl = pojo.table();
+            for (PojoField field : pojo.fields())
+                add2(src, "fields.put(\"" + field.javaName() + "\", \"" + javaTypeName(field)
+ "\");");
 
-            add2(src, (first ? "QueryEntity " : "") + "qryEntity = new QueryEntity();");
             add0(src, "");
-            add2(src, "qryEntity.setKeyType(" + pojo.keyClassName() + ".class.getName());");
-            add2(src, "qryEntity.setValueType(" + pojo.valueClassName() + ".class.getName());");
+            add2(src, "qryEntity.setFields(fields);");
             add0(src, "");
 
-            // Query fields.
-            addQueryFields(src, pojo.fields(), "// Query fields for " + tbl + ".", first);
-
             // Indexes.
             Collection<QueryIndex> idxs = pojo.indexes();
 
             if (!idxs.isEmpty()) {
                 add2(src, "// Indexes for " + tbl + ".");
-                add2(src, (firstIdxs ? "Collection<QueryIndex> " : "") + "idxs = new
ArrayList<>();");
+                add2(src, "Collection<QueryIndex> idxs = new ArrayList<>();");
                 add0(src, "");
 
-                firstIdxs = false;
+                boolean firstIdx = true;
 
                 for (QueryIndex idx : idxs) {
                     if (idx.getFields().size() == 1) {
                         Map.Entry<String, Boolean> fld = F.first(idx.getFields().entrySet());
 
                         add2(src, "idxs.add(new QueryIndex(\"" + fld.getKey() + "\", " +
fld.getValue() + ", \"" +
-                            idx.getName()  + "\"));");
+                            idx.getName() + "\"));");
                         add0(src, "");
                     }
                     else {
@@ -732,7 +686,7 @@ public class CodeGenerator {
                         add0(src, "");
 
                         for (Map.Entry<String, Boolean> idxFld : idx.getFields().entrySet())
-                            add2(src, "idxFlds.put(\"" + idxFld.getKey()  + "\", " + idxFld.getValue()
+ ");");
+                            add2(src, "idxFlds.put(\"" + idxFld.getKey() + "\", " + idxFld.getValue()
+ ");");
 
                         add0(src, "");
 
@@ -750,12 +704,55 @@ public class CodeGenerator {
                 add0(src, "");
             }
 
-            add2(src, "ccfg.setQueryEntities(qryEntities);");
-            add0(src, "");
+            add2(src, "return qryEntity;");
 
-            first = false;
+            add1(src, "}");
+            add0(src, "");
         }
 
+        add1(src, "/**");
+        add1(src, "* Configure cache.");
+        add1(src, "*");
+        add1(src, "* @param cacheName Cache name.");
+        add1(src, "* @param storeFactory Cache store factory.");
+        add1(src, "*/");
+        add1(src, "public static <K, V> CacheConfiguration<K, V> cache(String
cacheName," +
+            " CacheJdbcPojoStoreFactory<K, V> storeFactory) {");
+        add2(src, "if (storeFactory == null)");
+        add3(src, " throw new IllegalArgumentException(\"Cache store factory cannot be null.\");");
+        add0(src, "");
+        add2(src, "CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(cacheName);");
+        add0(src, "");
+        add2(src, "ccfg.setCacheStoreFactory(storeFactory);");
+        add2(src, "ccfg.setReadThrough(true);");
+        add2(src, "ccfg.setWriteThrough(true);");
+        add0(src, "");
+
+        add2(src, "// Configure JDBC types. ");
+        add2(src, "Collection<JdbcType> jdbcTypes = new ArrayList<>();");
+        add0(src, "");
+
+        for (PojoDescriptor pojo : pojos)
+            add2(src, "jdbcTypes.add(jdbcType" + pojo.valueClassName() + "(cacheName));");
+
+        add0(src, "");
+
+        add2(src, "storeFactory.setTypes(jdbcTypes.toArray(new JdbcType[jdbcTypes.size()]));");
+        add0(src, "");
+
+
+        add2(src, "// Configure query entities. ");
+        add2(src, "Collection<QueryEntity> qryEntities = new ArrayList<>();");
+        add0(src, "");
+
+        for (PojoDescriptor pojo : pojos)
+            add2(src, "qryEntities.add(queryEntity" + pojo.valueClassName() + "());");
+
+        add0(src, "");
+
+        add2(src, "ccfg.setQueryEntities(qryEntities);");
+        add0(src, "");
+
         add2(src, "return ccfg;");
         add1(src, "}");
 


Mime
View raw message