public interface BinaryObject extends Serializable, Cloneable
NOTE: user does not need to (and should not) implement this interface directly.
To work with the binary format directly, user should create a cache projection
over BinaryObject
class and then retrieve individual fields as needed:
IgniteCache<BinaryObject, BinaryObject> prj = cache.withKeepBinary(); // Convert instance of MyKey to binary format. // We could also use BinaryObjectBuilder to create the key in binary format directly. BinaryObject key = ignite.binary().toBinary(new MyKey()); BinaryObject val = prj.get(key); String field = val.field("myFieldName");Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized typed objects at all times. In this case we do incur the deserialization cost.
IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null); MyValue val = cache.get(new MyKey()); // Normal java getter. String fieldVal = val.getMyFieldName();
ArrayList
in Java will become
List
in C#, LinkedList
in Java is LinkedList
in C#, HashMap
in Java is Dictionary
in C#, and TreeMap
in Java becomes SortedDictionary
in C#, etc.
BinaryObjectBuilder
which allows to build binary objects dynamically:
BinaryObjectBuilder builder = Ignition.ignite().binary().builder("org.project.MyObject"); builder.setField("fieldA", "A"); builder.setField("fieldB", "B"); BinaryObject binaryObj = builder.build();For the cases when class definition is present in the class path, it is also possible to populate a standard POJO and then convert it to binary format, like so:
MyObject obj = new MyObject(); obj.setFieldA("A"); obj.setFieldB(123); BinaryObject binaryObj = Ignition.ignite().binary().toBinary(obj);
IgniteBinary.type(Class)
methods. Having metadata also allows for proper formatting of BinaryObject.toString()
method,
even when binary objects are kept in binary format only, which may be necessary for audit reasons.Modifier and Type | Method and Description |
---|---|
BinaryObject |
clone()
Copies this binary object.
|
<T> T |
deserialize()
Gets fully deserialized instance of binary object.
|
<T> T |
deserialize(ClassLoader ldr)
Gets fully deserialized instance of binary object.
|
String |
enumName()
Get name for this enum object.
|
int |
enumOrdinal()
Get ordinal for this enum object.
|
<F> F |
field(String fieldName)
Gets field value.
|
boolean |
hasField(String fieldName)
Checks whether field exists in the object.
|
int |
size()
Get the size of the object
|
BinaryObjectBuilder |
toBuilder()
Creates a new
BinaryObjectBuilder based on this binary object. |
BinaryType |
type()
Gets type information for this binary object.
|
BinaryType type() throws BinaryObjectException
BinaryObjectException
- In case of error.<F> F field(String fieldName) throws BinaryObjectException
F
- Type of the field value.fieldName
- Field name.BinaryObjectException
- In case of any other error.boolean hasField(String fieldName)
fieldName
- Field name.True
if field exists.<T> T deserialize() throws BinaryObjectException
T
- Type of the deserialized object.BinaryInvalidTypeException
- If class doesn't exist.BinaryObjectException
- In case of any other error.<T> T deserialize(ClassLoader ldr) throws BinaryObjectException
ldr
was not specified, configured class loader
will be used IgniteConfiguration.getClassLoader()
.T
- Type of the deserialized object.ldr
- Class loader.BinaryInvalidTypeException
- If class doesn't exist.BinaryObjectException
- In case of any other error.BinaryObject clone() throws CloneNotSupportedException
CloneNotSupportedException
BinaryObjectBuilder toBuilder() throws BinaryObjectException
BinaryObjectBuilder
based on this binary object. The following code
BinaryObjectBuilder builder = binaryObject.toBuilder();is equivalent to
BinaryObjectBuilder builder = ignite.binary().builder(binaryObject);
BinaryObjectException
- If builder cannot be created.int enumOrdinal() throws BinaryObjectException
BinaryType.isEnum()
to check if object is of enum type.BinaryObjectException
- If object is not enum.String enumName() throws BinaryObjectException
BinaryType.isEnum()
to check if object is of enum type.BinaryObjectException
- If object is not enum.int size()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.16.0 Release Date : December 15 2023