#413 - Introduce constructor to R2dbcEntityTemplate accepting ConnectionFactory.
This is a short-cut constructor that allows for simpler creation of the Template API.
This commit is contained in:
@@ -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
|
||||
|
||||
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}.
|
||||
*
|
||||
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user