From 20eb2c1a6d9f56abc93d5fb767f910b75a92fc67 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 3 Sep 2018 14:28:45 +0200 Subject: [PATCH] #2 - Resolve package cycle between r2dbc.function and r2dbc.function.convert. --- .../r2dbc/function/DefaultDatabaseClient.java | 2 +- .../DefaultReactiveDataAccessStrategy.java | 1 + .../function/ReactiveDataAccessStrategy.java | 70 +++++------------- .../convert/MappingR2dbcConverter.java | 1 - .../r2dbc/function/convert/SettableValue.java | 71 +++++++++++++++++++ .../support/SimpleR2dbcRepository.java | 2 +- 6 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 src/main/java/org/springframework/data/r2dbc/function/convert/SettableValue.java diff --git a/src/main/java/org/springframework/data/r2dbc/function/DefaultDatabaseClient.java b/src/main/java/org/springframework/data/r2dbc/function/DefaultDatabaseClient.java index 0b4ce1e..7aac79b 100644 --- a/src/main/java/org/springframework/data/r2dbc/function/DefaultDatabaseClient.java +++ b/src/main/java/org/springframework/data/r2dbc/function/DefaultDatabaseClient.java @@ -52,9 +52,9 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.NullHandling; import org.springframework.data.domain.Sort.Order; import org.springframework.data.r2dbc.UncategorizedR2dbcException; -import org.springframework.data.r2dbc.function.ReactiveDataAccessStrategy.SettableValue; import org.springframework.data.r2dbc.function.connectionfactory.ConnectionProxy; import org.springframework.data.r2dbc.function.convert.ColumnMapRowMapper; +import org.springframework.data.r2dbc.function.convert.SettableValue; import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator; import org.springframework.jdbc.core.SqlProvider; import org.springframework.lang.Nullable; diff --git a/src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java b/src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java index 332bcb4..7a4a282 100644 --- a/src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java +++ b/src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java @@ -28,6 +28,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.r2dbc.function.convert.EntityRowMapper; +import org.springframework.data.r2dbc.function.convert.SettableValue; import org.springframework.data.relational.core.conversion.BasicRelationalConverter; import org.springframework.data.relational.core.conversion.RelationalConverter; import org.springframework.data.relational.core.mapping.RelationalMappingContext; diff --git a/src/main/java/org/springframework/data/r2dbc/function/ReactiveDataAccessStrategy.java b/src/main/java/org/springframework/data/r2dbc/function/ReactiveDataAccessStrategy.java index 76711a5..20024a2 100644 --- a/src/main/java/org/springframework/data/r2dbc/function/ReactiveDataAccessStrategy.java +++ b/src/main/java/org/springframework/data/r2dbc/function/ReactiveDataAccessStrategy.java @@ -22,72 +22,40 @@ import java.util.List; import java.util.function.BiFunction; import org.springframework.data.domain.Sort; -import org.springframework.lang.Nullable; +import org.springframework.data.r2dbc.function.convert.SettableValue; /** * @author Mark Paluch */ public interface ReactiveDataAccessStrategy { + /** + * @param typeToRead + * @return all field names for a specific type. + */ List getAllFields(Class typeToRead); + /** + * @param object + * @return {@link SettableValue} that represent an {@code INSERT} of {@code object}. + */ List getInsert(Object object); + /** + * Map the {@link Sort} object to apply field name mapping using {@link Class the type to read}. + * + * @param typeToRead + * @param sort + * @return + */ Sort getMappedSort(Class typeToRead, Sort sort); // TODO: Broaden T to Mono/Flux for reactive relational data access? BiFunction getRowMapper(Class typeToRead); - String getTableName(Class type); - /** - * A database value that can be set in a statement. + * @param type + * @return the table name for the {@link Class entity type}. */ - class SettableValue { - - private final Object identifier; - private final @Nullable Object value; - private final Class type; - - /** - * Create a {@link SettableValue} using an integer index. - * - * @param index - * @param value - * @param type - */ - public SettableValue(int index, @Nullable Object value, Class type) { - - this.identifier = index; - this.value = value; - this.type = type; - } - - /** - * Create a {@link SettableValue} using a {@link String} identifier. - * - * @param identifier - * @param value - * @param type - */ - public SettableValue(String identifier, @Nullable Object value, Class type) { - - this.identifier = identifier; - this.value = value; - this.type = type; - } - - public Object getIdentifier() { - return identifier; - } - - @Nullable - public Object getValue() { - return value; - } - - public Class getType() { - return type; - } - } + String getTableName(Class type); } diff --git a/src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java b/src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java index 21fb76c..b187e67 100644 --- a/src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java +++ b/src/main/java/org/springframework/data/r2dbc/function/convert/MappingR2dbcConverter.java @@ -26,7 +26,6 @@ import java.util.function.BiFunction; import org.springframework.core.convert.ConversionService; import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.r2dbc.function.ReactiveDataAccessStrategy.SettableValue; import org.springframework.data.relational.core.conversion.RelationalConverter; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; diff --git a/src/main/java/org/springframework/data/r2dbc/function/convert/SettableValue.java b/src/main/java/org/springframework/data/r2dbc/function/convert/SettableValue.java new file mode 100644 index 0000000..8338b16 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/function/convert/SettableValue.java @@ -0,0 +1,71 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.r2dbc.function.convert; + +import org.springframework.lang.Nullable; + +/** + * A database value that can be set in a statement. + * + * @author Mark Paluch + */ +public class SettableValue { + + private final Object identifier; + private final @Nullable Object value; + private final Class type; + + /** + * Create a {@link SettableValue} using an integer index. + * + * @param index + * @param value + * @param type + */ + public SettableValue(int index, @Nullable Object value, Class type) { + + this.identifier = index; + this.value = value; + this.type = type; + } + + /** + * Create a {@link SettableValue} using a {@link String} identifier. + * + * @param identifier + * @param value + * @param type + */ + public SettableValue(String identifier, @Nullable Object value, Class type) { + + this.identifier = identifier; + this.value = value; + this.type = type; + } + + public Object getIdentifier() { + return identifier; + } + + @Nullable + public Object getValue() { + return value; + } + + public Class getType() { + return type; + } +} diff --git a/src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java b/src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java index 03537b9..b72b016 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java @@ -30,8 +30,8 @@ import org.springframework.data.r2dbc.function.DatabaseClient; import org.springframework.data.r2dbc.function.DatabaseClient.BindSpec; import org.springframework.data.r2dbc.function.DatabaseClient.GenericExecuteSpec; import org.springframework.data.r2dbc.function.FetchSpec; -import org.springframework.data.r2dbc.function.ReactiveDataAccessStrategy.SettableValue; import org.springframework.data.r2dbc.function.convert.MappingR2dbcConverter; +import org.springframework.data.r2dbc.function.convert.SettableValue; import org.springframework.data.relational.repository.query.RelationalEntityInformation; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.util.Assert;