Author: cutting
Date: Mon Apr 22 19:50:19 2013
New Revision: 1470682

URL: http://svn.apache.org/r1470682
Log:
AVRO-1300. Java: Fix generated copy constructors to copy field values.  
Contributed by taton.

Modified:
    avro/trunk/CHANGES.txt
    
avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
    
avro/trunk/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
    avro/trunk/lang/java/tools/src/test/compiler/output/Player.java

Modified: avro/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1470682&r1=1470681&r2=1470682&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Apr 22 19:50:19 2013
@@ -39,6 +39,9 @@ Trunk (not yet released)
     AVRO-1295. Java: Fix printing of a non-null namespace within a
     null namespace. (cutting)
 
+    AVRO-1300. Java: Fix generated copy constructors to copy field
+    values. (Christophe Taton via cutting)
+
 Avro 1.7.4 (22 February 2012)
 
   NEW FEATURES

Modified: 
avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
URL: 
http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm?rev=1470682&r1=1470681&r2=1470682&view=diff
==============================================================================
--- 
avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
 (original)
+++ 
avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
 Mon Apr 22 19:50:19 2013
@@ -155,6 +155,12 @@ public class ${this.mangle($schema.getNa
     /** Creates a Builder by copying an existing Builder */
     private Builder(#if 
($schema.getNamespace())$schema.getNamespace().#end${this.mangle($schema.getName())}.Builder
 other) {
       super(other);
+#foreach ($field in $schema.getFields())
+      if (isValidValue(fields()[$field.pos()], 
other.${this.mangle($field.name(), $schema.isError())})) {
+        this.${this.mangle($field.name(), $schema.isError())} = 
data().deepCopy(fields()[$field.pos()].schema(), 
other.${this.mangle($field.name(), $schema.isError())});
+        fieldSetFlags()[$field.pos()] = true;
+      }
+#end
     }
     
     /** Creates a Builder by copying an existing 
$this.mangle($schema.getName()) instance */

Modified: 
avro/trunk/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
URL: 
http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java?rev=1470682&r1=1470681&r2=1470682&view=diff
==============================================================================
--- 
avro/trunk/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
 (original)
+++ 
avro/trunk/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java
 Mon Apr 22 19:50:19 2013
@@ -146,6 +146,22 @@ public class Player extends org.apache.a
     /** Creates a Builder by copying an existing Builder */
     private Builder(avro.examples.baseball.Player.Builder other) {
       super(other);
+      if (isValidValue(fields()[0], other.number)) {
+        this.number = data().deepCopy(fields()[0].schema(), other.number);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.first_name)) {
+        this.first_name = data().deepCopy(fields()[1].schema(), 
other.first_name);
+        fieldSetFlags()[1] = true;
+      }
+      if (isValidValue(fields()[2], other.last_name)) {
+        this.last_name = data().deepCopy(fields()[2].schema(), 
other.last_name);
+        fieldSetFlags()[2] = true;
+      }
+      if (isValidValue(fields()[3], other.position)) {
+        this.position = data().deepCopy(fields()[3].schema(), other.position);
+        fieldSetFlags()[3] = true;
+      }
     }
     
     /** Creates a Builder by copying an existing Player instance */

Modified: avro/trunk/lang/java/tools/src/test/compiler/output/Player.java
URL: 
http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/compiler/output/Player.java?rev=1470682&r1=1470681&r2=1470682&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/compiler/output/Player.java (original)
+++ avro/trunk/lang/java/tools/src/test/compiler/output/Player.java Mon Apr 22 
19:50:19 2013
@@ -146,6 +146,22 @@ public class Player extends org.apache.a
     /** Creates a Builder by copying an existing Builder */
     private Builder(avro.examples.baseball.Player.Builder other) {
       super(other);
+      if (isValidValue(fields()[0], other.number)) {
+        this.number = data().deepCopy(fields()[0].schema(), other.number);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.first_name)) {
+        this.first_name = data().deepCopy(fields()[1].schema(), 
other.first_name);
+        fieldSetFlags()[1] = true;
+      }
+      if (isValidValue(fields()[2], other.last_name)) {
+        this.last_name = data().deepCopy(fields()[2].schema(), 
other.last_name);
+        fieldSetFlags()[2] = true;
+      }
+      if (isValidValue(fields()[3], other.position)) {
+        this.position = data().deepCopy(fields()[3].schema(), other.position);
+        fieldSetFlags()[3] = true;
+      }
     }
     
     /** Creates a Builder by copying an existing Player instance */


Reply via email to