Package oracle.nosql.driver.values
Interface FieldValueEventHandler
-
public interface FieldValueEventHandlerFieldValueEventHandler is an event-driven interface that allows multiple implementations of serializers and deserializers for aFieldValue. The events correspond to the data model exposed byFieldValue.Events can be generated from
FieldValueinstances themselves, from a wire protocol, or from a generic program. Examples of uses include- Binary serializer for the wire protocol, capturing events generated
from a
FieldValueinstances - Binary de-serializer for the wire protocol, capturing events generated from code that is reading the wire protocol
- JSON serializer for
FieldValueinstances - JSON pretty-printfor
FieldValueinstances - Direct-from/to-object serializer or deserializer that operates on
POJOs intead of
FieldValue
FieldValueinstance. Seegenerate(oracle.nosql.driver.values.FieldValue, oracle.nosql.driver.values.FieldValueEventHandler).Example usage
MapValue map = new MapValue(); map.put(...); ... JsonSerializer js = new JsonSerializer(null); FieldValueEventHandler.generate(map, js); String json = js.toString();
Functionally here is how the event handler is to be used. Look at the
generate(oracle.nosql.driver.values.FieldValue, oracle.nosql.driver.values.FieldValueEventHandler)method for implementation details. There are no specific start/end events, although they could be added if deemed useful.Simple (atomic) field value events are just that, e.g.
booleanValue(true); integerValue(6);
Map values have startMap and endMap events that surround them. These methods have a size argument to let the event handler know the size of the map. It's possible that the size is not known but it's best to provide one if possible, and in some cases (protocol serialization) it's required. Map entries require key and value, where the value may be a nested map or array. To account for nesting the events are:startMap(1) startMapField(key) // pass the key String // an event that creates a value, including a nested map or array stringValue("a string") endMapField() endMap(1)Array values have startArray and endArray events that surround them. These methods have a size argument to let the event handler know the size of the array. It's possible that the size is not known but it's best to provide one if possible, and in some cases (protocol serialization) it's required. Array entry events are followed with endArrayField events. This simplifies implementations that need to know if they are working within an array. Here's an array example.startArray(2) startMap(msize) // nested map endMap(msize) // map is empty endArrayField() stringValue("a string") // add string to the array endArrayField() endArray(2) - Binary serializer for the wire protocol, capturing events generated
from a
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbinaryValue(byte[] byteArray)A binary valuevoidbooleanValue(boolean value)A boolean valuevoiddoubleValue(double value)A double valuevoidemptyValue()An EmptyValuevoidendArray(int size)End an ArrayValue.voidendArrayField()End a field in an array.voidendMap(int size)End a MapValue.voidendMapField()End a field in a map.static voidgenerate(FieldValue value, FieldValueEventHandler handler)Generates events from aFieldValueinstance sending them to theFieldValueEventHandlerprovided.static voidgenerateForArray(ArrayValue array, FieldValueEventHandler handler)Generates events forArrayValuesending them to the specifiedFieldValueEventHandler.static voidgenerateForMap(MapValue map, FieldValueEventHandler handler)Generates events forMapValuesending them to the specifiedFieldValueEventHandler.voidintegerValue(int value)An integer valuevoidjsonNullValue()A JsonNullValuevoidlongValue(long value)A long valuevoidnullValue()A NullValuevoidnumberValue(BigDecimal value)A Number value.voidstartArray(int size)Start an ArrayValue.voidstartMap(int size)Start a MapValue.voidstartMapField(String key)Start a field in a map.voidstringValue(String value)A String valuevoidtimestampValue(TimestampValue timestamp)A Timestamp value
-
-
-
Method Detail
-
startMap
void startMap(int size) throws IOExceptionStart a MapValue. This method accepts the size of the map, but there are situations where the size may not be known. In this case -1 should be passed and it is up to the implementing class to decide if it can operate without a size and if not, throw IllegalArgumentException.- Parameters:
size- the number of entries in the map or -1 if not known.- Throws:
IllegalArgumentException- if the size is invalid or cannot be handled by the implementation.IOException- conditionally, based on implementation
-
startArray
void startArray(int size) throws IOExceptionStart an ArrayValue. This method accepts the size of the array, but there are situations where the size may not be known. In this case -1 should be passed and it is up to the implementing class to decide if it can operate without a size and if not, throw IllegalArgumentException.- Parameters:
size- the number of entries in the array or -1 if not known.- Throws:
IllegalArgumentException- if the size is invalid or cannot be handled by the implementation.IOException- conditionally, based on implementation
-
endMap
void endMap(int size) throws IOExceptionEnd a MapValue.- Parameters:
size- the number of entries in the map or -1 if not known.- Throws:
IOException- conditionally, based on implementation
-
endArray
void endArray(int size) throws IOExceptionEnd an ArrayValue.- Parameters:
size- the number of entries in the array or -1 if not known.- Throws:
IOException- conditionally, based on implementation
-
startMapField
void startMapField(String key) throws IOException
Start a field in a map.- Parameters:
key- the key of the field.- Throws:
IOException- conditionally, based on implementation
-
endMapField
void endMapField() throws IOExceptionEnd a field in a map.- Throws:
IOException- conditionally, based on implementation
-
endArrayField
void endArrayField() throws IOExceptionEnd a field in an array. There is no corresponding start for array entries. This allows, for example, JSON serializers to insert array value separators without the complexity of tracking the entire event sequence.- Throws:
IOException- conditionally, based on implementation
-
booleanValue
void booleanValue(boolean value) throws IOExceptionA boolean value- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
binaryValue
void binaryValue(byte[] byteArray) throws IOExceptionA binary value- Parameters:
byteArray- the byte[] value- Throws:
IOException- conditionally, based on implementation
-
stringValue
void stringValue(String value) throws IOException
A String value- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
integerValue
void integerValue(int value) throws IOExceptionAn integer value- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
longValue
void longValue(long value) throws IOExceptionA long value- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
doubleValue
void doubleValue(double value) throws IOExceptionA double value- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
numberValue
void numberValue(BigDecimal value) throws IOException
A Number value.- Parameters:
value- the value- Throws:
IOException- conditionally, based on implementation
-
timestampValue
void timestampValue(TimestampValue timestamp) throws IOException
A Timestamp value- Parameters:
timestamp- the value- Throws:
IOException- conditionally, based on implementation
-
jsonNullValue
void jsonNullValue() throws IOExceptionA JsonNullValue- Throws:
IOException- conditionally, based on implementation
-
nullValue
void nullValue() throws IOExceptionA NullValue- Throws:
IOException- conditionally, based on implementation
-
emptyValue
void emptyValue() throws IOExceptionAn EmptyValue- Throws:
IOException- conditionally, based on implementation
-
generate
static void generate(FieldValue value, FieldValueEventHandler handler) throws IOException
Generates events from aFieldValueinstance sending them to theFieldValueEventHandlerprovided.- Parameters:
value- the FieldValue used to generate eventshandler- the handler to use- Throws:
IOException- conditionally, based on implementation
-
generateForMap
static void generateForMap(MapValue map, FieldValueEventHandler handler) throws IOException
Generates events forMapValuesending them to the specifiedFieldValueEventHandler.- Parameters:
map- the MapValue to usehandler- the handler to use- Throws:
IOException- conditionally, based on implementation
-
generateForArray
static void generateForArray(ArrayValue array, FieldValueEventHandler handler) throws IOException
Generates events forArrayValuesending them to the specifiedFieldValueEventHandler.- Parameters:
array- the ArrayValue to usehandler- the handler to use- Throws:
IOException- conditionally, based on implementation
-
-