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 Summary
ConstructorsConstructorDescriptionConverterAwareMappingSpannerEntityProcessor(SpannerMappingContext spannerMappingContext) ConverterAwareMappingSpannerEntityProcessor(SpannerMappingContext spannerMappingContext, Collection<org.springframework.core.convert.converter.Converter> writeConverters, Collection<org.springframework.core.convert.converter.Converter> readConverters) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.cloud.spanner.KeyconvertToKey(Object key) Convert a given object to a Cloud Spanner key.Class<?>getCorrespondingSpannerJavaType(Class originalType, boolean isIterableInnerType) Gets the type that will work for both read and writes with Spanner directly.Get the read converter used by this processor.Get the SpannerWriteConverter used to convert types into Cloud Spanner compatible types.Get the write converter used by this processor.<T> List<T>Converts a set of SpannerResultSetinto a list of objects.<T> List<T>mapToList(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, String... includeColumns) Converts a set of SpannerResultSetinto a list of objects.<T> List<T>mapToList(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, Set<String> includeColumns, boolean allowMissingColumns) Converts a SpannerResultSetinto a list of objects.default <R> R<R> Rread(Class<R> type, com.google.cloud.spanner.Struct source, Set<String> includeColumns, boolean allowMissingColumns) voidwrite(Object source, MultipleValueBinder sink) Writes each of the source properties to the sink.voidwrite(Object source, MultipleValueBinder sink, Set<String> includeColumns) Writes an object's properties to the sink.
-
Constructor Details
-
ConverterAwareMappingSpannerEntityProcessor
-
ConverterAwareMappingSpannerEntityProcessor
public ConverterAwareMappingSpannerEntityProcessor(SpannerMappingContext spannerMappingContext, Collection<org.springframework.core.convert.converter.Converter> writeConverters, Collection<org.springframework.core.convert.converter.Converter> readConverters)
-
-
Method Details
-
mapToList
Description copied from interface:SpannerEntityProcessorConverts a set of SpannerResultSetinto a list of objects.- Specified by:
mapToListin interfaceSpannerEntityProcessor- 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:SpannerEntityProcessorConverts a SpannerResultSetinto a list of objects.- Specified by:
mapToListin interfaceSpannerEntityProcessor- 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:SpannerEntityProcessorConverts a set of SpannerResultSetinto a list of objects.- Specified by:
mapToListin interfaceSpannerEntityProcessor- 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
Description copied from interface:SpannerEntityProcessorGets the type that will work for both read and writes with Spanner directly.- Specified by:
getCorrespondingSpannerJavaTypein interfaceSpannerEntityProcessor- 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
Writes each of the source properties to the sink.- Specified by:
writein interfaceorg.springframework.data.convert.EntityWriter<Object,MultipleValueBinder> - Parameters:
source- entity to be writtensink- the stateful multiple-value-binder as a target for writing.
-
write
Description copied from interface:SpannerEntityWriterWrites an object's properties to the sink.- Specified by:
writein interfaceSpannerEntityWriter- Parameters:
source- the object to writesink- the sink to which to writeincludeColumns- the properties/columns to write. If null, then all columns are written.
-
convertToKey
Description copied from interface:SpannerEntityWriterConvert a given object to a Cloud Spanner key.- Specified by:
convertToKeyin interfaceSpannerEntityWriter- 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
Description copied from interface:SpannerEntityWriterGet the SpannerWriteConverter used to convert types into Cloud Spanner compatible types.- Specified by:
getSpannerWriteConverterin interfaceSpannerEntityWriter- Returns:
- a SpannerWriteConverter
-
read
-
getWriteConverter
Description copied from interface:SpannerEntityProcessorGet the write converter used by this processor.- Specified by:
getWriteConverterin interfaceSpannerEntityProcessor- Returns:
- the write converter.
-
getReadConverter
Description copied from interface:SpannerEntityProcessorGet the read converter used by this processor.- Specified by:
getReadConverterin interfaceSpannerEntityProcessor- Returns:
- the read converter.
-
read
- Specified by:
readin interfaceorg.springframework.data.convert.EntityReader<Object,com.google.cloud.spanner.Struct>
-