Skip to content

Commit f1e79e9

Browse files
committed
#413 - Introduce constructor to R2dbcEntityTemplate accepting ConnectionFactory.
This is a short-cut constructor that allows for simpler creation of the Template API.
1 parent ce57b25 commit f1e79e9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.springframework.data.projection.ProjectionInformation;
5252
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
5353
import org.springframework.data.r2dbc.convert.R2dbcConverter;
54+
import org.springframework.data.r2dbc.dialect.DialectResolver;
5455
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
5556
import org.springframework.data.r2dbc.mapping.OutboundRow;
5657
import org.springframework.data.r2dbc.mapping.event.AfterConvertCallback;
@@ -101,6 +102,25 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
101102

102103
private @Nullable ReactiveEntityCallbacks entityCallbacks;
103104

105+
/**
106+
* Create a new {@link R2dbcEntityTemplate} given {@link ConnectionFactory}.
107+
*
108+
* @param connectionFactory must not be {@literal null}.
109+
* @since 1.2
110+
*/
111+
public R2dbcEntityTemplate(ConnectionFactory connectionFactory) {
112+
113+
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
114+
115+
R2dbcDialect dialect = DialectResolver.getDialect(connectionFactory);
116+
117+
this.databaseClient = DatabaseClient.builder().connectionFactory(connectionFactory)
118+
.bindMarkers(dialect.getBindMarkersFactory()).build();
119+
this.dataAccessStrategy = new DefaultReactiveDataAccessStrategy(dialect);
120+
this.mappingContext = dataAccessStrategy.getConverter().getMappingContext();
121+
this.projectionFactory = new SpelAwareProxyProjectionFactory();
122+
}
123+
104124
/**
105125
* Create a new {@link R2dbcEntityTemplate} given {@link DatabaseClient}.
106126
*

0 commit comments

Comments
 (0)