public interface PortableObject extends Serializable, Cloneable
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 PortableObject class and then retrieve individual fields as needed:
IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
// Convert instance of MyKey to portable format.
// We could also use GridPortableBuilder to create the key in portable format directly.
PortableObject key = grid.portables().toPortable(new MyKey());
PortableObject 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. However, if
PortableMarshaller.isKeepDeserialized() is true then Ignite will only deserialize on the first access
and will cache the deserialized object, so it does not have to be deserialized again:
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.
PortableBuilder which allows to build portable objects dynamically:
PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
builder.setField("fieldA", "A");
builder.setField("fieldB", "B");
PortableObject 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);
PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
IgnitePortables.metadata(Class)
methods. Having metadata also allows for proper formatting of PortableObject.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()
Copies this portable object.
|
<T> T |
deserialize()
Gets fully deserialized instance of portable object.
|
<F> F |
field(String fieldName)
Gets field value.
|
boolean |
hasField(String fieldName)
Checks whether field is set.
|
PortableMetadata |
metaData()
Gets meta data for this portable object.
|
int |
typeId()
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
fieldName - Field name.PortableException - In case of any other error.boolean hasField(String fieldName)
fieldName - Field name.true if field is set.@Nullable <T> T deserialize() throws PortableException
PortableInvalidClassException - If class doesn't exist.PortableException - In case of any other error.PortableObject clone() throws CloneNotSupportedException
CloneNotSupportedException
Follow @ApacheIgnite
Ignite Fabric : ver. 1.4.0 Release Date : September 24 2015