Class VersionedEntity
- java.lang.Object
-
- google.registry.backup.VersionedEntity
-
- All Implemented Interfaces:
java.io.Serializable
public abstract class VersionedEntity extends java.lang.Object implements java.io.Serializable
A DatastoreEntity's
serialized 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 DatastoreKey
is stored, and theentityProtoBytes()
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
:auditedOfy().save().toEntity(..)
- Entity is serializable, but the more efficient approach is to convert an Entity to a
ProtocolBuffer (
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.,
UpdateAutoTimestamp
. - If it is related to CommitLog management, e.g.,
EppResource.revisions
.
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 assertions
on Objectify entities.InitSqlTestUtils.assertContainsExactlyElementsIn
is an example of a workaround.Note that
java.util.Optional
is 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 static class
VersionedEntity.Builder
-
Constructor Summary
Constructors Constructor Description VersionedEntity()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract long
commitTimeMills()
static VersionedEntity
from(long commitTimeMillis, byte[] entityProtoBytes)
java.util.Optional<com.google.appengine.api.datastore.Entity>
getEntity()
boolean
isDelete()
abstract com.google.appengine.api.datastore.Key
key()
TheKey
of theEntity
.
-
-
-
Method Detail
-
commitTimeMills
public abstract long commitTimeMills()
-
key
public abstract com.google.appengine.api.datastore.Key key()
TheKey
of theEntity
.
-
getEntity
@Memoized public java.util.Optional<com.google.appengine.api.datastore.Entity> getEntity()
-
isDelete
public boolean isDelete()
-
from
public static VersionedEntity from(long commitTimeMillis, byte[] entityProtoBytes)
-
-