Interface RecordV2DataType
This provides the ability to handle data in Diffusion proprietary 'record' format. This format allows string data to be organized into 'records' which in turn are made up of 'fields'. Each field is a string but may be handled as either an integer or a decimal field if required.
This format is compatible with legacy RECORD topics (removed in release 6.2) and therefore can be used to migrate client applications from using such topics with minimal change to the application.
The data can either be free format or constrained by a Schema.
In free format mode, no schema is associated with the data and the data will
contain zero or more records, each comprising zero or more fields. In this
mode the meaning of each field is entirely up to the application and no
validation will be performed by Diffusion, either in the client library, or
at the server. To write free format records, a RecordV2Builder can be
used to create a RecordV2 object. Such a builder may be created using
the valueBuilder() method.
When using a Schema then the permitted records and fields are defined
by the schema. The schema names the records and the fields within them and
provides a mechanism for direct access to the fields. The schema is also used
to validate the data to ensure it complies with the schema definition.
In schema mode, data can be created and updated using a
MutableRecordModel which allows records and fields to be conveniently
set and updated by name. A base model can be created from a schema using the
Schema.createMutableModel() method. The model can at any time be used
to create a new RecordV2 object. A consumer of a RecordV2
value can read it as a RecordModel by simply using the
RecordV2.asModel(Schema) method to produce an immutable
representation of the data. When creating the data using a
MutableRecordModel then the model ensures that the data is valid and
therefore there is no need for the server or the consuming client to validate
the data.
Schemas can be parsed from JSON strings or more simply using a
SchemaBuilder obtained using the schemaBuilder() method. A
schema can be bound to a RecordV2 data type instance using the method
withSchema(Schema). This method will return a new RecordV2DataType
instance with the schema bound to it for validation.
A RecordV2 object can only be validated within the context of a
Schema. For this reason if the validate method is called on a dataType that has no bound schema, it will
always succeed.
- Since:
- 6.0
- Author:
- DiffusionData Limited
-
Method Summary
Modifier and TypeMethodDescriptionReturns support for binary deltas.parseSchema(String json) Parse a schema from a JSON string.readValue(byte[] in) Parse a value from aRecordV2format byte array.readValue(byte[] in, int offset, int length) Parse a value from aRecordV2format byte array.Creates a new schema builder.Creates a newRecordV2Builder.withSchema(Schema schema) Bind a specific schema to aRecordV2DataTypeinstance.Methods inherited from interface com.pushtechnology.diffusion.datatype.DataType
canReadAs, deltaType, deltaType, getTypeName, readAs, readAs, readAs, readValue, serializedBinaryDeltaType, toBytes, validate, validate, writeValue
-
Method Details
-
binaryDeltaType
DeltaType<RecordV2,BinaryDelta> binaryDeltaType()Returns support for binary deltas.Equivalent to calling
deltaType(BinaryDelta.class).- Specified by:
binaryDeltaTypein interfaceDataType<RecordV2>- Returns:
- the delta type, or null if none
-
readValue
Parse a value from aRecordV2format byte array.RecordV2instances can only be invalid in the context of a schema so this method does not throwInvalidDataException.- Specified by:
readValuein interfaceDataType<RecordV2>- Parameters:
in- the binary data. The implementation re-uses the array to avoid copying. The caller must ensure the array is not modified.offset- the start position of the data to be read within the byte arraylength- the length of the data to be read within the byte array- Throws:
IndexOutOfBoundsException- if eitheroffsetorlengthis negative, oroffset + length > bytes.length
-
readValue
Parse a value from aRecordV2format byte array.Equivalent to
readValue(in, 0, in.length). -
parseSchema
Parse a schema from a JSON string.- Parameters:
json- string containing a schema definition- Returns:
- schema
- Throws:
SchemaParseException- if a schema parsing error occurs.
-
valueBuilder
RecordV2Builder valueBuilder()Creates a newRecordV2Builder.Such a builder may be used to generate free format
RecordV2format value that is not constrained by aSchema.- Returns:
- a new records builder
-
schemaBuilder
SchemaBuilder schemaBuilder()Creates a new schema builder.- Returns:
- a new schema builder
-
withSchema
Bind a specific schema to aRecordV2DataTypeinstance.- Parameters:
schema- to bind to the data type- Returns:
- a new
RecordV2DataTypeinstance bound to a specific schema
-