Browse Source

#413 - Introduce constructor to R2dbcEntityTemplate accepting ConnectionFactory.

This is a short-cut constructor that allows for simpler creation of the Template API.
pull/1188/head
Mark Paluch 5 years ago
parent
commit
c23485d90e
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 20
      src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
  2. 2
      src/test/java/org/springframework/data/r2dbc/documentation/R2dbcEntityTemplateSnippets.java

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

@ -51,6 +51,7 @@ import org.springframework.data.mapping.context.MappingContext; @@ -51,6 +51,7 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionInformation;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.r2dbc.convert.R2dbcConverter;
import org.springframework.data.r2dbc.dialect.DialectResolver;
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
import org.springframework.data.r2dbc.mapping.OutboundRow;
import org.springframework.data.r2dbc.mapping.event.AfterConvertCallback;
@ -101,6 +102,25 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -101,6 +102,25 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
private @Nullable ReactiveEntityCallbacks entityCallbacks;
/**
* Create a new {@link R2dbcEntityTemplate} given {@link ConnectionFactory}.
*
* @param connectionFactory must not be {@literal null}.
* @since 1.2
*/
public R2dbcEntityTemplate(ConnectionFactory connectionFactory) {
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
R2dbcDialect dialect = DialectResolver.getDialect(connectionFactory);
this.databaseClient = DatabaseClient.builder().connectionFactory(connectionFactory)
.bindMarkers(dialect.getBindMarkersFactory()).build();
this.dataAccessStrategy = new DefaultReactiveDataAccessStrategy(dialect);
this.mappingContext = dataAccessStrategy.getConverter().getMappingContext();
this.projectionFactory = new SpelAwareProxyProjectionFactory();
}
/**
* Create a new {@link R2dbcEntityTemplate} given {@link DatabaseClient}.
*

2
src/test/java/org/springframework/data/r2dbc/documentation/R2dbcEntityTemplateSnippets.java

@ -76,7 +76,7 @@ class R2dbcEntityTemplateSnippets { @@ -76,7 +76,7 @@ class R2dbcEntityTemplateSnippets {
// tag::insert[]
Mono<Person> insert = template.insert(Person.class) // <1>
.using(new Person()); // <2>
.using(new Person("John", "Doe")); // <2>
// end::insert[]
}

Loading…
Cancel
Save