Class ConverterAwareMappingSpannerEntityWriter

java.lang.Object
com.google.cloud.spring.data.spanner.core.convert.ConverterAwareMappingSpannerEntityWriter
All Implemented Interfaces:
SpannerEntityWriter, org.springframework.data.convert.EntityWriter<Object,MultipleValueBinder>

public class ConverterAwareMappingSpannerEntityWriter extends Object implements SpannerEntityWriter
The primary class for adding values from entity objects to Mutation.WriteBuilder for the purpose of creating mutations for Spanner.
Since:
1.1
  • Field Details

    • singleItemTypeValueBinderMethodMap

      public static final Map<Class<?>,BiFunction<com.google.cloud.spanner.ValueBinder,?,?>> singleItemTypeValueBinderMethodMap
      A map of types to functions that binds them to `ValueBinder` objects.
  • Method Details

    • findFirstCompatibleSpannerSingleItemNativeType

      public static Class<?> findFirstCompatibleSpannerSingleItemNativeType(Predicate<Class> testFunc)
    • findFirstCompatibleSpannerMultipleItemNativeType

      public static Class<?> findFirstCompatibleSpannerMultipleItemNativeType(Predicate<Class> testFunc)
    • write

      public void write(Object source, MultipleValueBinder sink)
      Specified by:
      write in interface org.springframework.data.convert.EntityWriter<Object,MultipleValueBinder>
    • write

      public void write(Object source, MultipleValueBinder sink, Set<String> includeColumns)
      Writes an object's properties to the sink.
      Specified by:
      write in interface SpannerEntityWriter
      Parameters:
      source - the object to write
      sink - the sink to which to write
      includeColumns - the columns to write. If null, then all columns are written.
    • convertToKey

      public com.google.cloud.spanner.Key convertToKey(Object key)
      Description copied from interface: SpannerEntityWriter
      Convert a given object to a Cloud Spanner key.
      Specified by:
      convertToKey in interface SpannerEntityWriter
      Parameters:
      key - the object containing the key values. This can already be a Cloud Spanner key, a single key component, or an array of key components.
      Returns:
      the Cloud Spanner key.
    • getSpannerWriteConverter

      public SpannerWriteConverter getSpannerWriteConverter()
      Description copied from interface: SpannerEntityWriter
      Get the SpannerWriteConverter used to convert types into Cloud Spanner compatible types.
      Specified by:
      getSpannerWriteConverter in interface SpannerEntityWriter
      Returns:
      a SpannerWriteConverter
    • attemptSetIterableValueOnBinder

      public static boolean attemptSetIterableValueOnBinder(Iterable<Object> value, com.google.cloud.spanner.ValueBinder valueBinder, SpannerCustomConverter writeConverter, Class innerType)
      Bind an iterable value to a ValueBinder.
      Parameters:
      value - the value to bind.
      valueBinder - the binder that accepts the value.
      writeConverter - the converter to use to convert the values.
      innerType - the type of the items in the iterable.
      Returns:
      true if the binding was successful.
    • attemptBindSingleValue

      public static boolean attemptBindSingleValue(Object propertyValue, Class<?> propertyType, com.google.cloud.spanner.ValueBinder valueBinder, SpannerCustomConverter spannerCustomConverter)
      Bind a value to a ValueBinder.
      Parameters:
      propertyValue - the value to bind.
      propertyType - the type of the value to bind.
      valueBinder - the binder.
      spannerCustomConverter - the converter used to convert if necessary.
      Returns:
      true if the value was bound successfully.