コード例 #1
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNestedNullNamespace() throws Exception {
   Schema inner = Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
   Schema outer = Schema.createRecord("Outer", null, "space", false);
   outer.setFields(Arrays.asList(new Field("f", inner, null, null)));
   assertEquals(outer, Schema.parse(outer.toString()));
 }
コード例 #2
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNullNamespaceAlias() throws Exception {
   Schema s = Schema.parse("{\"type\":\"record\",\"name\":\"Z\",\"fields\":[]}");
   Schema t =
       Schema.parse(
           "{\"type\":\"record\",\"name\":\"x.Y\",\"aliases\":[\".Z\"]," + "\"fields\":[]}");
   Schema u = Schema.applyAliases(s, t);
   assertEquals("x.Y", u.getFullName());
 }
コード例 #3
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testFloat() throws Exception {
   assertEquals(Schema.create(Type.FLOAT), Schema.parse("\"float\""));
   assertEquals(Schema.create(Type.FLOAT), Schema.parse("{\"type\":\"float\"}"));
   check("\"float\"", "1.1", new Float(1.1));
   checkDefault("\"float\"", "\"NaN\"", Float.NaN);
   checkDefault("\"float\"", "\"Infinity\"", Float.POSITIVE_INFINITY);
   checkDefault("\"float\"", "\"-Infinity\"", Float.NEGATIVE_INFINITY);
 }
コード例 #4
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testDouble() throws Exception {
   assertEquals(Schema.create(Type.DOUBLE), Schema.parse("\"double\""));
   assertEquals(Schema.create(Type.DOUBLE), Schema.parse("{\"type\":\"double\"}"));
   check("\"double\"", "1.2", new Double(1.2));
   checkDefault("\"double\"", "\"NaN\"", Double.NaN);
   checkDefault("\"double\"", "\"Infinity\"", Double.POSITIVE_INFINITY);
   checkDefault("\"double\"", "\"-Infinity\"", Double.NEGATIVE_INFINITY);
 }
コード例 #5
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testRecursiveEquals() throws Exception {
   String jsonSchema =
       "{\"type\":\"record\", \"name\":\"List\", \"fields\": ["
           + "{\"name\":\"next\", \"type\":\"List\"}]}";
   Schema s1 = Schema.parse(jsonSchema);
   Schema s2 = Schema.parse(jsonSchema);
   assertEquals(s1, s2);
   s1.hashCode(); // test no stackoverflow
 }
コード例 #6
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNestedNullNamespaceReferencingWithUnion() {
   Schema inner = Schema.parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
   Schema innerUnion = Schema.createUnion(Arrays.asList(inner, Schema.create(Type.NULL)));
   Schema outer = Schema.createRecord("Outer", null, "space", false);
   outer.setFields(
       Arrays.asList(
           new Field("f1", innerUnion, null, null), new Field("f2", innerUnion, null, null)));
   assertEquals(outer, Schema.parse(outer.toString()));
 }
コード例 #7
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNestedNonNullNamespace2() throws Exception {
   Schema inner1 = Schema.createFixed("InnerFixed", null, "space", 1);
   Schema inner2 =
       Schema.parse(
           "{\"type\":\"record\",\"namespace\":\"space\",\"name\":"
               + "\"InnerRecord\",\"fields\":[]}");
   Schema nullOuter = Schema.createRecord("Outer", null, null, false);
   nullOuter.setFields(
       Arrays.asList(new Field("f1", inner1, null, null), new Field("f2", inner2, null, null)));
   assertEquals(nullOuter, Schema.parse(nullOuter.toString()));
 }
コード例 #8
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 private static void checkProp(Schema s0) throws Exception {
   if (s0.getType().equals(Schema.Type.UNION)) return; // unions have no props
   assertEquals(null, s0.getProp("foo"));
   Schema s1 = Schema.parse(s0.toString());
   s1.addProp("foo", "bar");
   assertEquals("bar", s1.getProp("foo"));
   assertFalse(s0.equals(s1));
   Schema s2 = Schema.parse(s1.toString());
   assertEquals("bar", s2.getProp("foo"));
   assertEquals(s1, s2);
   assertFalse(s0.equals(s2));
 }
コード例 #9
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNamespaceNesting() throws Exception {
   String y =
       "{\"type\":\"record\",\"name\":\"y.Y\",\"fields\":["
           + "{\"name\":\"f\",\"type\":\"x.X\"}]}";
   String x =
       "{\"type\":\"record\",\"name\":\"x.X\",\"fields\":["
           + "{\"name\":\"f\",\"type\":"
           + y
           + "}"
           + "]}";
   Schema xs = Schema.parse(x);
   assertEquals(xs, Schema.parse(xs.toString()));
 }
コード例 #10
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  @Test
  public void testFieldDocs() {
    String schemaStr =
        "{\"name\": \"Rec\",\"type\": \"record\",\"fields\" : ["
            + "{\"name\": \"f\", \"type\": \"int\", \"doc\": \"test\"}]}";

    // check field doc is parsed correctly
    Schema schema = Schema.parse(schemaStr);
    assertEquals("test", schema.getField("f").doc());

    // check print/read cycle preserves field doc
    schema = Schema.parse(schema.toString());
    assertEquals("test", schema.getField("f").doc());
  }
コード例 #11
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 /**
  * Test that equals() and hashCode() don't require exponential time on certain pathological
  * schemas.
  */
 public void testSchemaExplosion() throws Exception {
   for (int i = 1; i < 15; i++) { // 15 is big enough to trigger
     // create a list of records, each with a single field whose type is a
     // union of all of the records.
     List<Schema> recs = new ArrayList<Schema>();
     for (int j = 0; j < i; j++)
       recs.add(Schema.createRecord("" + (char) ('A' + j), null, null, false));
     for (Schema s : recs) {
       Schema union = Schema.createUnion(recs);
       Field f = new Field("x", union, null, null);
       List<Field> fields = new ArrayList<Field>();
       fields.add(f);
       s.setFields(fields);
     }
     // check that equals and hashcode are correct and complete in a
     // reasonable amount of time
     for (Schema s1 : recs) {
       Schema s2 = Schema.parse(s1.toString());
       assertEquals(s1.hashCode(), s2.hashCode());
       assertEquals(s1, s2);
     }
   }
 }
コード例 #12
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testFixed() throws Exception {
   String json = "{\"type\": \"fixed\", \"name\":\"Test\", \"size\": 1}";
   Schema schema = Schema.parse(json);
   check(json, "\"a\"", new GenericData.Fixed(schema, new byte[] {(byte) 'a'}), false);
   checkParseError("{\"type\":\"fixed\"}"); // size required
 }
