@@ -25,7 +25,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class SimpleConnectionHandle implements ConnectionHandle {
|
||||
public class SimpleConnectionHandle implements ConnectionHandle {
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.data.r2dbc.convert;
|
||||
import io.r2dbc.spi.ColumnMetadata;
|
||||
import io.r2dbc.spi.Row;
|
||||
import io.r2dbc.spi.RowMetadata;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Collection;
|
||||
@@ -434,14 +432,22 @@ public class MappingR2dbcConverter extends BasicRelationalConverter implements R
|
||||
return columns;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class RowParameterValueProvider implements ParameterValueProvider<RelationalPersistentProperty> {
|
||||
|
||||
private final @NonNull Row resultSet;
|
||||
private final Row resultSet;
|
||||
private final @Nullable RowMetadata metadata;
|
||||
private final @NonNull RelationalPersistentEntity<?> entity;
|
||||
private final @NonNull RelationalConverter converter;
|
||||
private final @NonNull String prefix;
|
||||
private final RelationalPersistentEntity<?> entity;
|
||||
private final RelationalConverter converter;
|
||||
private final String prefix;
|
||||
|
||||
public RowParameterValueProvider(Row resultSet, RowMetadata metadata, RelationalPersistentEntity<?> entity,
|
||||
RelationalConverter converter, String prefix) {
|
||||
this.resultSet = resultSet;
|
||||
this.metadata = metadata;
|
||||
this.entity = entity;
|
||||
this.converter = converter;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -15,17 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.core;
|
||||
|
||||
import io.r2dbc.spi.Connection;
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import io.r2dbc.spi.R2dbcException;
|
||||
import io.r2dbc.spi.Result;
|
||||
import io.r2dbc.spi.Row;
|
||||
import io.r2dbc.spi.RowMetadata;
|
||||
import io.r2dbc.spi.Statement;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -42,9 +31,18 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.r2dbc.spi.Connection;
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import io.r2dbc.spi.R2dbcException;
|
||||
import io.r2dbc.spi.Result;
|
||||
import io.r2dbc.spi.Row;
|
||||
import io.r2dbc.spi.RowMetadata;
|
||||
import io.r2dbc.spi.Statement;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -305,7 +303,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Base class for {@link DatabaseClient.GenericExecuteSpec} implementations.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class ExecuteSpecSupport {
|
||||
|
||||
final Map<Integer, SettableValue> byIndex;
|
||||
@@ -319,6 +316,13 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
this.sqlSupplier = sqlSupplier;
|
||||
}
|
||||
|
||||
ExecuteSpecSupport(Map<Integer, SettableValue> byIndex, Map<String, SettableValue> byName,
|
||||
Supplier<String> sqlSupplier) {
|
||||
this.byIndex = byIndex;
|
||||
this.byName = byName;
|
||||
this.sqlSupplier = sqlSupplier;
|
||||
}
|
||||
|
||||
<T> FetchSpec<T> exchange(Supplier<String> sqlSupplier, BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
|
||||
String sql = getRequiredSql(sqlSupplier);
|
||||
@@ -630,7 +634,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Base class for {@link DatabaseClient.GenericExecuteSpec} implementations.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
private abstract class DefaultSelectSpecSupport {
|
||||
|
||||
final String table;
|
||||
@@ -650,6 +653,14 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
this.page = Pageable.unpaged();
|
||||
}
|
||||
|
||||
DefaultSelectSpecSupport(String table, List<String> projectedFields, Criteria criteria, Sort sort, Pageable page) {
|
||||
this.table = table;
|
||||
this.projectedFields = projectedFields;
|
||||
this.criteria = criteria;
|
||||
this.sort = sort;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public DefaultSelectSpecSupport project(String... selectedFields) {
|
||||
Assert.notNull(selectedFields, "Projection fields must not be null!");
|
||||
|
||||
@@ -789,7 +800,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
private final @Nullable Class<T> typeToRead;
|
||||
private final BiFunction<Row, RowMetadata, T> mappingFunction;
|
||||
|
||||
DefaultTypedSelectSpec(Class<T> typeToRead) {
|
||||
DefaultTypedSelectSpec(@Nullable Class<T> typeToRead) {
|
||||
|
||||
super(dataAccessStrategy.getTableName(typeToRead));
|
||||
|
||||
@@ -798,7 +809,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
|
||||
DefaultTypedSelectSpec(String table, List<String> projectedFields, Criteria criteria, Sort sort, Pageable page,
|
||||
Class<T> typeToRead, BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
@Nullable Class<T> typeToRead, BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
|
||||
super(table, projectedFields, criteria, sort, page);
|
||||
|
||||
@@ -905,13 +916,19 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Default implementation of {@link DatabaseClient.GenericInsertSpec}.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class DefaultGenericInsertSpec<T> implements GenericInsertSpec<T> {
|
||||
|
||||
private final String table;
|
||||
private final Map<String, SettableValue> byName;
|
||||
private final BiFunction<Row, RowMetadata, T> mappingFunction;
|
||||
|
||||
DefaultGenericInsertSpec(String table, Map<String, SettableValue> byName,
|
||||
BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
this.table = table;
|
||||
this.byName = byName;
|
||||
this.mappingFunction = mappingFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericInsertSpec<T> value(String field, Object value) {
|
||||
|
||||
@@ -988,7 +1005,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Default implementation of {@link DatabaseClient.TypedInsertSpec}.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class DefaultTypedInsertSpec<T, R> implements TypedInsertSpec<T>, InsertSpec<R> {
|
||||
|
||||
private final Class<?> typeToInsert;
|
||||
@@ -1004,6 +1020,14 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
this.mappingFunction = mappingFunction;
|
||||
}
|
||||
|
||||
DefaultTypedInsertSpec(Class<?> typeToInsert, String table, Publisher<T> objectToInsert,
|
||||
BiFunction<Row, RowMetadata, R> mappingFunction) {
|
||||
this.typeToInsert = typeToInsert;
|
||||
this.table = table;
|
||||
this.objectToInsert = objectToInsert;
|
||||
this.mappingFunction = mappingFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedInsertSpec<T> table(String tableName) {
|
||||
|
||||
@@ -1118,7 +1142,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class DefaultGenericUpdateSpec implements GenericUpdateSpec, UpdateMatchingSpec {
|
||||
|
||||
private final @Nullable Class<?> typeToUpdate;
|
||||
@@ -1126,6 +1149,14 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
private final Update assignments;
|
||||
private final Criteria where;
|
||||
|
||||
DefaultGenericUpdateSpec(@Nullable Class<?> typeToUpdate, @Nullable String table, Update assignments,
|
||||
Criteria where) {
|
||||
this.typeToUpdate = typeToUpdate;
|
||||
this.table = table;
|
||||
this.assignments = assignments;
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateMatchingSpec using(Update update) {
|
||||
|
||||
@@ -1181,13 +1212,18 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class DefaultTypedUpdateSpec<T> implements TypedUpdateSpec<T>, UpdateSpec {
|
||||
|
||||
private final @Nullable Class<T> typeToUpdate;
|
||||
private final @Nullable String table;
|
||||
private final T objectToUpdate;
|
||||
|
||||
DefaultTypedUpdateSpec(@Nullable Class<T> typeToUpdate, @Nullable String table, T objectToUpdate) {
|
||||
this.typeToUpdate = typeToUpdate;
|
||||
this.table = table;
|
||||
this.objectToUpdate = objectToUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateSpec using(T objectToUpdate) {
|
||||
|
||||
@@ -1270,13 +1306,18 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Default implementation of {@link DatabaseClient.TypedInsertSpec}.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class DefaultDeleteSpec<T> implements DeleteMatchingSpec, TypedDeleteSpec<T> {
|
||||
|
||||
private final @Nullable Class<T> typeToDelete;
|
||||
private final @Nullable String table;
|
||||
private final Criteria where;
|
||||
|
||||
DefaultDeleteSpec(@Nullable Class<T> typeToDelete, @Nullable String table, Criteria where) {
|
||||
this.typeToDelete = typeToDelete;
|
||||
this.table = table;
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteSpec matching(Criteria criteria) {
|
||||
|
||||
@@ -1483,7 +1524,6 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
/**
|
||||
* Holder for a connection that makes sure the close action is invoked atomically only once.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
static class ConnectionCloseHolder extends AtomicBoolean {
|
||||
|
||||
private static final long serialVersionUID = -8994138383301201380L;
|
||||
@@ -1491,6 +1531,11 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
final Connection connection;
|
||||
final Function<Connection, Publisher<Void>> closeFunction;
|
||||
|
||||
ConnectionCloseHolder(Connection connection, Function<Connection, Publisher<Void>> closeFunction) {
|
||||
this.connection = connection;
|
||||
this.closeFunction = closeFunction;
|
||||
}
|
||||
|
||||
Mono<Void> close() {
|
||||
|
||||
return Mono.defer(() -> {
|
||||
@@ -1504,11 +1549,14 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
static class StatementWrapper implements BindTarget {
|
||||
|
||||
final Statement statement;
|
||||
|
||||
StatementWrapper(Statement statement) {
|
||||
this.statement = statement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(Object identifier, Object value) {
|
||||
this.statement.bind(identifier, value);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.r2dbc.core;
|
||||
|
||||
import io.r2dbc.spi.Connection;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -29,7 +28,6 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class DefaultFetchSpec<T> implements FetchSpec<T> {
|
||||
|
||||
private final ConnectionAccessor connectionAccessor;
|
||||
@@ -37,6 +35,14 @@ class DefaultFetchSpec<T> implements FetchSpec<T> {
|
||||
private final Function<Connection, Flux<T>> resultFunction;
|
||||
private final Function<Connection, Mono<Integer>> updatedRowsFunction;
|
||||
|
||||
DefaultFetchSpec(ConnectionAccessor connectionAccessor, String sql, Function<Connection, Flux<T>> resultFunction,
|
||||
Function<Connection, Mono<Integer>> updatedRowsFunction) {
|
||||
this.connectionAccessor = connectionAccessor;
|
||||
this.sql = sql;
|
||||
this.resultFunction = resultFunction;
|
||||
this.updatedRowsFunction = updatedRowsFunction;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.function.FetchSpec#one()
|
||||
*/
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.core;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -45,7 +43,6 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class DefaultStatementMapper implements StatementMapper {
|
||||
|
||||
private final R2dbcDialect dialect;
|
||||
@@ -53,6 +50,14 @@ class DefaultStatementMapper implements StatementMapper {
|
||||
private final UpdateMapper updateMapper;
|
||||
private final MappingContext<RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext;
|
||||
|
||||
DefaultStatementMapper(R2dbcDialect dialect, RenderContext renderContext, UpdateMapper updateMapper,
|
||||
MappingContext<RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext) {
|
||||
this.dialect = dialect;
|
||||
this.renderContext = renderContext;
|
||||
this.updateMapper = updateMapper;
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.function.StatementMapper#forType(java.lang.Class)
|
||||
@@ -255,13 +260,18 @@ class DefaultStatementMapper implements StatementMapper {
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
static class DefaultPreparedOperation<T> implements PreparedOperation<T> {
|
||||
|
||||
private final T source;
|
||||
private final RenderContext renderContext;
|
||||
private final Bindings bindings;
|
||||
|
||||
public DefaultPreparedOperation(T source, RenderContext renderContext, Bindings bindings) {
|
||||
this.source = source;
|
||||
this.renderContext = renderContext;
|
||||
this.bindings = bindings;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.function.PreparedOperation#getSource()
|
||||
@@ -305,11 +315,14 @@ class DefaultStatementMapper implements StatementMapper {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class DefaultTypedStatementMapper<T> implements TypedStatementMapper<T> {
|
||||
|
||||
final RelationalPersistentEntity<T> entity;
|
||||
|
||||
DefaultTypedStatementMapper(RelationalPersistentEntity<T> entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.function.StatementMapper#forType(java.lang.Class)
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.core;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -344,14 +343,47 @@ abstract class NamedParameterUtils {
|
||||
return substituteNamedParameters(parsedSql, bindMarkersFactory, paramSource);
|
||||
}
|
||||
|
||||
@Value
|
||||
private static class ParameterHolder {
|
||||
private static final class ParameterHolder {
|
||||
|
||||
String parameterName;
|
||||
private final String parameterName;
|
||||
|
||||
int startIndex;
|
||||
private final int startIndex;
|
||||
|
||||
int endIndex;
|
||||
private final int endIndex;
|
||||
|
||||
ParameterHolder(String parameterName, int startIndex, int endIndex) {
|
||||
this.parameterName = parameterName;
|
||||
this.startIndex = startIndex;
|
||||
this.endIndex = endIndex;
|
||||
}
|
||||
|
||||
String getParameterName() {
|
||||
return this.parameterName;
|
||||
}
|
||||
|
||||
int getStartIndex() {
|
||||
return this.startIndex;
|
||||
}
|
||||
|
||||
int getEndIndex() {
|
||||
return this.endIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof ParameterHolder))
|
||||
return false;
|
||||
ParameterHolder that = (ParameterHolder) o;
|
||||
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
|
||||
&& Objects.equals(this.parameterName, that.parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.parameterName, this.startIndex, this.endIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.springframework.data.r2dbc.dialect;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
@@ -65,12 +63,16 @@ public class PostgresDialect extends org.springframework.data.relational.core.di
|
||||
return this.arrayColumns.get();
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class R2dbcArrayColumns implements ArrayColumns {
|
||||
|
||||
private final ArrayColumns delegate;
|
||||
private final SimpleTypeHolder simpleTypeHolder;
|
||||
|
||||
R2dbcArrayColumns(ArrayColumns delegate, SimpleTypeHolder simpleTypeHolder) {
|
||||
this.delegate = delegate;
|
||||
this.simpleTypeHolder = simpleTypeHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return this.delegate.isSupported();
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.query;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -268,11 +266,14 @@ public class Criteria {
|
||||
/**
|
||||
* Default {@link CriteriaStep} implementation.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
static class DefaultCriteriaStep implements CriteriaStep {
|
||||
|
||||
private final String property;
|
||||
|
||||
DefaultCriteriaStep(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.function.query.Criteria.CriteriaStep#is(java.lang.Object)
|
||||
@@ -438,7 +439,7 @@ public class Criteria {
|
||||
}
|
||||
|
||||
protected Criteria createCriteria(Comparator comparator, Object value) {
|
||||
return new Criteria(property, comparator, value);
|
||||
return new Criteria(this.property, comparator, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.repository.query;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
@@ -42,30 +39,41 @@ interface R2dbcQueryExecution {
|
||||
/**
|
||||
* An {@link R2dbcQueryExecution} that wraps the results of the given delegate with the given result processing.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
final class ResultProcessingExecution implements R2dbcQueryExecution {
|
||||
|
||||
private final @NonNull R2dbcQueryExecution delegate;
|
||||
private final @NonNull Converter<Object, Object> converter;
|
||||
private final R2dbcQueryExecution delegate;
|
||||
private final Converter<Object, Object> converter;
|
||||
|
||||
ResultProcessingExecution(R2dbcQueryExecution delegate, Converter<Object, Object> converter) {
|
||||
this.delegate = delegate;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.r2dbc.repository.query.R2dbcQueryExecution#execute(org.springframework.data.r2dbc.function.FetchSpec, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object execute(FetchSpec<?> query, Class<?> type, String tableName) {
|
||||
return converter.convert(delegate.execute(query, type, tableName));
|
||||
return this.converter.convert(this.delegate.execute(query, type, tableName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Converter} to post-process all source objects using the given {@link ResultProcessor}.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
final class ResultProcessingConverter implements Converter<Object, Object> {
|
||||
|
||||
private final @NonNull ResultProcessor processor;
|
||||
private final @NonNull MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext;
|
||||
private final @NonNull EntityInstantiators instantiators;
|
||||
private final ResultProcessor processor;
|
||||
private final MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext;
|
||||
private final EntityInstantiators instantiators;
|
||||
|
||||
ResultProcessingConverter(ResultProcessor processor,
|
||||
MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext,
|
||||
EntityInstantiators instantiators) {
|
||||
this.processor = processor;
|
||||
this.mappingContext = mappingContext;
|
||||
this.instantiators = instantiators;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
@@ -73,16 +81,16 @@ interface R2dbcQueryExecution {
|
||||
@Override
|
||||
public Object convert(Object source) {
|
||||
|
||||
ReturnedType returnedType = processor.getReturnedType();
|
||||
ReturnedType returnedType = this.processor.getReturnedType();
|
||||
|
||||
if (ClassUtils.isPrimitiveOrWrapper(returnedType.getReturnedType())) {
|
||||
return source;
|
||||
}
|
||||
|
||||
Converter<Object, Object> converter = new DtoInstantiatingConverter(returnedType.getReturnedType(),
|
||||
mappingContext, instantiators);
|
||||
this.mappingContext, this.instantiators);
|
||||
|
||||
return processor.processResult(source, converter);
|
||||
return this.processor.processResult(source, converter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.repository.support;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -95,8 +92,8 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType(),
|
||||
information);
|
||||
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, databaseClient, converter,
|
||||
dataAccessStrategy);
|
||||
return getTargetRepositoryViaReflection(information, entityInformation, this.databaseClient, this.converter,
|
||||
this.dataAccessStrategy);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -106,7 +103,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
@Override
|
||||
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider) {
|
||||
return Optional.of(new R2dbcQueryLookupStrategy(databaseClient, evaluationContextProvider, converter));
|
||||
return Optional.of(new R2dbcQueryLookupStrategy(this.databaseClient, evaluationContextProvider, this.converter));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -121,7 +118,7 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
private <T, ID> RelationalEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
||||
@Nullable RepositoryInformation information) {
|
||||
|
||||
RelationalPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
RelationalPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
|
||||
return new MappingRelationalEntityInformation<>((RelationalPersistentEntity<T>) entity);
|
||||
}
|
||||
@@ -131,13 +128,19 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
private static class R2dbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
|
||||
private final DatabaseClient databaseClient;
|
||||
private final QueryMethodEvaluationContextProvider evaluationContextProvider;
|
||||
private final R2dbcConverter converter;
|
||||
|
||||
R2dbcQueryLookupStrategy(DatabaseClient databaseClient,
|
||||
QueryMethodEvaluationContextProvider evaluationContextProvider, R2dbcConverter converter) {
|
||||
this.databaseClient = databaseClient;
|
||||
this.evaluationContextProvider = evaluationContextProvider;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries)
|
||||
@@ -146,16 +149,17 @@ public class R2dbcRepositoryFactory extends ReactiveRepositoryFactorySupport {
|
||||
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
|
||||
NamedQueries namedQueries) {
|
||||
|
||||
R2dbcQueryMethod queryMethod = new R2dbcQueryMethod(method, metadata, factory, converter.getMappingContext());
|
||||
R2dbcQueryMethod queryMethod = new R2dbcQueryMethod(method, metadata, factory,
|
||||
this.converter.getMappingContext());
|
||||
String namedQueryName = queryMethod.getNamedQueryName();
|
||||
|
||||
if (namedQueries.hasQuery(namedQueryName)) {
|
||||
String namedQuery = namedQueries.getQuery(namedQueryName);
|
||||
return new StringBasedR2dbcQuery(namedQuery, queryMethod, databaseClient, converter, EXPRESSION_PARSER,
|
||||
evaluationContextProvider);
|
||||
return new StringBasedR2dbcQuery(namedQuery, queryMethod, this.databaseClient, this.converter,
|
||||
EXPRESSION_PARSER, this.evaluationContextProvider);
|
||||
} else if (queryMethod.hasAnnotatedQuery()) {
|
||||
return new StringBasedR2dbcQuery(queryMethod, databaseClient, converter, EXPRESSION_PARSER,
|
||||
evaluationContextProvider);
|
||||
return new StringBasedR2dbcQuery(queryMethod, this.databaseClient, this.converter, EXPRESSION_PARSER,
|
||||
this.evaluationContextProvider);
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("Query derivation not yet supported!");
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.repository.support;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -24,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverter;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.core.PreparedOperation;
|
||||
@@ -44,13 +43,20 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, ID> {
|
||||
|
||||
private final @NonNull RelationalEntityInformation<T, ID> entity;
|
||||
private final @NonNull DatabaseClient databaseClient;
|
||||
private final @NonNull R2dbcConverter converter;
|
||||
private final @NonNull ReactiveDataAccessStrategy accessStrategy;
|
||||
private final RelationalEntityInformation<T, ID> entity;
|
||||
private final DatabaseClient databaseClient;
|
||||
private final R2dbcConverter converter;
|
||||
private final ReactiveDataAccessStrategy accessStrategy;
|
||||
|
||||
public SimpleR2dbcRepository(RelationalEntityInformation<T, ID> entity, DatabaseClient databaseClient,
|
||||
R2dbcConverter converter, ReactiveDataAccessStrategy accessStrategy) {
|
||||
this.entity = entity;
|
||||
this.databaseClient = databaseClient;
|
||||
this.converter = converter;
|
||||
this.accessStrategy = accessStrategy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#save(S)
|
||||
|
||||
Reference in New Issue
Block a user