Skip to content

Commit

Permalink
AVRO-3048: Use SpecificRecord's MODEL$ in builder creation (apache#1206)
Browse files Browse the repository at this point in the history
* AVRO-3048: Use SpecificRecord's MODEL$ in builder creation

* AVRO-3048: fix formatting of code templates
  • Loading branch information
unchuckable authored May 4, 2021
1 parent 6987101 commit 1034773
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ protected SpecificErrorBuilderBase(Schema schema) {
super(schema, SpecificData.get());
}

/**
* Creates a SpecificErrorBuilderBase for building errors of the given type.
*
* @param schema the schema associated with the error class.
* @param model the SpecificData instance associated with the error class
*/
protected SpecificErrorBuilderBase(Schema schema, SpecificData model) {
super(schema, model);
}

/**
* SpecificErrorBuilderBase copy constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ protected SpecificRecordBuilderBase(Schema schema) {
super(schema, SpecificData.getForSchema(schema));
}

/**
* Creates a SpecificRecordBuilderBase for building records of the given type.
*
* @param schema the schema associated with the record class.
* @param model the SpecificData associated with the specific record class
*/
protected SpecificRecordBuilderBase(Schema schema, SpecificData model) {
super(schema, model);
}

/**
* SpecificRecordBuilderBase copy constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static {

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -338,7 +338,7 @@ static {
*/
private Builder(#if ($schema.getNamespace())$this.mangle($schema.getNamespace()).#end${this.mangle($schema.getName())} other) {
#if ($schema.isError()) super(other)#else
super(SCHEMA$)#end;
super(SCHEMA$, MODEL$)#end;
#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())});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -350,7 +350,7 @@ private Builder(avro.examples.baseball.FieldTest.Builder other) {
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.FieldTest other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.number)) {
this.number = data().deepCopy(fields()[0].schema(), other.number);
fieldSetFlags()[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -274,7 +274,7 @@ private Builder(avro.examples.baseball.Player.Builder other) {
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.Player other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.number)) {
this.number = data().deepCopy(fields()[0].schema(), other.number);
fieldSetFlags()[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public interface Callback extends Proto {
*/
void bar(org.apache.avro.ipc.Callback<java.lang.Void> callback) throws java.io.IOException;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand All @@ -231,7 +231,7 @@ private Builder(avro.examples.baseball.AddExtraOptionalGettersTest.Builder other
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.AddExtraOptionalGettersTest other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.name)) {
this.name = data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
Expand Down
4 changes: 2 additions & 2 deletions lang/java/tools/src/test/compiler/output/NoSettersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand All @@ -203,7 +203,7 @@ private Builder(avro.examples.baseball.NoSettersTest.Builder other) {
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.NoSettersTest other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.name)) {
this.name = data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -271,7 +271,7 @@ private Builder(avro.examples.baseball.OptionalGettersAllFieldsTest.Builder othe
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.OptionalGettersAllFieldsTest other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.name)) {
this.name = data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -271,7 +271,7 @@ private Builder(avro.examples.baseball.OptionalGettersNullableFieldsTest.Builder
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.OptionalGettersNullableFieldsTest other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.name)) {
this.name = data().deepCopy(fields()[0].schema(), other.name);
fieldSetFlags()[0] = true;
Expand Down
4 changes: 2 additions & 2 deletions lang/java/tools/src/test/compiler/output/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static class Builder extends org.apache.avro.specific.SpecificRecordBuild

/** Creates a new Builder */
private Builder() {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
}

/**
Expand Down Expand Up @@ -274,7 +274,7 @@ private Builder(avro.examples.baseball.Player.Builder other) {
* @param other The existing instance to copy.
*/
private Builder(avro.examples.baseball.Player other) {
super(SCHEMA$);
super(SCHEMA$, MODEL$);
if (isValidValue(fields()[0], other.number)) {
this.number = data().deepCopy(fields()[0].schema(), other.number);
fieldSetFlags()[0] = true;
Expand Down

0 comments on commit 1034773

Please sign in to comment.