Skip to content

Commit a1081bb

Browse files
committed
#447 - Deprecate ReactiveDataAccessStrategy.
ReactiveDataAccessStrategy is now deprecated in favor of using StatementMapper, UpdateMapper, and R2dbcConverter directly. The access strategy interface was introduced to allow pluggable access strategies in DatabaseClient. With moving DatabaseClient into Spring Framework, this approach is no longer required.
1 parent 28edf27 commit a1081bb

File tree

8 files changed

+57
-17
lines changed

8 files changed

+57
-17
lines changed

src/main/asciidoc/reference/mapping.adoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Other strategies can also be put in place (if there is demand).
174174
[[mapping.custom.object.construction]]
175175
=== Customized Object Construction
176176

177-
The mapping subsystem allows the customization of the object construction by annotating a constructor with the `@PersistenceConstructor` annotation. The values to be used for the constructor parameters are resolved in the following way:
177+
The mapping subsystem allows the customization of the object construction by annotating a constructor with the `@PersistenceConstructor` annotation.The values to be used for the constructor parameters are resolved in the following way:
178178

179179
* If a parameter is annotated with the `@Value` annotation, the given expression is evaluated, and the result is used as the parameter value.
180180
* If the Java type has a property whose name matches the given field of the input row, then its property information is used to select the appropriate constructor parameter to which to pass the input field value.
@@ -212,7 +212,8 @@ To selectively handle the conversion yourself, register one or more one or more
212212
You can use the `r2dbcCustomConversions` method in `AbstractR2dbcConfiguration` to configure converters.
213213
The examples <<mapping.configuration, at the beginning of this chapter>> show how to perform the configuration with Java.
214214

215-
NOTE: Custom top-level entity conversion requires asymmetric types for conversion.Inbound data is extracted from R2DBC's `Row`.
215+
NOTE: Custom top-level entity conversion requires asymmetric types for conversion.
216+
Inbound data is extracted from R2DBC's `Row`.
216217
Outbound data (to be used with `INSERT`/`UPDATE` statements) is represented as `OutboundRow` and later assembled to a statement.
217218

218219
The following example of a Spring Converter implementation converts from a `Row` to a `Person` POJO:

src/main/asciidoc/reference/r2dbc-repositories.adoc

+3-7
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ When working with multiple, potentially different databases, your application wi
391391
The provided `AbstractR2dbcConfiguration` support class assumes a single `ConnectionFactory` from which the `Dialect` gets derived.
392392
That being said, you need to define a few beans yourself to configure Spring Data R2DBC to work with multiple databases.
393393

394-
R2DBC repositories require either a `DatabaseClient` and `ReactiveDataAccessStrategy` or `R2dbcEntityOperations` to implement repositories.
394+
R2DBC repositories require `R2dbcEntityOperations` to implement repositories.
395395
A simple configuration to scan for repositories without using `AbstractR2dbcConfiguration` looks like:
396396

