Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 5714709

Browse files
committed
spring-projects#30 - Polishing.
Fix custom converter documentation. Accept custom converters in DefaultReactiveDataAccessStrategy constructor.
1 parent 14e2a37 commit 5714709

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/main/asciidoc/reference/mapping.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public class PersonWriteConverter implements Converter<Person, OutboundRow> {
180180
181181
public OutboundRow convert(Person source) {
182182
OutboundRow row = new OutboundRow();
183-
row.put("_d", source.getId());
184-
row.put("name", source.getFirstName());
185-
row.put("age", source.getAge());
183+
row.put("_d", SettableValue.from(source.getId()));
184+
row.put("name", SettableValue.from(source.getFirstName()));
185+
row.put("age", SettableValue.from(source.getAge()));
186186
return row;
187187
}
188188
}

src/main/java/org/springframework/data/r2dbc/convert/R2dbcCustomConversions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class R2dbcCustomConversions extends CustomConversions {
4040
* @param converters must not be {@literal null}.
4141
*/
4242
public R2dbcCustomConversions(Collection<?> converters) {
43-
super(STORE_CONVERSIONS, appendOverriddes(converters));
43+
super(STORE_CONVERSIONS, appendOverrides(converters));
4444
}
4545

4646
/**
@@ -50,10 +50,10 @@ public R2dbcCustomConversions(Collection<?> converters) {
5050
* @param converters must not be {@literal null}.
5151
*/
5252
public R2dbcCustomConversions(StoreConversions storeConversions, Collection<?> converters) {
53-
super(storeConversions, appendOverriddes(converters));
53+
super(storeConversions, appendOverrides(converters));
5454
}
5555

56-
private static Collection<?> appendOverriddes(Collection<?> converters) {
56+
private static Collection<?> appendOverrides(Collection<?> converters) {
5757

5858
List<Object> objects = new ArrayList<>(converters);
5959
objects.addAll(R2dbcConverters.getOverrideConvertersToRegister());

src/main/java/org/springframework/data/r2dbc/core/DefaultReactiveDataAccessStrategy.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import io.r2dbc.spi.RowMetadata;
2020

2121
import java.util.ArrayList;
22+
import java.util.Collection;
2223
import java.util.Collections;
2324
import java.util.List;
2425
import java.util.function.BiFunction;
2526
import java.util.function.Function;
2627

28+
import org.springframework.core.annotation.AnnotatedElementUtils;
2729
import org.springframework.dao.InvalidDataAccessResourceUsageException;
2830
import org.springframework.data.convert.CustomConversions.StoreConversions;
2931
import org.springframework.data.mapping.context.MappingContext;
@@ -37,9 +39,11 @@
3739
import org.springframework.data.r2dbc.mapping.OutboundRow;
3840
import org.springframework.data.r2dbc.mapping.SettableValue;
3941
import org.springframework.data.r2dbc.query.UpdateMapper;
42+
import org.springframework.data.relational.core.mapping.NamingStrategy;
4043
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4144
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4245
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
46+
import org.springframework.data.relational.core.mapping.Table;
4347
import org.springframework.data.relational.core.sql.Select;
4448
import org.springframework.data.relational.core.sql.render.NamingStrategies;
4549
import org.springframework.data.relational.core.sql.render.RenderContext;
@@ -48,6 +52,7 @@
4852
import org.springframework.lang.Nullable;
4953
import org.springframework.util.Assert;
5054
import org.springframework.util.ClassUtils;
55+
import org.springframework.util.StringUtils;
5156

5257
/**
5358
* Default {@link ReactiveDataAccessStrategy} implementation.
@@ -63,21 +68,35 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
6368
private final StatementMapper statementMapper;
6469

6570
/**
66-
* Creates a new {@link DefaultReactiveDataAccessStrategy} given {@link Dialect}.
71+
* Creates a new {@link DefaultReactiveDataAccessStrategy} given {@link Dialect} and optional
72+
* {@link org.springframework.core.convert.converter.Converter}s.
6773
*
6874
* @param dialect the {@link Dialect} to use.
6975
*/
7076
public DefaultReactiveDataAccessStrategy(Dialect dialect) {
71-
this(dialect, createConverter(dialect));
77+
this(dialect, Collections.emptyList());
7278
}
7379

74-
private static R2dbcConverter createConverter(Dialect dialect) {
80+
/**
81+
* Creates a new {@link DefaultReactiveDataAccessStrategy} given {@link Dialect} and optional
82+
* {@link org.springframework.core.convert.converter.Converter}s.
83+
*
84+
* @param dialect the {@link Dialect} to use.
85+
* @param converters custom converters to register, must not be {@literal null}.
86+
* @see R2dbcCustomConversions
87+
* @see org.springframework.core.convert.converter.Converter
88+
*/
89+
public DefaultReactiveDataAccessStrategy(Dialect dialect, Collection<?> converters) {
90+
this(dialect, createConverter(dialect, converters));
91+
}
92+
93+
private static R2dbcConverter createConverter(Dialect dialect, Collection<?> converters) {
7594

7695
Assert.notNull(dialect, "Dialect must not be null");
96+
Assert.notNull(converters, "Converters must not be null");
7797

7898
R2dbcCustomConversions customConversions = new R2dbcCustomConversions(
79-
StoreConversions.of(dialect.getSimpleTypeHolder(), R2dbcCustomConversions.STORE_CONVERTERS),
80-
Collections.emptyList());
99+
StoreConversions.of(dialect.getSimpleTypeHolder(), R2dbcCustomConversions.STORE_CONVERTERS), converters);
81100

82101
RelationalMappingContext context = new RelationalMappingContext();
83102
context.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());

0 commit comments

Comments
 (0)