Search in sources :

Example 6 with PropertyHandler

use of org.springframework.data.mapping.PropertyHandler in project spring-cloud-gcp by spring-cloud.

the class MappingSpannerWriteConverter method write.

/**
 * Writes an object's properties to the sink.
 * @param source the object to write
 * @param sink the sink to which to write
 * @param includeColumns the properties/columns to write. If null, then all columns
 * are written.
 */
public void write(Object source, WriteBuilder sink, Set<String> includeColumns) {
    boolean writeAllColumns = includeColumns == null;
    SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext.getPersistentEntity(source.getClass());
    PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(source);
    persistentEntity.doWithProperties((PropertyHandler<SpannerPersistentProperty>) spannerPersistentProperty -> {
        if (!writeAllColumns && !includeColumns.contains(spannerPersistentProperty.getColumnName())) {
            return;
        }
        writeProperty(sink, accessor, spannerPersistentProperty);
    });
}
Also used : Date(com.google.cloud.Date) CustomConversions(org.springframework.data.convert.CustomConversions) ImmutableMap(com.google.common.collect.ImmutableMap) BiFunction(java.util.function.BiFunction) SpannerDataException(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerDataException) Set(java.util.Set) WriteBuilder(com.google.cloud.spanner.Mutation.WriteBuilder) Timestamp(com.google.cloud.Timestamp) PersistentPropertyAccessor(org.springframework.data.mapping.PersistentPropertyAccessor) PropertyHandler(org.springframework.data.mapping.PropertyHandler) SpannerPersistentProperty(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty) Map(java.util.Map) ValueBinder(com.google.cloud.spanner.ValueBinder) BiConsumer(java.util.function.BiConsumer) ByteArray(com.google.cloud.ByteArray) SpannerPersistentEntity(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentEntity) SpannerMappingContext(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerMappingContext) EntityWriter(org.springframework.data.convert.EntityWriter) PersistentPropertyAccessor(org.springframework.data.mapping.PersistentPropertyAccessor) SpannerPersistentProperty(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty)

Aggregations

PropertyHandler (org.springframework.data.mapping.PropertyHandler)6 Map (java.util.Map)4 Set (java.util.Set)4 List (java.util.List)3 MongoPersistentEntity (org.springframework.data.mongodb.core.mapping.MongoPersistentEntity)3 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)3 Assert (org.springframework.util.Assert)3 ByteArray (com.google.cloud.ByteArray)2 Date (com.google.cloud.Date)2 Timestamp (com.google.cloud.Timestamp)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BiFunction (java.util.function.BiFunction)2 Collectors (java.util.stream.Collectors)2 SpannerDataException (org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerDataException)2 SpannerMappingContext (org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerMappingContext)2 SpannerPersistentEntity (org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentEntity)2 SpannerPersistentProperty (org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty)2 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)2 CustomConversions (org.springframework.data.convert.CustomConversions)2 Sort (org.springframework.data.domain.Sort)2