コード例 #13
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 private static void checkParseError(String json) {
   try {
     Schema.parse(json);
   } catch (SchemaParseException e) {
     return;
   }
   fail("Should not have parsed: " + json);
 }
コード例 #14
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 private static void checkDefault(String schemaJson, String defaultJson, Object defaultValue)
     throws Exception {
   String recordJson =
       "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
           + "\"type\":"
           + schemaJson
           + ", "
           + "\"default\":"
           + defaultJson
           + "}]}";
   Schema expected = Schema.parse(recordJson);
   DatumReader<Object> in = new GenericDatumReader<Object>(ACTUAL, expected);
   GenericData.Record record =
       (GenericData.Record) in.read(null, DecoderFactory.get().binaryDecoder(new byte[0], null));
   assertEquals("Wrong default.", defaultValue, record.get("f"));
   assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
 }
コード例 #15
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test(expected = AvroTypeException.class)
 public void testNoDefaultField() throws Exception {
   Schema expected =
       Schema.parse(
           "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":"
               + "[{\"name\":\"f\", \"type\": \"string\"}]}");
   DatumReader<Object> in = new GenericDatumReader<Object>(ACTUAL, expected);
   in.read(null, DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(new byte[0]), null));
 }
コード例 #16
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 /**
  * Makes sure that "doc" tags are transcribed in the schemas. Note that there are docs both for
  * fields and for the records themselves.
  */
 @Test
 public void testDocs() {
   Schema schema = Schema.parse(SCHEMA_WITH_DOC_TAGS);
   assertEquals("This is not a world record.", schema.getDoc());
   assertEquals("Inner Fixed", schema.getField("inner_fixed").doc());
   assertEquals("Very Inner Fixed", schema.getField("inner_fixed").schema().getDoc());
   assertEquals("Inner String", schema.getField("inner_string").doc());
   assertEquals("Inner Enum", schema.getField("inner_enum").doc());
   assertEquals("Very Inner Enum", schema.getField("inner_enum").schema().getDoc());
   assertEquals("Inner Union", schema.getField("inner_union").doc());
 }
コード例 #17
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testEnumMismatch() throws Exception {
   Schema actual = Schema.parse("{\"type\":\"enum\",\"name\":\"E\",\"symbols\":[\"X\",\"Y\"]}");
   Schema expected = Schema.parse("{\"type\":\"enum\",\"name\":\"E\",\"symbols\":[\"Y\",\"Z\"]}");
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   DatumWriter<Object> writer = new GenericDatumWriter<Object>(actual);
   Encoder encoder = EncoderFactory.get().directBinaryEncoder(out, null);
   writer.write(new GenericData.EnumSymbol(actual, "Y"), encoder);
   writer.write(new GenericData.EnumSymbol(actual, "X"), encoder);
   encoder.flush();
   byte[] data = out.toByteArray();
   Decoder decoder = DecoderFactory.get().binaryDecoder(data, null);
   DatumReader<String> in = new GenericDatumReader<String>(actual, expected);
   assertEquals("Wrong value", new GenericData.EnumSymbol(expected, "Y"), in.read(null, decoder));
   try {
     in.read(null, decoder);
     fail("Should have thrown exception.");
   } catch (AvroTypeException e) {
     // expected
   }
 }
コード例 #18
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testArray() throws Exception {
   String json = "{\"type\":\"array\", \"items\": \"long\"}";
   Schema schema = Schema.parse(json);
   Collection<Long> array = new GenericData.Array<Long>(1, schema);
   array.add(1L);
   check(json, "[1]", array);
   array = new ArrayList<Long>(1);
   array.add(1L);
   check(json, "[1]", array);
   checkParseError("{\"type\":\"array\"}"); // items required
 }
コード例 #19
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  @Test
  public void testUnion() throws Exception {
    check("[\"string\", \"long\"]", false);
    checkDefault("[\"double\", \"long\"]", "1.1", new Double(1.1));

    // test that erroneous default values cause errors
    for (String type :
        new String[] {"int", "long", "float", "double", "string", "bytes", "boolean"}) {
      checkValidateDefaults("[\"" + type + "\", \"null\"]", "null"); // schema parse time
      boolean error = false;
      try {
        checkDefault("[\"" + type + "\", \"null\"]", "null", 0); // read time
      } catch (AvroTypeException e) {
        error = true;
      }
      assertTrue(error);
      checkValidateDefaults("[\"null\", \"" + type + "\"]", "0"); // schema parse time
      error = false;
      try {
        checkDefault("[\"null\", \"" + type + "\"]", "0", null); // read time
      } catch (AvroTypeException e) {
        error = true;
      }
      assertTrue(error);
    }

    // check union json
    String record = "{\"type\":\"record\",\"name\":\"Foo\",\"fields\":[]}";
    String fixed = "{\"type\":\"fixed\",\"name\":\"Bar\",\"size\": 1}";
    String enu = "{\"type\":\"enum\",\"name\":\"Baz\",\"symbols\": [\"X\"]}";
    Schema union = Schema.parse("[\"null\",\"string\"," + record + "," + enu + "," + fixed + "]");
    checkJson(union, null, "null");
    checkJson(union, new Utf8("foo"), "{\"string\":\"foo\"}");
    checkJson(union, new GenericData.Record(Schema.parse(record)), "{\"Foo\":{}}");
    checkJson(
        union,
        new GenericData.Fixed(Schema.parse(fixed), new byte[] {(byte) 'a'}),
        "{\"Bar\":\"a\"}");
    checkJson(union, new GenericData.EnumSymbol(Schema.parse(enu), "X"), "{\"Baz\":\"X\"}");
  }
コード例 #20
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  @Test
  public void testMapInRecord() throws Exception {
    String json =
        "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
            + "[{\"name\":\"f\", \"type\": {\"type\":\"map\", \"values\":\"long\"}}]}";
    Schema schema = Schema.parse(json);

    HashMap<Utf8, Long> map = new HashMap<Utf8, Long>();
    map.put(new Utf8("a"), 1L);
    GenericData.Record record = new GenericData.Record(schema);
    record.put("f", map);
    check(json, "{\"f\":{\"a\":1}}", record, false);
  }
