ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] incubator-ignite git commit: # IGNITE-32 WIP: Fixed POJO and XML generation.
Date Thu, 25 Dec 2014 07:48:06 GMT
# IGNITE-32 WIP: Fixed POJO and XML generation.


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

Branch: refs/heads/ignite-32
Commit: d055526d29f7b909942e17647db62c1110e4bcd3
Parents: 7d05f7d
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Thu Dec 25 14:48:02 2014 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Thu Dec 25 14:48:02 2014 +0700

----------------------------------------------------------------------
 .../ignite/schema/pojo/PojoCodeGenerator.java   | 38 +++++++++++++-------
 .../ignite/schema/xml/XmlTransformer.java       | 24 ++++++-------
 2 files changed, 37 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d055526d/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 963306c..8c1eee1 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
@@ -33,7 +33,6 @@ public class PojoCodeGenerator {
     private int indent;
 
     /**
-     *
      * @return
      */
     private String indent() {
@@ -58,9 +57,19 @@ public class PojoCodeGenerator {
         src.add("");
     }
 
-    private void newLine(Collection<String> src, String s) {
+    /**
+     * Generate key declarations.
+     *
+     * @param src Source code.
+     * @param pkg Package name.
+     * @param type Type name.
+     */
+    private void generateHeader(Collection<String> src, String pkg, String type) {
+        line(src, "package " + pkg + ";");
+
         empty(src);
-        line(src, s);
+
+        line(src, "public class " + type + " {");
     }
 
     /**
@@ -70,8 +79,11 @@ public class PojoCodeGenerator {
      * @param descs Type descriptor.
      */
     private void generateFields(Collection<String> src, Collection<GridCacheQueryTypeDescriptor>
descs) {
-        for(GridCacheQueryTypeDescriptor desc : descs)
+        for (GridCacheQueryTypeDescriptor desc : descs) {
             line(src, "private " + desc.getJavaType().getSimpleName() + " " + desc.getJavaName()
+ ";");
+
+            empty(src);
+        }
     }
 
     /**
@@ -81,13 +93,13 @@ public class PojoCodeGenerator {
      * @param descs Type descriptor.
      */
     private void generateMethods(Collection<String> src, Collection<GridCacheQueryTypeDescriptor>
descs) {
-        for(GridCacheQueryTypeDescriptor desc : descs) {
+        for (GridCacheQueryTypeDescriptor desc : descs) {
             String fldName = desc.getJavaName();
             String fldType = desc.getJavaType().getSimpleName();
 
             String mtdName = capitalize(fldName);
 
-            newLine(src, "public " + fldType + " get" + mtdName + "() {");
+            line(src, "public " + fldType + " get" + mtdName + "() {");
 
             indent++;
             line(src, "return " + fldName + ";");
@@ -95,7 +107,9 @@ public class PojoCodeGenerator {
 
             line(src, "}");
 
-            newLine(src, "public void set" + mtdName + "(" + fldName + ": " + fldType+ ")
{");
+            empty(src);
+
+            line(src, "public void set" + mtdName + "(" + fldType + " " + fldName + ") {");
 
             indent++;
             line(src, "this." + fldName + " = " + fldName + ";");
@@ -120,14 +134,12 @@ public class PojoCodeGenerator {
 
         res.mkdirs();
 
-        String keyType =  meta.getKeyType();
-        String valType =  meta.getType();
+        String keyType = meta.getKeyType();
+        String valType = meta.getType();
 
-        line(srcKey, pkg + ";");
-        line(srcVal, pkg + ";");
+        generateHeader(srcKey, pkg, keyType);
 
-        newLine(srcKey, "public class " + keyType + " {");
-        newLine(srcVal, "public class " + valType + " {");
+        generateHeader(srcVal, pkg, valType);
 
         indent++;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d055526d/modules/schema-load/src/main/java/org/apache/ignite/schema/xml/XmlTransformer.java
----------------------------------------------------------------------
diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/xml/XmlTransformer.java
b/modules/schema-load/src/main/java/org/apache/ignite/schema/xml/XmlTransformer.java
index 5a94729..e6de467 100644
--- a/modules/schema-load/src/main/java/org/apache/ignite/schema/xml/XmlTransformer.java
+++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/xml/XmlTransformer.java
@@ -65,7 +65,7 @@ public class XmlTransformer {
             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
 
         }
-        catch(ParserConfigurationException | TransformerConfigurationException e) {
+        catch (ParserConfigurationException | TransformerConfigurationException e) {
             throw new IllegalStateException(e);
         }
     }
@@ -156,7 +156,7 @@ public class XmlTransformer {
 
             Element map = addElement(prop, "map");
 
-            for(Map.Entry<String, Class<?>> item : fields.entrySet())
+            for (Map.Entry<String, Class<?>> item : fields.entrySet())
                 addElement(map, "entry", "key", item.getKey(), "value", item.getValue().getName());
         }
     }
@@ -196,7 +196,7 @@ public class XmlTransformer {
 
             Element list = addElement(prop, "list");
 
-            for(String textField : textFields)
+            for (String textField : textFields)
                 addElement(list, "value").setNodeValue(textField);
         }
     }
@@ -219,7 +219,7 @@ public class XmlTransformer {
 
                 LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>
fields = group.getValue();
 
-                for(Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
field : fields.entrySet()) {
+                for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
field : fields.entrySet()) {
                     Element entry2 = addElement(val1, "entry", "key", field.getKey());
 
                     Element val2 = addBean(entry2, IgniteBiTuple.class);
@@ -243,12 +243,12 @@ public class XmlTransformer {
      * @param parent Parent XML node.
      * @param meta Meta.
      */
-    private void addCacheQueryTypeMetadata(Node parent, GridCacheQueryTypeMetadata meta)
{
+    private void addCacheQueryTypeMetadata(Node parent, String pkg, GridCacheQueryTypeMetadata
meta) {
         Element bean = addBean(parent, GridCacheQueryTypeMetadata.class);
 
-        addProperty(bean, "type", meta.getType());
+        addProperty(bean, "type", pkg + "." + meta.getType());
 
-        addProperty(bean, "keyType", meta.getKeyType());
+        addProperty(bean, "keyType", pkg + "." + meta.getKeyType());
 
         addProperty(bean, "schema", meta.getSchema());
 
@@ -284,8 +284,8 @@ public class XmlTransformer {
      * @param out Output result.
      * @throws TransformerException If an unrecoverable error occurs during the course of
the transformation.
      */
-    public void transform(GridCacheQueryTypeMetadata meta, Result out) throws TransformerException
{
-        addCacheQueryTypeMetadata(beans, meta);
+    public void transform(String pkg, GridCacheQueryTypeMetadata meta, Result out) throws
TransformerException {
+        addCacheQueryTypeMetadata(beans, pkg, meta);
 
         transform(out);
     }
@@ -297,9 +297,9 @@ public class XmlTransformer {
      * @param out Output result.
      * @throws TransformerException If an unrecoverable error occurs during the course of
the transformation.
      */
-    public void transform(Collection<GridCacheQueryTypeMetadata> meta, Result out)
throws TransformerException {
-        for(GridCacheQueryTypeMetadata item : meta)
-            addCacheQueryTypeMetadata(beans, item);
+    public void transform(String pkg, Collection<GridCacheQueryTypeMetadata> meta,
Result out) throws TransformerException {
+        for (GridCacheQueryTypeMetadata item : meta)
+            addCacheQueryTypeMetadata(beans, pkg, item);
 
         transform(out);
     }


Mime
View raw message