- All Implemented Interfaces:
public abstract class VersionedEntity extends java.lang.Object implements java.io.SerializableA Datastore
Entity'sserialized state with timestamp. The intended use case is a multi-stage pipeline where an Entity's Java form is not needed in most stages.
For a new or updated Entity, its serialized bytes are stored along with its Datastore
Key. For a deleted entity, only its Datastore
Keyis stored, and the
entityProtoBytes()field is left unset.
Storing raw bytes is motivated by two factors. First, since I/O is frequent and the Java objects are rarely needed in our target use case, storing raw bytes is the most efficient approach. More importantly, due to our data model and our customization of
ObjectifyService, it is challenging to implement a serializer for Objectify entities that preserves the value of all properties. Without such serializers, Objectify entities cannot be used in a pipeline.
Objectify entities do not implement
Serializable, serialization of such objects is as follows:
- Convert an Objectify entity to a Datastore
- Entity is serializable, but the more efficient approach is to convert an Entity to a
OnestoreEntity.EntityProto) and then to raw bytes.
When the first conversion above is applied to an Objectify entity, a property value in the output may differ from the input in two situations:
- If a property is of an assign-on-persist data type, e.g.,
- If it is related to CommitLog management, e.g.,
Working around the side effects caused by our customization is difficult. Any solution would likely rely on Objectify's stack of context. However, many Objectify invocations in our code base are hardcoded to call the customized version of ObjectifyService, rendering Objectify's stack useless.
For now, this inability to use Objectify entities in pipelines is mostly a testing problem: we can not perform
BEAM pipeline assertionson Objectify entities.
InitSqlTestUtils.assertContainsExactlyElementsInis an example of a workaround.
java.util.Optionalis not serializable, therefore cannot be used as property type in this class.
- See Also:
- Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description
Constructors Constructor Description
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
from(long commitTimeMillis, byte entityProtoBytes)
public abstract long commitTimeMills()
public abstract com.google.appengine.api.datastore.Key key()The
@Memoized public java.util.Optional<com.google.appengine.api.datastore.Entity> getEntity()
public boolean isDelete()
public static VersionedEntity from(long commitTimeMillis, byte entityProtoBytes)