コード例 #21
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  @Test
  public void testRecord() throws Exception {
    String recordJson =
        "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
            + "[{\"name\":\"f\", \"type\":\"long\", \"foo\":\"bar\"}]}";
    Schema schema = Schema.parse(recordJson);

    GenericData.Record record = new GenericData.Record(schema);
    record.put("f", 11L);
    check(recordJson, "{\"f\":11}", record, false);

    // test field props
    assertEquals("bar", schema.getField("f").getProp("foo"));
    assertEquals("bar", Schema.parse(schema.toString()).getField("f").getProp("foo"));
    schema.getField("f").addProp("baz", "boo");
    assertEquals("boo", schema.getField("f").getProp("baz"));

    checkParseError("{\"type\":\"record\"}");
    checkParseError("{\"type\":\"record\",\"name\":\"X\"}");
    checkParseError("{\"type\":\"record\",\"name\":\"X\",\"fields\":\"Y\"}");
    checkParseError(
        "{\"type\":\"record\",\"name\":\"X\",\"fields\":" + "[{\"name\":\"f\"}]}"); // no type
    checkParseError(
        "{\"type\":\"record\",\"name\":\"X\",\"fields\":" + "[{\"type\":\"long\"}]}"); // no name
    // check invalid record names
    checkParseError("{\"type\":\"record\",\"name\":\"1X\",\"fields\":[]}");
    checkParseError("{\"type\":\"record\",\"name\":\"X$\",\"fields\":[]}");
    // check invalid field names
    checkParseError(
        "{\"type\":\"record\",\"name\":\"X\",\"fields\":["
            + "{\"name\":\"1f\",\"type\":\"int\"}]}");
    checkParseError(
        "{\"type\":\"record\",\"name\":\"X\",\"fields\":["
            + "{\"name\":\"f$\",\"type\":\"int\"}]}");
    checkParseError(
        "{\"type\":\"record\",\"name\":\"X\",\"fields\":["
            + "{\"name\":\"f.g\",\"type\":\"int\"}]}");
  }
コード例 #22
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNullPointer() throws Exception {
   String recordJson =
       "{\"type\":\"record\", \"name\":\"Test\", \"fields\":"
           + "[{\"name\":\"x\", \"type\":\"string\"}]}";
   Schema schema = Schema.parse(recordJson);
   GenericData.Record record = new GenericData.Record(schema);
   try {
     checkBinary(
         schema, record, new GenericDatumWriter<Object>(), new GenericDatumReader<Object>());
   } catch (NullPointerException e) {
     assertEquals("null of string in field x of Test", e.getMessage());
   }
 }
コード例 #23
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testEnum() throws Exception {
   check(
       BASIC_ENUM_SCHEMA,
       "\"B\"",
       new GenericData.EnumSymbol(Schema.parse(BASIC_ENUM_SCHEMA), "B"),
       false);
   checkParseError("{\"type\":\"enum\"}"); // symbols required
   checkParseError("{\"type\":\"enum\",\"symbols\": [\"X\"]}"); // name reqd
   // check no duplicate symbols
   checkParseError("{\"type\":\"enum\",\"name\":\"X\",\"symbols\":[\"X\",\"X\"]}");
   // check no invalid symbols
   checkParseError("{\"type\":\"enum\",\"name\":\"X\",\"symbols\":[\"1X\"]}");
   checkParseError("{\"type\":\"enum\",\"name\":\"X\",\"symbols\":[\"X$\"]}");
   checkParseError("{\"type\":\"enum\",\"name\":\"X\",\"symbols\":[\"X.Y\"]}");
 }
コード例 #24
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
 @Test
 public void testNamespaceScope() throws Exception {
   String z = "{\"type\":\"record\",\"name\":\"Z\",\"fields\":[]}";
   String y =
       "{\"type\":\"record\",\"name\":\"q.Y\",\"fields\":["
           + "{\"name\":\"f\",\"type\":"
           + z
           + "}]}";
   String x =
       "{\"type\":\"record\",\"name\":\"p.X\",\"fields\":["
           + "{\"name\":\"f\",\"type\":"
           + y
           + "},"
           + "{\"name\":\"g\",\"type\":"
           + z
           + "}"
           + "]}";
   Schema xs = Schema.parse(x);
   Schema ys = xs.getField("f").schema();
   assertEquals("p.Z", xs.getField("g").schema().getFullName());
   assertEquals("q.Z", ys.getField("f").schema().getFullName());
 }
コード例 #25
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  private static void check(String jsonSchema, boolean induce) throws Exception {
    Schema schema = Schema.parse(jsonSchema);
    checkProp(schema);
    Object reuse = null;
    for (Object datum : new RandomData(schema, COUNT)) {

      if (induce) {
        Schema induced = GenericData.get().induce(datum);
        assertEquals("Induced schema does not match.", schema, induced);
      }

      assertTrue(
          "Datum does not validate against schema " + datum,
          GenericData.get().validate(schema, datum));

      checkBinary(
          schema, datum, new GenericDatumWriter<Object>(), new GenericDatumReader<Object>(), null);
      reuse =
          checkBinary(
              schema,
              datum,
              new GenericDatumWriter<Object>(),
              new GenericDatumReader<Object>(),
              reuse);
      checkDirectBinary(
          schema, datum, new GenericDatumWriter<Object>(), new GenericDatumReader<Object>());
      checkBlockingBinary(
          schema, datum, new GenericDatumWriter<Object>(), new GenericDatumReader<Object>());
      checkJson(schema, datum, new GenericDatumWriter<Object>(), new GenericDatumReader<Object>());

      // Check that we can generate the code for every schema we see.
      TestSpecificCompiler.assertCompiles(schema, false);

      // Check that we can read/write the json of every schema we see.
      checkBinaryJson(jsonSchema);
    }
  }
コード例 #26
0
ファイル: TestSchema.java プロジェクト: krschultz/avro
  @Test
  public void testAliases() throws Exception {
    String t1 =
        "{\"type\":\"record\",\"name\":\"a.b\",\"fields\":["
            + "{\"name\":\"f\",\"type\":\"long\"},"
            + "{\"name\":\"h\",\"type\":\"int\"}]}";
    String t2 =
        "{\"type\":\"record\",\"name\":\"x.y\",\"aliases\":[\"a.b\"],"
            + "\"fields\":[{\"name\":\"g\",\"type\":\"long\",\"aliases\":[\"f\"]},"
            + "{\"name\":\"h\",\"type\":\"int\"}]}";
    Schema s1 = Schema.parse(t1);
    Schema s2 = Schema.parse(t2);

    assertEquals(s1.getAliases(), Collections.emptySet());
    assertEquals(s1.getField("f").aliases(), Collections.emptySet());
    assertEquals(s2.getAliases(), Collections.singleton("a.b"));
    assertEquals(s2.getField("g").aliases(), Collections.singleton("f"));

    Schema s3 = Schema.applyAliases(s1, s2);
    assertFalse(s2 == s3);
    assertEquals(s2, s3);

    t1 = "{\"type\":\"enum\",\"name\":\"a.b\"," + "\"symbols\":[\"x\"]}";
    t2 = "{\"type\":\"enum\",\"name\":\"a.c\",\"aliases\":[\"b\"]," + "\"symbols\":[\"x\"]}";
    s1 = Schema.parse(t1);
    s2 = Schema.parse(t2);
    s3 = Schema.applyAliases(s1, s2);
    assertFalse(s2 == s3);
    assertEquals(s2, s3);

    t1 = "{\"type\":\"fixed\",\"name\":\"a\"," + "\"size\": 5}";
    t2 = "{\"type\":\"fixed\",\"name\":\"b\",\"aliases\":[\"a\"]," + "\"size\": 5}";
    s1 = Schema.parse(t1);
    s2 = Schema.parse(t2);
    s3 = Schema.applyAliases(s1, s2);
    assertFalse(s2 == s3);
    assertEquals(s2, s3);
  }