397397
[source,java]
@@ -409,13 +409,9 @@ static class MySQLConfiguration {
409409
@Bean
410410
public R2dbcEntityOperations mysqlR2dbcEntityOperations(@Qualifier("mysql") ConnectionFactory connectionFactory) {
411411
412-
DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy(MySqlDialect.INSTANCE);
413-
DatabaseClient databaseClient = DatabaseClient.builder()
414-
.connectionFactory(connectionFactory)
415-
.dataAccessStrategy(strategy)
416-
.build();
412+
DatabaseClient databaseClient = DatabaseClient.create(connectionFactory);
417413
418-
return new R2dbcEntityTemplate(databaseClient, strategy);
414+
return new R2dbcEntityTemplate(databaseClient, MySqlDialect.INSTANCE);
419415
}
420416
}
421417
----

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

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.dao.DataAccessException;
2222
import org.springframework.dao.TransientDataAccessResourceException;
23+
import org.springframework.data.r2dbc.convert.R2dbcConverter;
2324
import org.springframework.data.relational.core.query.Query;
2425
import org.springframework.data.relational.core.query.Update;
2526
import org.springframework.r2dbc.core.DatabaseClient;
@@ -49,9 +50,20 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations {
4950
* @return the underlying {@link ReactiveDataAccessStrategy}.
5051
* @see ReactiveDataAccessStrategy
5152
* @since 1.1.3
53+
* @deprecated use {@link #getConverter()} instead as {@link ReactiveDataAccessStrategy} will be removed in a future
54+
* release.
5255
*/
56+
@Deprecated
5357
ReactiveDataAccessStrategy getDataAccessStrategy();
5458

59+
/**
60+
* Return the underlying {@link R2dbcConverter}.
61+
*
62+
* @return the underlying {@link R2dbcConverter}.
63+
* @since 1.2
64+
*/
65+
R2dbcConverter getConverter();
66+
5567
// -------------------------------------------------------------------------
5668
// Methods dealing with org.springframework.data.r2dbc.query.Query
5769
// -------------------------------------------------------------------------

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

+24
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.springframework.data.mapping.context.MappingContext;
5151
import org.springframework.data.projection.ProjectionInformation;
5252
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
53+
import org.springframework.data.r2dbc.convert.R2dbcConverter;
5354
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
5455
import org.springframework.data.r2dbc.mapping.OutboundRow;
5556
import org.springframework.data.r2dbc.mapping.event.AfterConvertCallback;
@@ -122,6 +123,20 @@ public R2dbcEntityTemplate(org.springframework.data.r2dbc.core.DatabaseClient da
122123
this(databaseClient, getDataAccessStrategy(databaseClient));
123124
}
124125

126+
/**
127+
* Create a new {@link R2dbcEntityTemplate} given {@link DatabaseClient}, {@link R2dbcDialect} and
128+
* {@link R2dbcConverter}.
129+
*
130+
* @param databaseClient must not be {@literal null}.
131+
* @param dialect the dialect to use, must not be {@literal null}.
132+
* @param converter the dialect to use, must not be {@literal null}.
133+
* @since 1.2
134+
*/
135+
public R2dbcEntityTemplate(org.springframework.r2dbc.core.DatabaseClient databaseClient, R2dbcDialect dialect,
136+
R2dbcConverter converter) {
137+
this(databaseClient, new DefaultReactiveDataAccessStrategy(dialect, converter));
138+
}
139+
125140
/**
126141
* Create a new {@link R2dbcEntityTemplate} given {@link DatabaseClient} and {@link ReactiveDataAccessStrategy}.
127142
*
@@ -170,6 +185,15 @@ public ReactiveDataAccessStrategy getDataAccessStrategy() {
170185
return this.dataAccessStrategy;
171186
}
172187

188+
/*
189+
* (non-Javadoc)
190+
* @see org.springframework.data.r2dbc.core.R2dbcEntityOperations#getConverter()
191+
*/
192+
@Override
193+
public R2dbcConverter getConverter() {
194+
return this.dataAccessStrategy.getConverter();
195+
}
196+
173197
/*
174198
* (non-Javadoc)
175199
* @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)

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

+3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
*
3838
* @author Mark Paluch
3939
* @see org.springframework.r2dbc.core.PreparedOperation
40+
* @deprecated since 1.2 in favor of using direct usage of {@link StatementMapper},
41+
* {@link org.springframework.data.r2dbc.query.UpdateMapper} and {@link R2dbcConverter}.
4042
*/
43+
@Deprecated
4144
public interface ReactiveDataAccessStrategy {
4245

4346
/**

src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@
122122
*
123123
* @return
124124
* @see #entityOperationsRef()
125+
* @deprecated since 1.2, in favor of {@link #entityOperationsRef()}.
125126
*/
126-
String databaseClientRef() default "r2dbcDatabaseClient";
127+
@Deprecated
128+
String databaseClientRef() default "";
127129

128130
/**
129131
* Configures the name of the {@link org.springframework.data.r2dbc.core.R2dbcEntityOperations} bean to be used with
@@ -134,7 +136,7 @@
134136
* @return
135137
* @since 1.1.3
136138
*/
137-
String entityOperationsRef() default "";
139+
String entityOperationsRef() default "r2dbcEntityTemplate";
138140

139141
/**
140142
* Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the

src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfi
9898

9999
AnnotationAttributes attributes = config.getAttributes();
100100

101-
String entityOperationsRef = attributes.getString("entityOperationsRef");
102-
if (StringUtils.hasText(entityOperationsRef)) {
103-
builder.addPropertyReference("entityOperations", entityOperationsRef);
104-
} else {
101+
String databaseClientRef = attributes.getString("databaseClientRef");
102+
if (StringUtils.hasText(databaseClientRef)) {
105103
builder.addPropertyReference("databaseClient", attributes.getString("databaseClientRef"));
106104
builder.addPropertyReference("dataAccessStrategy", "reactiveDataAccessStrategy");
105+
} else {
106+
builder.addPropertyReference("entityOperations", attributes.getString("entityOperationsRef"));
107107
}
108108
}
109109

src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrarTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ public class R2dbcRepositoriesRegistrarTests {
5050
static class EnableWithDatabaseClient {
5151

5252
@Bean
53-
public DatabaseClient r2dbcDatabaseClient() {
54-
return mock(DatabaseClient.class);
53+
public R2dbcEntityTemplate r2dbcEntityTemplate() {
54+
R2dbcEntityTemplate template = mock(R2dbcEntityTemplate.class);
55+
when(template.getDataAccessStrategy()).thenReturn(reactiveDataAccessStrategy());
56+
return template;
5557
}
5658

5759
@Bean

0 commit comments

Comments
 (0)