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
ConstructorDescriptionConverterAwareMappingSpannerEntityProcessor
(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.Key
convertToKey
(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 SpannerResultSet
into a list of objects.<T> List<T>
mapToList
(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, String... includeColumns) Converts a set of SpannerResultSet
into a list of objects.<T> List<T>
mapToList
(com.google.cloud.spanner.ResultSet resultSet, Class<T> entityClass, Set<String> includeColumns, boolean allowMissingColumns) Converts a SpannerResultSet
into a list of objects.default <R> R
<R> R
read
(Class<R> type, com.google.cloud.spanner.Struct source, Set<String> includeColumns, boolean allowMissingColumns) void
write
(Object source, MultipleValueBinder sink) Writes each of the source properties to the sink.void
write
(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:SpannerEntityProcessor
Converts a set of SpannerResultSet
into a list of objects.- Specified by:
mapToList
in 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:SpannerEntityProcessor
Converts a SpannerResultSet
into a list of objects.- Specified by:
mapToList
in 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:SpannerEntityProcessor
Converts a set of SpannerResultSet
into a list of objects.- Specified by:
mapToList
in 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:SpannerEntityProcessor
Gets the type that will work for both read and writes with Spanner directly.- Specified by:
getCorrespondingSpannerJavaType
in 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:
write
in 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:SpannerEntityWriter
Writes an object's properties to the sink.- Specified by:
write
in 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:SpannerEntityWriter
Convert a given object to a Cloud Spanner key.- Specified by:
convertToKey
in 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:SpannerEntityWriter
Get the SpannerWriteConverter used to convert types into Cloud Spanner compatible types.- Specified by:
getSpannerWriteConverter
in interfaceSpannerEntityWriter
- Returns:
- a SpannerWriteConverter
-
read
-
getWriteConverter
Description copied from interface:SpannerEntityProcessor
Get the write converter used by this processor.- Specified by:
getWriteConverter
in interfaceSpannerEntityProcessor
- Returns:
- the write converter.
-
getReadConverter
Description copied from interface:SpannerEntityProcessor
Get the read converter used by this processor.- Specified by:
getReadConverter
in interfaceSpannerEntityProcessor
- Returns:
- the read converter.
-
read
- Specified by:
read
in interfaceorg.springframework.data.convert.EntityReader<Object,
com.google.cloud.spanner.Struct>
-