avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1435349 - in /avro/trunk: ./ lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/ lang/java/ipc/src/test/java/org/apache/avro/spe...
Date Fri, 18 Jan 2013 21:22:05 GMT
Author: cutting
Date: Fri Jan 18 21:22:04 2013
New Revision: 1435349

URL: http://svn.apache.org/viewvc?rev=1435349&view=rev
Log:
AVRO-1223. Java: Add a static method to generated classes that returns its schema, getClassSchema().

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
    avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
    avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/fixed.vm
    avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1435349&r1=1435348&r2=1435349&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Jan 18 21:22:04 2013
@@ -19,6 +19,9 @@ Trunk (not yet released)
 
     AVRO-970. Java: Make Codec API public. (Rui Pereira via cutting)
 
+    AVRO-1223. Java: Add a static method to generated classes that
+    returns its schema, getClassSchema().  (cutting)
+
   BUG FIXES
 
     AVRO-1231. Java: Fix Trevni shredder to work on non-recursive

Modified: avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java?rev=1435349&r1=1435348&r2=1435349&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
(original)
+++ avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
Fri Jan 18 21:22:04 2013
@@ -81,7 +81,9 @@ public class SpecificCompiler {
   
   /* Reserved words for accessor/mutator methods */
   private static final Set<String> ACCESSOR_MUTATOR_RESERVED_WORDS = 
-      new HashSet<String>(Arrays.asList(new String[] { "class", "schema" }));
+      new HashSet<String>(Arrays.asList(new String[] {
+            "class", "schema", "classSchema"
+          }));
   static {
     // Add reserved words to accessor/mutator reserved words
     ACCESSOR_MUTATOR_RESERVED_WORDS.addAll(RESERVED_WORDS);

Modified: avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm?rev=1435349&r1=1435348&r2=1435349&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
(original)
+++ avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
Fri Jan 18 21:22:04 2013
@@ -30,4 +30,5 @@ public enum ${this.mangle($schema.getNam
   #foreach ($symbol in ${schema.getEnumSymbols()})${this.mangle($symbol)}#if ($velocityHasNext),
#end#end
   ;
   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("${this.javaEscape($schema.toString())}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
 }

Modified: avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/fixed.vm
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/fixed.vm?rev=1435349&r1=1435348&r2=1435349&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/fixed.vm
(original)
+++ avro/trunk/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/fixed.vm
Fri Jan 18 21:22:04 2013
@@ -29,6 +29,7 @@ package $schema.getNamespace();  
 @org.apache.avro.specific.AvroGenerated
 public class ${this.mangle($schema.getName())} extends org.apache.avro.specific.SpecificFixed
{
   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("${this.javaEscape($schema.toString())}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
   
   /** Creates a new ${this.mangle($schema.getName())} */
   public ${this.mangle($schema.getName())}() {

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=1435349&r1=1435348&r2=1435349&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
Fri Jan 18 21:22:04 2013
@@ -28,6 +28,7 @@ package $schema.getNamespace();  
 @org.apache.avro.specific.AvroGenerated
 public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends org.apache.avro.specific.SpecificExceptionBase#else
extends org.apache.avro.specific.SpecificRecordBase#end implements org.apache.avro.specific.SpecificRecord
{
   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("${this.javaEscape($schema.toString())}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
 #foreach ($field in $schema.getFields())
 #if ($field.doc())
   /** $field.doc() */

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java?rev=1435349&r1=1435348&r2=1435349&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
Fri Jan 18 21:22:04 2013
@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.ArrayList;
 
 import org.junit.Test;
+import org.junit.Assert;
 
 import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericData;
@@ -87,6 +88,11 @@ public class TestSpecificData {
         new SpecificDatumReader<Object>());
 }
 
+  @Test public void testGetClassSchema() throws Exception {
+    Assert.assertEquals(TestRecord.getClassSchema(), TestRecord.SCHEMA$);
+    Assert.assertEquals(MD5.getClassSchema(), MD5.SCHEMA$);
+    Assert.assertEquals(Kind.getClassSchema(), Kind.SCHEMA$);
+  }
 
 
 }



Mime
View raw message