コード例 #27
0
@SuppressWarnings("all")
public class TestSerializerSample extends SpecificRecordBase implements SpecificRecord {
  private static final long serialVersionUID = 1L;

  public static final Schema SCHEMA =
      Schema.parse(
          "{\"type\":\"record\",\"name\":\"TestSerializerSample\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"int1\",\"type\":[\"int\",\"null\"]},{\"name\":\"tinyint1\",\"type\":[\"int\",\"null\"]},{\"name\":\"smallint1\",\"type\":[\"int\",\"null\"]},{\"name\":\"bigint1\",\"type\":[\"long\",\"null\"]},{\"name\":\"boolean1\",\"type\":[\"boolean\",\"null\"]},{\"name\":\"double1\",\"type\":[\"double\",\"null\"]},{\"name\":\"string1\",\"type\":[\"string\",\"null\"]},{\"name\":\"record\",\"type\":[{\"type\":\"record\",\"name\":\"Record\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"sInt\",\"type\":[\"int\",\"null\"]},{\"name\":\"sBoolean\",\"type\":[\"boolean\",\"null\"]},{\"name\":\"sString\",\"type\":[\"string\",\"null\"]}]},\"null\"]},{\"name\":\"list1\",\"type\":[{\"type\":\"array\",\"items\":\"string\"},\"null\"]},{\"name\":\"map1\",\"type\":[{\"type\":\"map\",\"values\":\"int\"},\"null\"]},{\"name\":\"enum1\",\"type\":[{\"type\":\"enum\",\"name\":\"Enum1Values\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"symbols\":[\"BLUE\",\"RED\",\"GREEN\"]},\"null\"]},{\"name\":\"nullableint\",\"type\":[\"int\",\"null\"]},{\"name\":\"bytes1\",\"type\":[\"bytes\",\"null\"]},{\"name\":\"container1\",\"type\":[{\"type\":\"record\",\"name\":\"Record2Container\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"record2list\",\"type\":[{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Record2\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"enum2\",\"type\":[{\"type\":\"enum\",\"name\":\"Enum2Values\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"symbols\":[\"CAR\",\"BIKE\",\"PLANE\"]},\"null\"]},{\"name\":\"bigint2\",\"type\":[\"long\",\"null\"]},{\"name\":\"nullablebigint\",\"type\":[\"long\",\"null\"]},{\"name\":\"list2\",\"type\":[{\"type\":\"array\",\"items\":\"int\"},\"null\"]},{\"name\":\"map2\",\"type\":[{\"type\":\"map\",\"values\":\"Record\"},\"null\"]},{\"name\":\"byteslist\",\"type\":[{\"type\":\"array\",\"items\":\"bytes\"},\"null\"]},{\"name\":\"filling\",\"type\":[{\"type\":\"record\",\"name\":\"ModelFilling\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"stringfilling1\",\"type\":[\"string\",\"null\"]},{\"name\":\"stringfilling2\",\"type\":[\"string\",\"null\"]},{\"name\":\"stringfilling3\",\"type\":[\"string\",\"null\"]},{\"name\":\"stringfilling4\",\"type\":[\"string\",\"null\"]},{\"name\":\"intfilling\",\"type\":[\"int\",\"null\"]},{\"name\":\"boolfilling\",\"type\":[\"boolean\",\"null\"]},{\"name\":\"modelfilling\",\"type\":[{\"type\":\"record\",\"name\":\"ModelFilling2\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"longfilling\",\"type\":[\"long\",\"null\"]},{\"name\":\"stringfilling\",\"type\":[\"string\",\"null\"]},{\"name\":\"listfilling\",\"type\":[{\"type\":\"array\",\"items\":\"string\"},\"null\"]},{\"name\":\"enumfilling\",\"type\":[\"Enum2Values\",\"null\"]}]},\"null\"]},{\"name\":\"modelfilling3\",\"type\":[{\"type\":\"record\",\"name\":\"ModelFilling3\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.crosstest\",\"doc\":null,\"fields\":[{\"name\":\"intfilling\",\"type\":[\"int\",\"null\"]},{\"name\":\"doublefilling\",\"type\":[\"double\",\"null\"]}]},\"null\"]},{\"name\":\"enumfilling\",\"type\":[\"Enum1Values\",\"null\"]}]},\"null\"]}]}},\"null\"]}]},\"null\"]},{\"name\":\"innerSample\",\"type\":[\"TestSerializerSample\",\"null\"]}]}");

  @Override
  public Schema getSchema() {
    return SCHEMA;
  }

  public TestSerializerSample(
      Integer int1,
      Integer tinyint1,
      Integer smallint1,
      Long bigint1,
      Boolean boolean1,
      Double double1,
      String string1,
      Record record,
      List<String> list1,
      Map<String, Integer> map1,
      Enum1Values enum1,
      Integer nullableint,
      byte[] bytes1,
      Record2Container container1,
      TestSerializerSample innerSample) {
    this.int1 = int1;
    this.tinyint1 = tinyint1;
    this.smallint1 = smallint1;
    this.bigint1 = bigint1;
    this.boolean1 = boolean1;
    this.double1 = double1;
    this.string1 = string1;
    this.record = record;
    this.list1 = list1;
    this.map1 = map1;
    this.enum1 = enum1;
    this.nullableint = nullableint;
    this.bytes1 = bytes1;
    this.container1 = container1;
    this.innerSample = innerSample;
  }

  public TestSerializerSample() {}

  public Integer int1;

  public Integer tinyint1;

  public Integer smallint1;

  public Long bigint1;

  public Boolean boolean1;

