Class ConverterAwareMappingSpannerEntityProcessor

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

public class ConverterAwareMappingSpannerEntityProcessor extends Object implements SpannerEntityProcessor
The primary class for writing entity objects to Spanner and creating entity objects from rows stored in Spanner.
Since:
1.1
  • Constructor Details

    • ConverterAwareMappingSpannerEntityProcessor

      public ConverterAwareMappingSpannerEntityProcessor(SpannerMappingContext spannerMappingContext)
    • ConverterAwareMappingSpannerEntityProcessor

      public ConverterAwareMappingSpannerEntityProcessor(SpannerMappingContext spannerMappingContext, Collection<org.springframework.core.convert.converter.Converter> writeConverters, Collection<org.springframework.core.convert.converter.Converter> readConverters)
  • Method Details

    • mapToList

      public <T> List<T> mapToList(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass)
      Description copied from interface: SpannerEntityProcessor
      Converts a set of Spanner ResultSet into a list of objects.
      Specified by:
      mapToList in interface SpannerEntityProcessor
      Type Parameters:
      T - the type of the objects the Spanner results represent.
      Parameters:
      resultSet - the Spanner results to convert. The ResultSet will be exhausted and closed.
      entityClass - the type of the objects the Spanner results represent.
      Returns:
      a list of objects.
    • mapToList

      public <T> List<T> mapToList(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, Set<String> includeColumns, boolean allowMissingColumns)
      Description copied from interface: SpannerEntityProcessor
      Converts a Spanner ResultSet into a list of objects.
      Specified by:
      mapToList in interface SpannerEntityProcessor
      Type Parameters:
      T - the type of the objects the Spanner results represent.
      Parameters:
      resultSet - the Spanner results to convert. The ResultSet will be exhausted and closed.
      entityClass - the type of the objects the Spanner results represent.
      includeColumns - the Set of columns to read. If this param is null then all columns will be read.
      allowMissingColumns - if true, then properties with no corresponding column are not mapped. If false, then an exception is thrown.
      Returns:
      a list of objects.
    • mapToList

      public <T> List<T> mapToList(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, String... includeColumns)
      Description copied from interface: SpannerEntityProcessor
      Converts a set of Spanner ResultSet into a list of objects.
      Specified by:
      mapToList in interface SpannerEntityProcessor
      Type Parameters:
      T - the type of the objects the Spanner results represent.
      Parameters:
      resultSet - the Spanner results to convert. The ResultSet will be exhausted and closed.
      entityClass - the type of the objects the Spanner results represent.
      includeColumns - the columns to read. If none are provided then all columns are read.
      Returns:
      a list of objects.
    • getCorrespondingSpannerJavaType

      public Class<?> getCorrespondingSpannerJavaType(Class originalType, boolean isIterableInnerType)
      Description copied from interface: SpannerEntityProcessor
      Gets the type that will work for both read and writes with Spanner directly.
      Specified by:
      getCorrespondingSpannerJavaType in interface SpannerEntityProcessor
      Parameters:
      originalType - the original type that is possibly convertable by this converter.
      isIterableInnerType - true if the given type refers to an inner type. This is significant because Spanner does not support the same types as singular items and as array elements.
      Returns:
      the Java type that works directly with Spanner.
    • write

      public void write(Object source, MultipleValueBinder sink)
      Writes each of the source properties to the sink.
      Specified by:
      write in interface org.springframework.data.convert.EntityWriter<Object,MultipleValueBinder>
      Parameters:
      source - entity to be written
      sink - the stateful multiple-value-binder as a target for writing.
    • write

      public void write(Object source, MultipleValueBinder sink, Set<String> includeColumns)
      Description copied from interface: SpannerEntityWriter
      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 properties/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
    • read

      public <R> R read(Class<R> type, com.google.cloud.spanner.Struct source, Set<String> includeColumns, boolean allowMissingColumns)
    • getWriteConverter

      public SpannerWriteConverter getWriteConverter()
      Description copied from interface: SpannerEntityProcessor
      Get the write converter used by this processor.
      Specified by:
      getWriteConverter in interface SpannerEntityProcessor
      Returns:
      the write converter.
    • getReadConverter

      public SpannerReadConverter getReadConverter()
      Description copied from interface: SpannerEntityProcessor
      Get the read converter used by this processor.
      Specified by:
      getReadConverter in interface SpannerEntityProcessor
      Returns:
      the read converter.
    • read

      default <R> R read(Class<R> type, com.google.cloud.spanner.Struct source)
      Specified by:
      read in interface org.springframework.data.convert.EntityReader<Object,com.google.cloud.spanner.Struct>