@Deprecated public interface PortableObject extends org.apache.ignite.binary.BinaryObject
NOTE: user does not need to (and should not) implement this interface directly.
To work with the portable format directly, user should create a cache projection
over GridPortableObject class and then retrieve individual fields as needed:
CacheProjection<GridPortableObject.class, GridPortableObject.class> prj =
cache.projection(GridPortableObject.class, GridPortableObject.class);
// Convert instance of MyKey to portable format.
// We could also use GridPortableBuilder to create
// the key in portable format directly.
GridPortableObject key = grid.portables().toPortable(new MyKey());
GridPortableObject val = prj.get(key);
String field = val.field("myFieldName");
Alternatively, we could also choose a hybrid approach, where, for example,
the keys are concrete deserialized objects and the values are returned in portable
format, like so:
CacheProjection<MyKey.class, GridPortableObject.class> prj =
cache.projection(MyKey.class, GridPortableObject.class);
GridPortableObject val = prj.get(new MyKey());
String field = val.field("myFieldName");
We could also have the values as concrete deserialized objects and the keys in portable format,
but such use case is a lot less common because cache keys are usually a lot smaller than values, and
it may be very cheap to deserialize the keys, but not the values.
And finally, 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, however, Ignite will only deserialize on the first access and will cache the deserialized object, so it does not have to be deserialized again:
CacheProjection<MyKey.class, MyValue.class> prj =
cache.projection(MyKey.class, MyValue.class);
MyValue val = prj.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.
PortableBuilder which allows to build portable objects dynamically:
GridPortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
builder.setField("fieldA", "A");
builder.setField("fieldB", "B");
GridPortableObject portableObj = 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 portable format, like so:
MyObject obj = new MyObject();
obj.setFieldA("A");
obj.setFieldB(123);
GridPortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
GridPortables.metadata(...)
methods. Having metadata also allows for proper formatting of GridPortableObject.toString() method,
even when portable objects are kept in binary format only, which may be necessary for audit reasons.| Modifier and Type | Method and Description |
|---|---|
PortableObject |
clone()
Deprecated.
Copies this portable object.
|
<T> T |
deserialize()
Deprecated.
Gets fully deserialized instance of portable object.
|
<F> F |
field(String fieldName)
Deprecated.
Gets field value.
|
boolean |
hasField(String fieldName)
Deprecated.
Checks whether field is set.
|
PortableMetadata |
metaData()
Deprecated.
Gets meta data for this portable object.
|
PortableBuilder |
toBuilder()
Deprecated.
Creates a new portable builder based on this portable object.
|
int |
typeId()
Deprecated.
Gets portable object type ID.
|
int typeId()
@Nullable PortableMetadata metaData() throws PortableException
PortableException - In case of error.@Nullable <F> F field(String fieldName) throws PortableException
field in interface org.apache.ignite.binary.BinaryObjectfieldName - Field name.PortableException - In case of any other error.boolean hasField(String fieldName)
hasField in interface org.apache.ignite.binary.BinaryObjectfieldName - Field name.true if field is set.@Nullable
<T> T deserialize()
throws PortableException
deserialize in interface org.apache.ignite.binary.BinaryObjectPortableInvalidClassException - If class doesn't exist.PortableException - In case of any other error.PortableObject clone() throws CloneNotSupportedException
clone in interface org.apache.ignite.binary.BinaryObjectCloneNotSupportedExceptionPortableBuilder toBuilder() throws org.apache.ignite.binary.BinaryObjectException
toBuilder in interface org.apache.ignite.binary.BinaryObjectorg.apache.ignite.binary.BinaryObjectException - If failed to create new portable builder.
GridGain Fabric : ver. 7.8.12 Release Date : October 2 2017