  public Double double1;

  public String string1;

  public Record record;

  public List<String> list1;

  public Map<String, Integer> map1;

  public Enum1Values enum1;

  public Integer nullableint;

  public byte[] bytes1;

  public Record2Container container1;

  public TestSerializerSample innerSample;

  public Integer getInt1() {
    return int1;
  }

  public void setInt1(final Integer int1) {
    this.int1 = int1;
  }

  public Integer getTinyint1() {
    return tinyint1;
  }

  public void setTinyint1(final Integer tinyint1) {
    this.tinyint1 = tinyint1;
  }

  public Integer getSmallint1() {
    return smallint1;
  }

  public void setSmallint1(final Integer smallint1) {
    this.smallint1 = smallint1;
  }

  public Long getBigint1() {
    return bigint1;
  }

  public void setBigint1(final Long bigint1) {
    this.bigint1 = bigint1;
  }

  public Boolean isBoolean1() {
    return boolean1;
  }

  public void setBoolean1(final Boolean boolean1) {
    this.boolean1 = boolean1;
  }

  public Double getDouble1() {
    return double1;
  }

  public void setDouble1(final Double double1) {
    this.double1 = double1;
  }

  public String getString1() {
    return string1;
  }

  public void setString1(final String string1) {
    this.string1 = string1;
  }

  public Record getRecord() {
    return record;
  }

  public void setRecord(final Record record) {
    this.record = record;
  }

  public List<String> getList1() {
    return list1;
  }

  public void setList1(final List<String> list1) {
    this.list1 = list1;
  }

  public Map<String, Integer> getMap1() {
    return map1;
  }

  public void setMap1(final Map<String, Integer> map1) {
    this.map1 = map1;
  }

  public Enum1Values getEnum1() {
    return enum1;
  }

  public void setEnum1(final Enum1Values enum1) {
    this.enum1 = enum1;
  }

  public Integer getNullableint() {
    return nullableint;
  }

  public void setNullableint(final Integer nullableint) {
    this.nullableint = nullableint;
  }

  public byte[] getBytes1() {
    return bytes1;
  }

  public void setBytes1(final byte[] bytes1) {
    this.bytes1 = bytes1;
  }

  public Record2Container getContainer1() {
    return container1;
  }

  public void setContainer1(final Record2Container container1) {
    this.container1 = container1;
  }

  public TestSerializerSample getInnerSample() {
    return innerSample;
  }

  public void setInnerSample(final TestSerializerSample innerSample) {
    this.innerSample = innerSample;
  }

  // Used by DatumWriter. Applications should not call.
  public java.lang.Object get(int fieldPos) {
    switch (fieldPos) {
      case 0:
        return this.int1;
      case 1:
        return this.tinyint1;
      case 2:
        return this.smallint1;
      case 3:
        return this.bigint1;
      case 4:
        return this.boolean1;
      case 5:
        return this.double1;
      case 6:
        return this.string1;
      case 7:
        return this.record;
      case 8:
        return this.list1;
      case 9:
        return this.map1;
      case 10:
        return this.enum1;
      case 11:
        return this.nullableint;
      case 12:
        return this.bytes1;
      case 13:
        return this.container1;
      case 14:
        return this.innerSample;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in get()");
    }
  }

  // Used by DatumReader. Applications should not call.
  @SuppressWarnings(value = "unchecked")
  public void put(int fieldPos, java.lang.Object fieldValue) {
    switch (fieldPos) {
      case 0:
        this.int1 = (Integer) fieldValue;
        break;
      case 1:
        this.tinyint1 = (Integer) fieldValue;
        break;
      case 2:
        this.smallint1 = (Integer) fieldValue;
        break;
      case 3:
        this.bigint1 = (Long) fieldValue;
        break;
      case 4:
        this.boolean1 = (Boolean) fieldValue;
        break;
      case 5:
        this.double1 = (Double) fieldValue;
        break;
      case 6:
        this.string1 = (String) fieldValue;
        break;
      case 7:
        this.record = (Record) fieldValue;
        break;
      case 8:
        this.list1 = (List<String>) fieldValue;
        break;
      case 9:
        this.map1 = (Map<String, Integer>) fieldValue;
        break;
      case 10:
        this.enum1 = (Enum1Values) fieldValue;
        break;
      case 11:
        this.nullableint = (Integer) fieldValue;
        break;
      case 12:
        this.bytes1 = (byte[]) fieldValue;
        break;
      case 13:
        this.container1 = (Record2Container) fieldValue;
        break;
      case 14:
        this.innerSample = (TestSerializerSample) fieldValue;
        break;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in put()");
    }
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;

    final TestSerializerSample other = (TestSerializerSample) obj;
    return Objects.equal(this.int1, other.int1)
        && Objects.equal(this.tinyint1, other.tinyint1)
        && Objects.equal(this.smallint1, other.smallint1)
        && Objects.equal(this.bigint1, other.bigint1)
        && Objects.equal(this.boolean1, other.boolean1)
        && Objects.equal(this.double1, other.double1)
        && Objects.equal(this.string1, other.string1)
        && Objects.equal(this.record, other.record)
        && Objects.equal(this.list1, other.list1)
        && Objects.equal(this.map1, other.map1)
        && Objects.equal(this.enum1, other.enum1)
        && Objects.equal(this.nullableint, other.nullableint)
        && Arrays.equals(this.bytes1, other.bytes1)
        && Objects.equal(this.container1, other.container1)
        && Objects.equal(this.innerSample, other.innerSample);
  }

  @Override
  public int hashCode() {
    int result = 1;

    result = 31 * result + (this.int1 == null ? 0 : this.int1.hashCode());
    result = 31 * result + (this.tinyint1 == null ? 0 : this.tinyint1.hashCode());
    result = 31 * result + (this.smallint1 == null ? 0 : this.smallint1.hashCode());
    result = 31 * result + (this.bigint1 == null ? 0 : this.bigint1.hashCode());
    result = 31 * result + (this.boolean1 == null ? 0 : this.boolean1.hashCode());
    result = 31 * result + (this.double1 == null ? 0 : this.double1.hashCode());
    result = 31 * result + (this.string1 == null ? 0 : this.string1.hashCode());
    result = 31 * result + (this.record == null ? 0 : this.record.hashCode());
    result = 31 * result + (this.list1 == null ? 0 : this.list1.hashCode());
    result = 31 * result + (this.map1 == null ? 0 : this.map1.hashCode());
    result = 31 * result + (this.enum1 == null ? 0 : this.enum1.hashCode());
    result = 31 * result + (this.nullableint == null ? 0 : this.nullableint.hashCode());
    result = 31 * result + (this.bytes1 == null ? 0 : Arrays.hashCode(this.bytes1));
    result = 31 * result + (this.container1 == null ? 0 : this.container1.hashCode());
    result = 31 * result + (this.innerSample == null ? 0 : this.innerSample.hashCode());

    return result;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("int1", int1)
        .add("tinyint1", tinyint1)
        .add("smallint1", smallint1)
        .add("bigint1", bigint1)
        .add("boolean1", boolean1)
        .add("double1", double1)
        .add("string1", string1)
        .add("record", record)
        .add("list1", list1)
        .add("map1", map1)
        .add("enum1", enum1)
        .add("nullableint", nullableint)
        .add("bytes1", bytes1)
        .add("container1", container1)
        .add("innerSample", innerSample)
        .toString();
  }
}
コード例 #28
0
/**
 * Shows the pagination data for the item search. Child elements include the page number returned,
 * the maximum entries returned per page, the total number of pages that can be returned, and the
 * total number of items that match the search criteria.
 */
