Chapter 8. Avro Bindings

Table of Contents

Avro Bindings Overview
Generic Binding
Using a Single Generic Schema Binding
Using Multiple Generic Schema Bindings
Using Embedded Records
Managing Generic Schemas Dynamically
Specific Binding
Generating Specific Avro Classes
Using Avro-specific Bindings
Using Multiple Avro-specific Bindings
JSON Bindings
Using Avro JSON Bindings
Using a JSON Binding with a JSON Record

Once you have defined your schema (as described in Avro Schemas), you make use of it in your Oracle NoSQL Database application in the following way:

  1. Add the schema to your store. See Managing Avro Schema in the Store for information on how to do this.

  2. Identify the schema to your application.

  3. Serialize and/or deserialize Oracle NoSQL Database values which use the Avro data format. You use Avro bindings to perform the serialization functions. There are different bindings available to you, each of which offers pluses and negatives.

Other than that, the mechanisms you use to read/write/delete records in the store do not change just because you are using the Avro data format with your values. Avro affects your code only where you manage your values.

The following sections describe the bindings that you use to serialize and deserialize your data. The binding that you use defines how you provide your schema to the store.

Avro Bindings Overview

There are four bindings you can use to serialize and deserialize store values that use the Avro data format. Each binding has strengths and weaknesses. The following sections go into three of the four in some detail. But, briefly, the four bindings are:

  • Generic

    A generic binding is a general-purpose binding. Generic bindings identify fields to be read and written by supplying a simple string that names the field. This allows you to use the binding in a somewhat generic way, but it suffers from a lack of type safety at application compile time.

    If you are just starting out with Avro, and have no initial reason to prefer one of the other bindings, then you should start with the generic binding.

    Generic bindings are described in Generic Binding.

  • Specific

    Specific bindings make use of classes that are generated from your schema specifications using an Ant tool. The generated classes allow you to manage the fields in your schema using getter and setter methods. As a programming methodology, specific schemas might represent a familiar programming style, depending on your past experiences.

    Unlike generic and JSON bindings, specific bindings require you to know in advance of compile time what all of your store schemas will be. This is because specific bindings make use of classes that are generated from your schema specifications using an Avro tool that can be called from Ant, and so there is no way for your application to dynamically discover the set of all schemas in use in the store.

    Specific bindings are described in Specific Binding.

  • JSON

    JSON bindings behave similarly to generic bindings, but offer less support for Avro data types. JSON bindings are most useful if you are integrating your Oracle NoSQL Database client code into a system that is JSON-oriented, because they expose JSON objects.

    JSON bindings are described in JSON Bindings.

  • Raw

    Raw bindings is an advanced feature that allows you to use low-level Avro APIs to serialize and deserialize objects. Raw bindings should be used when the other three built-in bindings will not work for you, for whatever reason. Usage of Raw bindings requires a good understanding of the Avro API set. As a result, their usage is beyond the scope of this manual.

Note that you can read using one binding and write using another one. The Avro data format (which is what is actually used for the data placed into the store) is binding independent. Put another way, the bindings know how to read and write the Avro data format; the data format itself has no knowledge of the bindings.