Class DataTypeTranslator
- java.lang.Object
-
- com.google.appengine.api.datastore.DataTypeTranslator
-
public final class DataTypeTranslator extends Object
DataTypeTranslatoris a utility class for converting between the data store'sPropertyprotocol buffers and the user-facing classes (String,User, etc.).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataTypeTranslator.ComparableByteArrayA wrapper for abyte[]that implementsComparable.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddPropertiesToPb(Map<String,?> map, com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto)Add all of the properties in the specified map to anEntityProto.static voidextractImplicitPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the implicit properties present onprotointomap.static voidextractIndexedPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the indexed properties present onprotointomap.static voidextractPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the properties present onprotointomap.static Collection<com.google.storage.onestore.v3.OnestoreEntity.Property>findIndexedPropertiesOnPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, String propertyName)Locates and returns all indexed properties with the given name on the given proto.static @Nullable Comparable<Object>getComparablePropertyValue(com.google.storage.onestore.v3.OnestoreEntity.Property property)Returns the value for the property as its comparable representation type.static @Nullable ObjectgetPropertyValue(com.google.storage.onestore.v3.OnestoreEntity.Property property)Returns the value for the property as its canonical type.static intgetTypeRank(Class<? extends Comparable> datastoreType)Get the rank of the given datastore type relative to other datastore types.static EntitytoEntityFromSerializedV1Proto(byte[] serializedV1Entity)Deserializes a Cloud Datastore V1Entityprotobuf and converts it to an App Engine DatastoreEntity.static byte[]toSerializedV1Proto(Entity entity)Converts an App Engine DatastoreEntityto a Cloud DatastoreEntityV1 protobuf and serializes it.
-
-
-
Method Detail
-
addPropertiesToPb
public static void addPropertiesToPb(Map<String,?> map, com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto)
Add all of the properties in the specified map to anEntityProto. This involves determining the type of each property and creating the proper type-specific protocol buffer.If the property value is an
Entity.UnindexedValue, or if it's a type that is never indexed, e.g.TextandBlob, it's added toEntityProto.raw_property. Otherwise it's added toEntityProto.property.- Parameters:
map- A notnullmap of all the properties which will be set onprotoproto- A notnullprotocol buffer
-
extractIndexedPropertiesFromPb
public static void extractIndexedPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the indexed properties present onprotointomap.
-
extractPropertiesFromPb
public static void extractPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the properties present onprotointomap.
-
extractImplicitPropertiesFromPb
public static void extractImplicitPropertiesFromPb(com.google.storage.onestore.v3.OnestoreEntity.EntityProto proto, Map<String,@Nullable Object> map)Copy all of the implicit properties present onprotointomap.
-
findIndexedPropertiesOnPb
public static Collection<com.google.storage.onestore.v3.OnestoreEntity.Property> findIndexedPropertiesOnPb(com.google.storage.onestore.v3.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.- Returns:
- A list, potentially empty, containing matching properties.
-
getPropertyValue
public static @Nullable Object getPropertyValue(com.google.storage.onestore.v3.OnestoreEntity.Property property)
Returns the value for the property as its canonical type.- Parameters:
property- a notnullproperty- Returns:
nullif no value was set forproperty
-
toEntityFromSerializedV1Proto
public static Entity toEntityFromSerializedV1Proto(byte[] serializedV1Entity)
Deserializes a Cloud Datastore V1Entityprotobuf and converts it to an App Engine DatastoreEntity.serializedV1Entityshould be an output oftoSerializedV1Proto(com.google.appengine.api.datastore.Entity); no guarantees for other inputs.- Throws:
IllegalArgumentException- if the argument could not be deserialized
-
toSerializedV1Proto
public static byte[] toSerializedV1Proto(Entity entity)
Converts an App Engine DatastoreEntityto a Cloud DatastoreEntityV1 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
xby checkingx.equals(toEntityFromSerializedV1Proto(toSerializedV1Proto(x)).
-
getComparablePropertyValue
public static @Nullable Comparable<Object> getComparablePropertyValue(com.google.storage.onestore.v3.OnestoreEntity.Property property)
Returns the value for the property as its comparable representation type.- Parameters:
property- a notnullproperty- Returns:
nullif no value was set forproperty
-
getTypeRank
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.
-
-