Class TwoStepsConversions

java.lang.Object
com.google.cloud.spring.data.datastore.core.convert.TwoStepsConversions
All Implemented Interfaces:
ReadWriteConversions

public class TwoStepsConversions extends Object implements 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 Details

    • TwoStepsConversions

      public TwoStepsConversions(org.springframework.data.convert.CustomConversions customConversions, ObjectToKeyFactory objectToKeyFactory, DatastoreMappingContext datastoreMappingContext)
  • Method Details

    • convertOnRead

      public <T> T convertOnRead(Object val, Class targetCollectionType, Class targetComponentType)
      Description copied from interface: ReadWriteConversions
      Converts a given object to an object of a target type.
      Specified by:
      convertOnRead in interface ReadWriteConversions
      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 interface ReadWriteConversions
      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 Datastore Value; supports collections.
      Specified by:
      convertOnWrite in interface ReadWriteConversions
      Parameters:
      proppertyVal - the objects to convert.
      persistentProperty - the source field information.
      Returns:
      a Cloud Datastore value.
    • convertOnWriteSingle

      public com.google.cloud.datastore.Value convertOnWriteSingle(Object propertyVal)
      Description copied from interface: ReadWriteConversions
      Converts an object to a Cloud Datastore Value, for non-collection objects.
      Specified by:
      convertOnWriteSingle in interface ReadWriteConversions
      Parameters:
      propertyVal - the object to convert.
      Returns:
      a Cloud Datastore value.
    • convertCollection

      public <T> T convertCollection(Object collection, Class<?> target)
    • getDatastoreCompatibleType

      public Optional<Class<?>> getDatastoreCompatibleType(Class inputType)
      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 interface ReadWriteConversions
      Parameters:
      inputType - the given type to test.
      Returns:
      the Cloud Datastore-compatible native Java type, if it exists.
    • registerEntityConverter

      public void registerEntityConverter(DatastoreEntityConverter datastoreEntityConverter)
      Description copied from interface: ReadWriteConversions
      Registers DatastoreEntityConverter to be used for embedded entities.
      Specified by:
      registerEntityConverter in interface ReadWriteConversions
      Parameters:
      datastoreEntityConverter - the DatastoreEntityConverter.