@SuppressWarnings("all")
public class PaginationOutputType extends SpecificRecordBase implements SpecificRecord {
  private static final long serialVersionUID = 1L;

  public static final Schema SCHEMA =
      Schema.parse(
          "{\"type\":\"record\",\"name\":\"PaginationOutputType\",\"namespace\":\"com.ctriposs.baiji.rpc.common.types\",\"doc\":null,\"fields\":[{\"name\":\"pageNumber\",\"type\":[\"int\",\"null\"]},{\"name\":\"entriesPerPage\",\"type\":[\"int\",\"null\"]},{\"name\":\"totalPages\",\"type\":[\"int\",\"null\"]},{\"name\":\"totalEntries\",\"type\":[\"int\",\"null\"]}]}");

  @Override
  public Schema getSchema() {
    return SCHEMA;
  }

  public PaginationOutputType(
      Integer pageNumber, Integer entriesPerPage, Integer totalPages, Integer totalEntries) {
    this.pageNumber = pageNumber;
    this.entriesPerPage = entriesPerPage;
    this.totalPages = totalPages;
    this.totalEntries = totalEntries;
  }

  public PaginationOutputType() {}

  /**
   * The subset of item data returned in the current response. Search results are divided into sets,
   * or "pages," of item data. The number of pages is equal to the total number of items matching
   * the search criteria divided by the value specified for entriesPerPage in the request. The
   * response for a request contains one "page" of item data. This returned value indicates the page
   * number of item data returned (a subset of the complete result set). If this field contains 1,
   * the response contains the first page of item data (the default). If the value returned in
   * totalEntries is less than the value for entriesPerPage, pageNumber returns 1 and the response
   * contains the entire result set. The value of pageNumber is normally equal to the value input
   * for paginationInput.pageNumber. However, if the number input for pageNumber is greater than the
   * total possible pages of output, Baiji returns the last page of item data in the result set, and
   * the value for pageNumber is set to the respective (last) page number.
   */
  public Integer pageNumber;

  /**
   * The maximum number of items that can be returned in the response. This number is always equal
   * to the value input for paginationInput.entriesPerPage. The end of the result set has been
   * reached if the number specified for entriesPerPage is greater than the number of items found on
   * the specified pageNumber. In this case, there will be fewer items returned than the number
   * specified in entriesPerPage. This can be determined by comparing the entriesPerPage value with
   * the value returned in the count attribute for the searchResult field.
   */
  public Integer entriesPerPage;

  /**
   * The total number of pages of data that could be returned by repeated search requests. Note that
   * if you modify the value of inputPagination.entriesPerPage in a request, the value output for
   * totalPages will change. A value of "0" is returned if service does not find any items that
   * match the search criteria.
   */
  public Integer totalPages;

  /**
   * The total number of items found that match the search criteria in your request. Depending on
   * the input value for entriesPerPage, the response might include only a portion (a page) of the
   * entire result set. A value of "0" is returned if service does not find any items that match the
   * search criteria.
   */
  public Integer totalEntries;

  /**
   * The subset of item data returned in the current response. Search results are divided into sets,
   * or "pages," of item data. The number of pages is equal to the total number of items matching
   * the search criteria divided by the value specified for entriesPerPage in the request. The
   * response for a request contains one "page" of item data. This returned value indicates the page
   * number of item data returned (a subset of the complete result set). If this field contains 1,
   * the response contains the first page of item data (the default). If the value returned in
   * totalEntries is less than the value for entriesPerPage, pageNumber returns 1 and the response
   * contains the entire result set. The value of pageNumber is normally equal to the value input
   * for paginationInput.pageNumber. However, if the number input for pageNumber is greater than the
   * total possible pages of output, Baiji returns the last page of item data in the result set, and
   * the value for pageNumber is set to the respective (last) page number.
   */
  public Integer getPageNumber() {
    return pageNumber;
  }

  /**
   * The subset of item data returned in the current response. Search results are divided into sets,
   * or "pages," of item data. The number of pages is equal to the total number of items matching
   * the search criteria divided by the value specified for entriesPerPage in the request. The
   * response for a request contains one "page" of item data. This returned value indicates the page
   * number of item data returned (a subset of the complete result set). If this field contains 1,
   * the response contains the first page of item data (the default). If the value returned in
   * totalEntries is less than the value for entriesPerPage, pageNumber returns 1 and the response
   * contains the entire result set. The value of pageNumber is normally equal to the value input
   * for paginationInput.pageNumber. However, if the number input for pageNumber is greater than the
   * total possible pages of output, Baiji returns the last page of item data in the result set, and
   * the value for pageNumber is set to the respective (last) page number.
   */
  public void setPageNumber(final Integer pageNumber) {
    this.pageNumber = pageNumber;
  }

  /**
   * The maximum number of items that can be returned in the response. This number is always equal
   * to the value input for paginationInput.entriesPerPage. The end of the result set has been
   * reached if the number specified for entriesPerPage is greater than the number of items found on
   * the specified pageNumber. In this case, there will be fewer items returned than the number
   * specified in entriesPerPage. This can be determined by comparing the entriesPerPage value with
   * the value returned in the count attribute for the searchResult field.
   */
  public Integer getEntriesPerPage() {
    return entriesPerPage;
  }

  /**
   * The maximum number of items that can be returned in the response. This number is always equal
   * to the value input for paginationInput.entriesPerPage. The end of the result set has been
   * reached if the number specified for entriesPerPage is greater than the number of items found on
   * the specified pageNumber. In this case, there will be fewer items returned than the number
   * specified in entriesPerPage. This can be determined by comparing the entriesPerPage value with
   * the value returned in the count attribute for the searchResult field.
   */
  public void setEntriesPerPage(final Integer entriesPerPage) {
    this.entriesPerPage = entriesPerPage;
  }

