Class TwoStepsConversions
java.lang.Object
com.google.cloud.spring.data.datastore.core.convert.TwoStepsConversions
- All Implemented Interfaces:
ReadWriteConversions
In order to support
CustomConversions, this class applies 2-step conversions. The first
step produces one of SimpleTypeHolder's simple
types. The second step converts simple types to Datastore-native types. The second step is
skipped if the first one produces a Datastore-native type.- Since:
- 1.1
-
Constructor Summary
ConstructorsConstructorDescriptionTwoStepsConversions(org.springframework.data.convert.CustomConversions customConversions, ObjectToKeyFactory objectToKeyFactory, DatastoreMappingContext datastoreMappingContext) -
Method Summary
Modifier and TypeMethodDescription<T> TconvertCollection(Object collection, Class<?> target) <T> TconvertOnRead(Object val, EmbeddedType embeddedType, org.springframework.data.util.TypeInformation targetTypeInformation) Converts a given object to an object of a target type that is possibly an embedded entity.<T> TconvertOnRead(Object val, Class targetCollectionType, Class targetComponentType) Converts a given object to an object of a target type.com.google.cloud.datastore.ValueconvertOnWrite(Object propertyVal, DatastorePersistentProperty persistentProperty) Converts an object to a Cloud DatastoreValue; supports collections.com.google.cloud.datastore.ValueconvertOnWriteSingle(Object propertyVal) Converts an object to a Cloud DatastoreValue, for non-collection objects.getDatastoreCompatibleType(Class inputType) Get the Cloud Datastore-compatible native Java type that can be used to store the given type.voidregisterEntityConverter(DatastoreEntityConverter datastoreEntityConverter) RegistersDatastoreEntityConverterto be used for embedded entities.
-
Constructor Details
-
TwoStepsConversions
public TwoStepsConversions(org.springframework.data.convert.CustomConversions customConversions, ObjectToKeyFactory objectToKeyFactory, DatastoreMappingContext datastoreMappingContext)
-
-
Method Details
-
convertOnRead
Description copied from interface:ReadWriteConversionsConverts a given object to an object of a target type.- Specified by:
convertOnReadin interfaceReadWriteConversions- Type Parameters:
T- the type of the object that is produced by reading- Parameters:
val- the simple type or Iterable value to convert. Arrays are not supported.targetCollectionType- the type of the collection to be converted into.nullif the property is a singular object.targetComponentType- the type of the property to convert. For collection-like properties this refers to the individual items' type.- Returns:
- an object of a target type.
-
convertOnRead
public <T> T convertOnRead(Object val, EmbeddedType embeddedType, org.springframework.data.util.TypeInformation targetTypeInformation) Description copied from interface:ReadWriteConversionsConverts a given object to an object of a target type that is possibly an embedded entity.- Specified by:
convertOnReadin interfaceReadWriteConversions- Type Parameters:
T- the type of the object that is produced by reading- Parameters:
val- the simple type or Iterable value to convert. Arrays are not supported.embeddedType- contains the type of embedded entity conversion should produce.targetTypeInformation- type metadata information for the desired type.- Returns:
- an object of a target type.
-
convertOnWrite
public com.google.cloud.datastore.Value convertOnWrite(Object propertyVal, DatastorePersistentProperty persistentProperty) Description copied from interface:ReadWriteConversionsConverts an object to a Cloud DatastoreValue; supports collections.- Specified by:
convertOnWritein interfaceReadWriteConversions- Parameters:
propertyVal- the objects to convert.persistentProperty- the source field information.- Returns:
- a Cloud Datastore value.
-
convertOnWriteSingle
Description copied from interface:ReadWriteConversionsConverts an object to a Cloud DatastoreValue, for non-collection objects.- Specified by:
convertOnWriteSinglein interfaceReadWriteConversions- Parameters:
propertyVal- the object to convert.- Returns:
- a Cloud Datastore value.
-
convertCollection
-
getDatastoreCompatibleType
Description copied from interface:ReadWriteConversionsGet the Cloud Datastore-compatible native Java type that can be used to store the given type.- Specified by:
getDatastoreCompatibleTypein interfaceReadWriteConversions- Parameters:
inputType- the given type to test.- Returns:
- the Cloud Datastore-compatible native Java type, if it exists.
-
registerEntityConverter
Description copied from interface:ReadWriteConversionsRegistersDatastoreEntityConverterto be used for embedded entities.- Specified by:
registerEntityConverterin interfaceReadWriteConversions- Parameters:
datastoreEntityConverter- the DatastoreEntityConverter.
-