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
ConstructorDescriptionTwoStepsConversions
(org.springframework.data.convert.CustomConversions customConversions, ObjectToKeyFactory objectToKeyFactory, DatastoreMappingContext datastoreMappingContext) -
Method Summary
Modifier and TypeMethodDescription<T> T
convertCollection
(Object collection, Class<?> target) <T> T
convertOnRead
(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> T
convertOnRead
(Object val, Class targetCollectionType, Class targetComponentType) Converts a given object to an object of a target type.com.google.cloud.datastore.Value
convertOnWrite
(Object proppertyVal, DatastorePersistentProperty persistentProperty) Converts an object to a Cloud DatastoreValue
; supports collections.com.google.cloud.datastore.Value
convertOnWriteSingle
(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.void
registerEntityConverter
(DatastoreEntityConverter datastoreEntityConverter) RegistersDatastoreEntityConverter
to 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:ReadWriteConversions
Converts a given object to an object of a target type.- Specified by:
convertOnRead
in 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.null
if 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:ReadWriteConversions
Converts a given object to an object of a target type that is possibly an embedded entity.- Specified by:
convertOnRead
in 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 proppertyVal, DatastorePersistentProperty persistentProperty) Description copied from interface:ReadWriteConversions
Converts an object to a Cloud DatastoreValue
; supports collections.- Specified by:
convertOnWrite
in interfaceReadWriteConversions
- Parameters:
proppertyVal
- the objects to convert.persistentProperty
- the source field information.- Returns:
- a Cloud Datastore value.
-
convertOnWriteSingle
Description copied from interface:ReadWriteConversions
Converts an object to a Cloud DatastoreValue
, for non-collection objects.- Specified by:
convertOnWriteSingle
in interfaceReadWriteConversions
- Parameters:
propertyVal
- the object to convert.- Returns:
- a Cloud Datastore value.
-
convertCollection
-
getDatastoreCompatibleType
Description copied from interface:ReadWriteConversions
Get the Cloud Datastore-compatible native Java type that can be used to store the given type.- Specified by:
getDatastoreCompatibleType
in interfaceReadWriteConversions
- Parameters:
inputType
- the given type to test.- Returns:
- the Cloud Datastore-compatible native Java type, if it exists.
-
registerEntityConverter
Description copied from interface:ReadWriteConversions
RegistersDatastoreEntityConverter
to be used for embedded entities.- Specified by:
registerEntityConverter
in interfaceReadWriteConversions
- Parameters:
datastoreEntityConverter
- the DatastoreEntityConverter.
-