  /**
   * The total number of pages of data that could be returned by repeated search requests. Note that
   * if you modify the value of inputPagination.entriesPerPage in a request, the value output for
   * totalPages will change. A value of "0" is returned if service does not find any items that
   * match the search criteria.
   */
  public Integer getTotalPages() {
    return totalPages;
  }

  /**
   * The total number of pages of data that could be returned by repeated search requests. Note that
   * if you modify the value of inputPagination.entriesPerPage in a request, the value output for
   * totalPages will change. A value of "0" is returned if service does not find any items that
   * match the search criteria.
   */
  public void setTotalPages(final Integer totalPages) {
    this.totalPages = totalPages;
  }

  /**
   * The total number of items found that match the search criteria in your request. Depending on
   * the input value for entriesPerPage, the response might include only a portion (a page) of the
   * entire result set. A value of "0" is returned if service does not find any items that match the
   * search criteria.
   */
  public Integer getTotalEntries() {
    return totalEntries;
  }

  /**
   * The total number of items found that match the search criteria in your request. Depending on
   * the input value for entriesPerPage, the response might include only a portion (a page) of the
   * entire result set. A value of "0" is returned if service does not find any items that match the
   * search criteria.
   */
  public void setTotalEntries(final Integer totalEntries) {
    this.totalEntries = totalEntries;
  }

  // Used by DatumWriter. Applications should not call.
  public java.lang.Object get(int fieldPos) {
    switch (fieldPos) {
      case 0:
        return this.pageNumber;
      case 1:
        return this.entriesPerPage;
      case 2:
        return this.totalPages;
      case 3:
        return this.totalEntries;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in get()");
    }
  }

  // Used by DatumReader. Applications should not call.
  @SuppressWarnings(value = "unchecked")
  public void put(int fieldPos, java.lang.Object fieldValue) {
    switch (fieldPos) {
      case 0:
        this.pageNumber = (Integer) fieldValue;
        break;
      case 1:
        this.entriesPerPage = (Integer) fieldValue;
        break;
      case 2:
        this.totalPages = (Integer) fieldValue;
        break;
      case 3:
        this.totalEntries = (Integer) fieldValue;
        break;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in put()");
    }
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;

    final PaginationOutputType other = (PaginationOutputType) obj;
    return Objects.equal(this.pageNumber, other.pageNumber)
        && Objects.equal(this.entriesPerPage, other.entriesPerPage)
        && Objects.equal(this.totalPages, other.totalPages)
        && Objects.equal(this.totalEntries, other.totalEntries);
  }

  @Override
  public int hashCode() {
    int result = 1;

    result = 31 * result + (this.pageNumber == null ? 0 : this.pageNumber.hashCode());
    result = 31 * result + (this.entriesPerPage == null ? 0 : this.entriesPerPage.hashCode());
    result = 31 * result + (this.totalPages == null ? 0 : this.totalPages.hashCode());
    result = 31 * result + (this.totalEntries == null ? 0 : this.totalEntries.hashCode());

    return result;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("pageNumber", pageNumber)
        .add("entriesPerPage", entriesPerPage)
        .add("totalPages", totalPages)
        .add("totalEntries", totalEntries)
        .toString();
  }
}
コード例 #29
0
@SuppressWarnings("all")
public class AddMessageRequestType extends SpecificRecordBase implements SpecificRecord {
  private static final long serialVersionUID = 1L;

  public static final Schema SCHEMA =
      Schema.parse(
          "{\"type\":\"record\",\"name\":\"AddMessageRequestType\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.message\",\"doc\":null,\"fields\":[{\"name\":\"message\",\"type\":[{\"type\":\"record\",\"name\":\"Message\",\"namespace\":\"com.ctriposs.baiji.rpc.samples.message\",\"doc\":null,\"fields\":[{\"name\":\"content\",\"type\":[\"string\",\"null\"]},{\"name\":\"author\",\"type\":[\"string\",\"null\"]},{\"name\":\"createdTime\",\"type\":[\"datetime\",\"null\"]}]},\"null\"]}]}");

  @Override
  public Schema getSchema() {
    return SCHEMA;
  }

  public AddMessageRequestType(Message message) {
    this.message = message;
  }

  public AddMessageRequestType() {}

  public Message message;

  public Message getMessage() {
    return message;
  }

  public void setMessage(final Message message) {
    this.message = message;
  }

  // Used by DatumWriter. Applications should not call.
  public Object get(int fieldPos) {
    switch (fieldPos) {
      case 0:
        return this.message;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in get()");
    }
  }

  // Used by DatumReader. Applications should not call.
  @SuppressWarnings(value = "unchecked")
  public void put(int fieldPos, Object fieldValue) {
    switch (fieldPos) {
      case 0:
        this.message = (Message) fieldValue;
        break;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in put()");
    }
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;

    final AddMessageRequestType other = (AddMessageRequestType) obj;
    return Objects.equal(this.message, other.message);
  }

  @Override
  public int hashCode() {
    int result = 1;

    result = 31 * result + (this.message == null ? 0 : this.message.hashCode());

    return result;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this).add("message", message).toString();
  }
}
コード例 #30
0
ファイル: ErrorDataType.java プロジェクト: xiongs/baiji4j
/** This is service, validation or framework-level error. */
@SuppressWarnings("all")
public class ErrorDataType extends SpecificRecordBase implements SpecificRecord {
  private static final long serialVersionUID = 1L;

  public static final Schema SCHEMA =
      Schema.parse(
          "{\"type\":\"record\",\"name\":\"ErrorDataType\",\"namespace\":\"com.ctriposs.baiji.rpc.common.types\",\"doc\":null,\"fields\":[{\"name\":\"message\",\"type\":[\"string\",\"null\"]},{\"name\":\"errorCode\",\"type\":[\"string\",\"null\"]},{\"name\":\"stackTrace\",\"type\":[\"string\",\"null\"]},{\"name\":\"severityCode\",\"type\":[{\"type\":\"enum\",\"name\":\"SeverityCodeType\",\"namespace\":\"com.ctriposs.baiji.rpc.common.types\",\"doc\":null,\"symbols\":[\"ERROR\",\"WARNING\"]},\"null\"]},{\"name\":\"errorFields\",\"type\":[{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"ErrorFieldType\",\"namespace\":\"com.ctriposs.baiji.rpc.common.types\",\"doc\":null,\"fields\":[{\"name\":\"fieldName\",\"type\":[\"string\",\"null\"]},{\"name\":\"errorCode\",\"type\":[\"string\",\"null\"]},{\"name\":\"message\",\"type\":[\"string\",\"null\"]}]}},\"null\"]},{\"name\":\"errorClassification\",\"type\":[{\"type\":\"enum\",\"name\":\"ErrorClassificationCodeType\",\"namespace\":\"com.ctriposs.baiji.rpc.common.types\",\"doc\":null,\"symbols\":[\"SERVICE_ERROR\",\"VALIDATION_ERROR\",\"FRAMEWORK_ERROR\",\"SLAERROR\",\"SECURITY_ERROR\"]},\"null\"]}]}");

