public interface BinaryObjectBuilder
Here is an example of how a binary object can be built dynamically:
BinaryObjectBuilder builder = Ignition.ignite().binary().builder("org.project.MyObject"); builder.setField("fieldA", "A"); builder.setField("fieldB", "B"); BinaryObject binaryObj = builder.build();
Also builder can be initialized by existing binary object. This allows changing some fields without affecting other fields.
BinaryObjectBuilder builder = Ignition.ignite().binary().builder(person); builder.setField("name", "John"); person = builder.build();If you need to modify nested binary object you can get an instance of a builder for nested binary object using
getField(String)
, changes made on nested builder will affect parent object,
for example:
BinaryObjectBuilder personBuilder = grid.binary().createBuilder(personBinaryObj); BinaryObjectBuilder addressBuilder = personBuilder.getField("address"); addressBuilder.setField("city", "New York"); personBinaryObj = personBuilder.build(); // Should be "New York". String city = personBinaryObj.getField("address").getField("city");
Make sure to set values for all the fields that an object from your domain model has.
If you need to set null as a value use setField(String, Object, Class)
method directly specifying
field's type.
If to follow this recommendation you'll reduce the size of internal metadata object that every binary object of a particular type has. Usually the metadata size grows because particular fields are not set to an instance of a binary object constructed with the builder. Every time when you construct an object setting only a subset of the fields the metadata object related to this type is expanded by the metadata processor which treats every new combination of the fields as the new version of the binary object.
Modifier and Type | Method and Description |
---|---|
BinaryObject |
build()
Builds binary object.
|
<T> T |
getField(String name)
Returns value assigned to the specified field.
|
BinaryObjectBuilder |
removeField(String fieldName)
Removes field from this builder.
|
BinaryObjectBuilder |
setField(String name,
BinaryObjectBuilder builder)
Sets field value.
|
BinaryObjectBuilder |
setField(String name,
Object val)
Sets field value.
|
<T> BinaryObjectBuilder |
setField(String name,
T val,
Class<? super T> type)
Sets field value with value type specification.
|
<T> T getField(String name)
BinaryObjectBuilder
will be returned,
which can be modified.
Collections and maps returned from this method are modifiable.
name
- Field name.BinaryObjectBuilder setField(String name, Object val)
name
- Field name.val
- Field value (cannot be null
).BinaryObject.type()
<T> BinaryObjectBuilder setField(String name, T val, Class<? super T> type)
Field type is needed for proper metadata update.
name
- Field name.val
- Field value (may be null
).type
- Field type.BinaryObject.type()
BinaryObjectBuilder setField(String name, BinaryObjectBuilder builder)
This method should be used if field is binary object.
name
- Field name.builder
- Builder for object field (may be null
).BinaryObjectBuilder removeField(String fieldName)
fieldName
- Field name.this
instance for chaining.BinaryObject build() throws BinaryObjectException
BinaryObjectException
- In case of error.
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024