Class DataTypeTranslator (2.0.0)

public final class DataTypeTranslator

DataTypeTranslator is a utility class for converting between the data store's Property protocol buffers and the user-facing classes (String, User, etc.).

Inheritance

Object > DataTypeTranslator

Static Methods

addPropertiesToPb(Map<String,?> map, OnestoreEntity.EntityProto proto)

public static void addPropertiesToPb(Map<String,?> map, OnestoreEntity.EntityProto proto)

Add all of the properties in the specified map to an EntityProto. This involves determining the type of each property and creating the proper type-specific protocol buffer.

If the property value is an UnindexedValue, or if it's a type that is never indexed, e.g. Text and Blob, it's added to EntityProto.raw_property. Otherwise it's added to EntityProto.property.

Parameters
NameDescription
mapMap<String,?>

A not null map of all the properties which will be set on proto

protocom.google.storage.onestore.v3.OnestoreEntity.EntityProto

A not null protocol buffer

extractImplicitPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

public static void extractImplicitPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

Copy all of the implicit properties present on proto into map.

Parameters
NameDescription
protocom.google.storage.onestore.v3.OnestoreEntity.EntityProto
mapMap<String,@org.checkerframework.checker.nullness.qual.Nullable java.lang.Object>

extractIndexedPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

public static void extractIndexedPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

Copy all of the indexed properties present on proto into map.

Parameters
NameDescription
protocom.google.storage.onestore.v3.OnestoreEntity.EntityProto
mapMap<String,@org.checkerframework.checker.nullness.qual.Nullable java.lang.Object>

extractPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

public static void extractPropertiesFromPb(OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)

Copy all of the properties present on proto into map.

Parameters
NameDescription
protocom.google.storage.onestore.v3.OnestoreEntity.EntityProto
mapMap<String,@org.checkerframework.checker.nullness.qual.Nullable java.lang.Object>

findIndexedPropertiesOnPb(OnestoreEntity.EntityProto proto, String propertyName)

public static Collection<OnestoreEntity.Property> findIndexedPropertiesOnPb(OnestoreEntity.EntityProto proto, String propertyName)

Locates and returns all indexed properties with the given name on the given proto. If there are a mix of matching multiple and non-multiple properties, the collection will contain the first non-multiple property.

Parameters
NameDescription
protocom.google.storage.onestore.v3.OnestoreEntity.EntityProto
propertyNameString
Returns
TypeDescription
Collection<com.google.storage.onestore.v3.OnestoreEntity.Property>

A list, potentially empty, containing matching properties.

getComparablePropertyValue(OnestoreEntity.Property property)

public static @Nullable Comparable<Object> getComparablePropertyValue(OnestoreEntity.Property property)

Returns the value for the property as its comparable representation type.

Parameter
NameDescription
propertycom.google.storage.onestore.v3.OnestoreEntity.Property

a not null property

Returns
TypeDescription
@org.checkerframework.checker.nullness.qual.Nullable java.lang.Comparable<Object>

null if no value was set for property

getPropertyValue(OnestoreEntity.Property property)

public static @Nullable Object getPropertyValue(OnestoreEntity.Property property)

Returns the value for the property as its canonical type.

Parameter
NameDescription
propertycom.google.storage.onestore.v3.OnestoreEntity.Property

a not null property

Returns
TypeDescription
@org.checkerframework.checker.nullness.qual.Nullable java.lang.Object

null if no value was set for property

getTypeRank(Class<? extends Comparable> datastoreType)

public static int getTypeRank(Class<? extends Comparable> datastoreType)

Get the rank of the given datastore type relative to other datastore types. Note that datastore types do not necessarily have unique ranks.

Parameter
NameDescription
datastoreTypeClass<? extends java.lang.Comparable>
Returns
TypeDescription
int

toEntityFromSerializedV1Proto(byte[] serializedV1Entity)

public static Entity toEntityFromSerializedV1Proto(byte[] serializedV1Entity)

Deserializes a Cloud Datastore V1 Entity protobuf and converts it to an App Engine Datastore Entity. serializedV1Entity should be an output of #toSerializedV1Proto; no guarantees for other inputs.

Parameter
NameDescription
serializedV1Entitybyte[]
Returns
TypeDescription
Entity

toSerializedV1Proto(Entity entity)

public static byte[] toSerializedV1Proto(Entity entity)

Converts an App Engine Datastore Entity to a Cloud Datastore Entity V1 protobuf and serializes it.

Note that the conversion may be lossy or fail; for example, the Cloud Datastore V1 API supports only UTF-8 strings, so App Engine Datastore entities with string properties that are not UTF-8 encoded may behave in unexpected ways if supplied to Cloud Datastore. You can verify that the conversion was successful for entity x by checking x.equals(toEntityFromSerializedV1Proto(toSerializedV1Proto(x)).

Parameter
NameDescription
entityEntity
Returns
TypeDescription
byte[]