  @Override
  public Schema getSchema() {
    return SCHEMA;
  }

  public ErrorDataType(
      String message,
      String errorCode,
      String stackTrace,
      SeverityCodeType severityCode,
      List<ErrorFieldType> errorFields,
      ErrorClassificationCodeType errorClassification) {
    this.message = message;
    this.errorCode = errorCode;
    this.stackTrace = stackTrace;
    this.severityCode = severityCode;
    this.errorFields = errorFields;
    this.errorClassification = errorClassification;
  }

  public ErrorDataType() {}

  /** A brief description of the condition that raised the error. */
  public String message;

  /** A unique code that identifies the particular error condition that occurred. */
  public String errorCode;

  /** StackTrace of exception causing this error, only used in debug mode. */
  public String stackTrace;

  /**
   * Indicates whether the reported problem is fatal (an error) or is less- severe (a warning).
   * Review the error message details for information on the cause.
   */
  public SeverityCodeType severityCode;

  /**
   * Some warning and error messages return one or more variables that contain contextual
   * information about the error. This is often the field or value that triggered the error.
   */
  public List<ErrorFieldType> errorFields;

  /**
   * API errors are divided between three classes: service errors, validation errors and framework
   * errors.
   */
  public ErrorClassificationCodeType errorClassification;

  /** A brief description of the condition that raised the error. */
  public String getMessage() {
    return message;
  }

  /** A brief description of the condition that raised the error. */
  public void setMessage(final String message) {
    this.message = message;
  }

  /** A unique code that identifies the particular error condition that occurred. */
  public String getErrorCode() {
    return errorCode;
  }

  /** A unique code that identifies the particular error condition that occurred. */
  public void setErrorCode(final String errorCode) {
    this.errorCode = errorCode;
  }

  /** StackTrace of exception causing this error, only used in debug mode. */
  public String getStackTrace() {
    return stackTrace;
  }

  /** StackTrace of exception causing this error, only used in debug mode. */
  public void setStackTrace(final String stackTrace) {
    this.stackTrace = stackTrace;
  }

  /**
   * Indicates whether the reported problem is fatal (an error) or is less- severe (a warning).
   * Review the error message details for information on the cause.
   */
  public SeverityCodeType getSeverityCode() {
    return severityCode;
  }

  /**
   * Indicates whether the reported problem is fatal (an error) or is less- severe (a warning).
   * Review the error message details for information on the cause.
   */
  public void setSeverityCode(final SeverityCodeType severityCode) {
    this.severityCode = severityCode;
  }

  /**
   * Some warning and error messages return one or more variables that contain contextual
   * information about the error. This is often the field or value that triggered the error.
   */
  public List<ErrorFieldType> getErrorFields() {
    return errorFields;
  }

  /**
   * Some warning and error messages return one or more variables that contain contextual
   * information about the error. This is often the field or value that triggered the error.
   */
  public void setErrorFields(final List<ErrorFieldType> errorFields) {
    this.errorFields = errorFields;
  }

  /**
   * API errors are divided between three classes: service errors, validation errors and framework
   * errors.
   */
  public ErrorClassificationCodeType getErrorClassification() {
    return errorClassification;
  }

  /**
   * API errors are divided between three classes: service errors, validation errors and framework
   * errors.
   */
  public void setErrorClassification(final ErrorClassificationCodeType errorClassification) {
    this.errorClassification = errorClassification;
  }

  // Used by DatumWriter. Applications should not call.
  public java.lang.Object get(int fieldPos) {
    switch (fieldPos) {
      case 0:
        return this.message;
      case 1:
        return this.errorCode;
      case 2:
        return this.stackTrace;
      case 3:
        return this.severityCode;
      case 4:
        return this.errorFields;
      case 5:
        return this.errorClassification;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in get()");
    }
  }

  // Used by DatumReader. Applications should not call.
  @SuppressWarnings(value = "unchecked")
  public void put(int fieldPos, java.lang.Object fieldValue) {
    switch (fieldPos) {
      case 0:
        this.message = (String) fieldValue;
        break;
      case 1:
        this.errorCode = (String) fieldValue;
        break;
      case 2:
        this.stackTrace = (String) fieldValue;
        break;
      case 3:
        this.severityCode = (SeverityCodeType) fieldValue;
        break;
      case 4:
        this.errorFields = (List<ErrorFieldType>) fieldValue;
        break;
      case 5:
        this.errorClassification = (ErrorClassificationCodeType) fieldValue;
        break;
      default:
        throw new BaijiRuntimeException("Bad index " + fieldPos + " in put()");
    }
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;

    final ErrorDataType other = (ErrorDataType) obj;
    return Objects.equal(this.message, other.message)
        && Objects.equal(this.errorCode, other.errorCode)
        && Objects.equal(this.stackTrace, other.stackTrace)
        && Objects.equal(this.severityCode, other.severityCode)
        && Objects.equal(this.errorFields, other.errorFields)
        && Objects.equal(this.errorClassification, other.errorClassification);
  }

  @Override
  public int hashCode() {
    int result = 1;

    result = 31 * result + (this.message == null ? 0 : this.message.hashCode());
    result = 31 * result + (this.errorCode == null ? 0 : this.errorCode.hashCode());
    result = 31 * result + (this.stackTrace == null ? 0 : this.stackTrace.hashCode());
    result = 31 * result + (this.severityCode == null ? 0 : this.severityCode.hashCode());
    result = 31 * result + (this.errorFields == null ? 0 : this.errorFields.hashCode());
    result =
        31 * result + (this.errorClassification == null ? 0 : this.errorClassification.hashCode());

    return result;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("message", message)
        .add("errorCode", errorCode)
        .add("stackTrace", stackTrace)
        .add("severityCode", severityCode)
        .add("errorFields", errorFields)
        .add("errorClassification", errorClassification)
        .toString();
  }
}