#54 - Build against R2DBC 1.0 snapshots.

This commit is contained in:
Mark Paluch
2019-02-01 09:43:51 +01:00
parent 3a5278ce87
commit 432b885853
21 changed files with 66 additions and 106 deletions

View File

@@ -28,7 +28,7 @@ public interface BindMarker {
* {@literal null} values.
* @see Statement#bind
*/
void bind(Statement<?> statement, Object value);
void bind(Statement statement, Object value);
/**
* Bind a {@literal null} value to the {@link Statement} using the underlying binding strategy.
@@ -37,5 +37,5 @@ public interface BindMarker {
* @param valueType value type, must not be {@literal null}.
* @see Statement#bindNull
*/
void bindNull(Statement<?> statement, Class<?> valueType);
void bindNull(Statement statement, Class<?> valueType);
}

View File

@@ -22,17 +22,6 @@ public interface Dialect {
*/
BindMarkersFactory getBindMarkersFactory();
/**
* Returns the clause to include for returning generated keys. The returned query is directly appended to
* {@code INSERT} statements.
*
* @return the clause to include for returning generated keys.
* @deprecated to be removed after upgrading to R2DBC 1.0M7 in favor of using the driver's direct support for
* retrieving generated keys.
*/
@Deprecated
String generatedKeysClause();
/**
* Return a collection of types that are natively supported by this database/driver. Defaults to
* {@link Collections#emptySet()}.

View File

@@ -11,13 +11,4 @@ public class H2Dialect extends PostgresDialect {
* Singleton instance.
*/
public static final H2Dialect INSTANCE = new H2Dialect();
/*
* (non-Javadoc)
* @see org.springframework.data.r2dbc.dialect.Dialect#returnGeneratedKeys()
*/
@Override
public String generatedKeysClause() {
return "";
}
}

View File

@@ -74,7 +74,7 @@ class IndexedBindMarkers implements BindMarkers {
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(io.r2dbc.spi.Statement, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, Object value) {
public void bind(Statement statement, Object value) {
statement.bind(this.index, value);
}
@@ -83,7 +83,7 @@ class IndexedBindMarkers implements BindMarkers {
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(io.r2dbc.spi.Statement, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, Class<?> valueType) {
public void bindNull(Statement statement, Class<?> valueType) {
statement.bindNull(this.index, valueType);
}
}

View File

@@ -101,7 +101,7 @@ class NamedBindMarkers implements BindMarkers {
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindValue(io.r2dbc.spi.Statement, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, Object value) {
public void bind(Statement statement, Object value) {
statement.bind(this.identifier, value);
}
@@ -110,7 +110,7 @@ class NamedBindMarkers implements BindMarkers {
* @see org.springframework.data.r2dbc.dialect.BindMarker#bindNull(io.r2dbc.spi.Statement, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, Class<?> valueType) {
public void bindNull(Statement statement, Class<?> valueType) {
statement.bindNull(this.identifier, valueType);
}
}

View File

@@ -73,15 +73,6 @@ public class PostgresDialect implements Dialect {
return INDEXED;
}
/*
* (non-Javadoc)
* @see org.springframework.data.r2dbc.dialect.Dialect#returnGeneratedKeys()
*/
@Override
public String generatedKeysClause() {
return "RETURNING *";
}
/*
* (non-Javadoc)
* @see org.springframework.data.r2dbc.dialect.Dialect#getSimpleTypesKeys()

View File

@@ -62,15 +62,6 @@ public class SqlServerDialect implements Dialect {
return NAMED;
}
/*
* (non-Javadoc)
* @see org.springframework.data.r2dbc.dialect.Dialect#returnGeneratedKeys()
*/
@Override
public String generatedKeysClause() {
return "select SCOPE_IDENTITY() AS GENERATED_KEYS";
}
/*
* (non-Javadoc)
* @see org.springframework.data.r2dbc.dialect.Dialect#getSimpleTypesKeys()

View File

@@ -19,7 +19,7 @@ public interface BindIdOperation extends BindableOperation {
* @param value the actual value. Must not be {@literal null}.
* @see Statement#bind
*/
void bindId(Statement<?> statement, Object value);
void bindId(Statement statement, Object value);
/**
* Bind the given {@code values} to the {@link Statement} using the underlying binding strategy.
@@ -28,5 +28,5 @@ public interface BindIdOperation extends BindableOperation {
* @param values the actual values.
* @see Statement#bind
*/
void bindIds(Statement<?> statement, Iterable<? extends Object> values);
void bindIds(Statement statement, Iterable<? extends Object> values);
}

View File

@@ -24,7 +24,7 @@ public interface BindableOperation extends QueryOperation {
* {@literal null} values.
* @see Statement#bind
*/
void bind(Statement<?> statement, String identifier, Object value);
void bind(Statement statement, String identifier, Object value);
/**
* Bind a {@literal null} value to the {@link Statement} using the underlying binding strategy.
@@ -34,7 +34,7 @@ public interface BindableOperation extends QueryOperation {
* @param valueType value type, must not be {@literal null}.
* @see Statement#bindNull
*/
void bindNull(Statement<?> statement, String identifier, Class<?> valueType);
void bindNull(Statement statement, String identifier, Class<?> valueType);
/**
* Bind a {@link SettableValue} to the {@link Statement} using the underlying binding strategy. Binds either the
@@ -45,7 +45,7 @@ public interface BindableOperation extends QueryOperation {
* @see Statement#bind
* @see Statement#bindNull
*/
default void bind(Statement<?> statement, SettableValue value) {
default void bind(Statement statement, SettableValue value) {
if (value.getValue() == null) {
bindNull(statement, value.getIdentifier().toString(), value.getType());

View File

@@ -251,14 +251,14 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
return new DefaultGenericExecuteSpec(sqlSupplier);
}
private static void doBind(Statement<?> statement, Map<String, SettableValue> byName,
private static void doBind(Statement statement, Map<String, SettableValue> byName,
Map<Integer, SettableValue> byIndex) {
bindByIndex(statement, byIndex);
bindByName(statement, byName);
}
private static void bindByName(Statement<?> statement, Map<String, SettableValue> byName) {
private static void bindByName(Statement statement, Map<String, SettableValue> byName) {
byName.forEach((name, o) -> {
@@ -270,7 +270,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
});
}
private static void bindByIndex(Statement<?> statement, Map<Integer, SettableValue> byIndex) {
private static void bindByIndex(Statement statement, Map<Integer, SettableValue> byIndex) {
byIndex.forEach((i, o) -> {
@@ -329,7 +329,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
<T> FetchSpec<T> exchange(String sql, BiFunction<Row, RowMetadata, T> mappingFunction) {
Function<Connection, Statement<?>> executeFunction = it -> {
Function<Connection, Statement> executeFunction = it -> {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
@@ -338,7 +338,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
BindableOperation operation = namedParameters.expand(sql, dataAccessStrategy.getBindMarkersFactory(),
new MapBindParameterSource(byName));
Statement<?> statement = it.createStatement(operation.toQuery());
Statement statement = it.createStatement(operation.toQuery());
byName.forEach((name, o) -> {
@@ -632,7 +632,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
<R> FetchSpec<R> execute(String sql, BiFunction<Row, RowMetadata, R> mappingFunction) {
Function<Connection, Statement<?>> selectFunction = it -> {
Function<Connection, Statement> selectFunction = it -> {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
@@ -886,13 +886,13 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
BindableOperation bindableInsert = dataAccessStrategy.insertAndReturnGeneratedKeys(table, byName.keySet());
String sql = bindableInsert.toQuery();
Function<Connection, Statement<?>> insertFunction = it -> {
Function<Connection, Statement> insertFunction = it -> {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
}
Statement<?> statement = it.createStatement(sql);
Statement statement = it.createStatement(sql).returnGeneratedValues();
byName.forEach((k, v) -> bindableInsert.bind(statement, v));
@@ -1015,7 +1015,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
logger.debug("Executing SQL statement [" + sql + "]");
}
Statement<?> statement = it.createStatement(sql);
Statement statement = it.createStatement(sql).returnGeneratedValues();
for (SettableValue settable : insertValues) {
bindableInsert.bind(statement, settable);

View File

@@ -304,8 +304,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
*/
@Override
public BindableOperation insertAndReturnGeneratedKeys(String table, Set<String> columns) {
return new DefaultBindableInsert(dialect.getBindMarkersFactory().create(), table, columns,
dialect.generatedKeysClause());
return new DefaultBindableInsert(dialect.getBindMarkersFactory().create(), table, columns);
}
/*
@@ -442,8 +441,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
private final Map<String, BindMarker> markers = new LinkedHashMap<>();
private final String query;
DefaultBindableInsert(BindMarkers bindMarkers, String table, Collection<String> columns,
String returningStatement) {
DefaultBindableInsert(BindMarkers bindMarkers, String table, Collection<String> columns) {
StringBuilder builder = new StringBuilder();
List<String> placeholders = new ArrayList<>(columns.size());
@@ -459,10 +457,6 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
builder.append("INSERT INTO ").append(table).append(" (").append(columnsString).append(")").append(" VALUES(")
.append(placeholdersString).append(")");
if (StringUtils.hasText(returningStatement)) {
builder.append(' ').append(returningStatement);
}
this.query = builder.toString();
}
@@ -471,7 +465,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bind(io.r2dbc.spi.Statement, java.lang.String, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
markers.get(identifier).bind(statement, value);
}
@@ -480,7 +474,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bindNull(io.r2dbc.spi.Statement, java.lang.String, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
markers.get(identifier).bindNull(statement, valueType);
}
@@ -529,7 +523,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bind(io.r2dbc.spi.Statement, java.lang.String, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
markers.get(identifier).bind(statement, value);
}
@@ -538,7 +532,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bindNull(io.r2dbc.spi.Statement, java.lang.String, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
markers.get(identifier).bindNull(statement, valueType);
}
@@ -547,7 +541,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindId(io.r2dbc.spi.Statement, java.lang.Object)
*/
@Override
public void bindId(Statement<?> statement, Object value) {
public void bindId(Statement statement, Object value) {
idMarker.bind(statement, value);
}
@@ -556,7 +550,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindIds(io.r2dbc.spi.Statement, java.lang.Iterable)
*/
@Override
public void bindIds(Statement<?> statement, Iterable<? extends Object> values) {
public void bindIds(Statement statement, Iterable<? extends Object> values) {
throw new UnsupportedOperationException();
}
@@ -590,7 +584,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bind(io.r2dbc.spi.Statement, java.lang.String, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
throw new UnsupportedOperationException();
}
@@ -599,7 +593,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bindNull(io.r2dbc.spi.Statement, java.lang.String, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
throw new UnsupportedOperationException();
}
@@ -608,7 +602,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindId(io.r2dbc.spi.Statement, java.lang.Object)
*/
@Override
public void bindId(Statement<?> statement, Object value) {
public void bindId(Statement statement, Object value) {
idMarker.bind(statement, value);
}
@@ -617,7 +611,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindIds(io.r2dbc.spi.Statement, java.lang.Iterable)
*/
@Override
public void bindIds(Statement<?> statement, Iterable<? extends Object> values) {
public void bindIds(Statement statement, Iterable<? extends Object> values) {
throw new UnsupportedOperationException();
}
@@ -654,7 +648,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bind(io.r2dbc.spi.Statement, java.lang.String, java.lang.Object)
*/
@Override
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
throw new UnsupportedOperationException();
}
@@ -663,7 +657,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindableOperation#bindNull(io.r2dbc.spi.Statement, java.lang.String, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
throw new UnsupportedOperationException();
}
@@ -672,7 +666,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindId(io.r2dbc.spi.Statement, java.lang.Object)
*/
@Override
public void bindId(Statement<?> statement, Object value) {
public void bindId(Statement statement, Object value) {
BindMarker bindMarker = bindMarkers.next();
markers.add(bindMarker.getPlaceholder());
@@ -684,7 +678,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
* @see org.springframework.data.r2dbc.function.BindIdOperation#bindIds(io.r2dbc.spi.Statement, java.lang.Iterable)
*/
@Override
public void bindIds(Statement<?> statement, Iterable<? extends Object> values) {
public void bindIds(Statement statement, Iterable<? extends Object> values) {
for (Object value : values) {
bindId(statement, value);

View File

@@ -147,12 +147,12 @@ public class NamedParameterExpander {
return new BindableOperation() {
@Override
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
statement.bind(identifier, value);
}
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
statement.bindNull(identifier, valueType);
}

View File

@@ -395,10 +395,16 @@ abstract class NamedParameterUtils {
*/
@Override
@SuppressWarnings("unchecked")
public void bind(Statement<?> statement, String identifier, Object value) {
public void bind(Statement statement, String identifier, Object value) {
List<BindMarker> bindMarkers = getBindMarkers(identifier);
if (bindMarkers == null) {
statement.bind(identifier, value);
return;
}
if (bindMarkers.size() == 1) {
bindMarkers.get(0).bind(statement, value);
} else {
@@ -427,7 +433,7 @@ abstract class NamedParameterUtils {
}
}
private void bind(Statement<?> statement, Iterator<BindMarker> markers, Object valueToBind) {
private void bind(Statement statement, Iterator<BindMarker> markers, Object valueToBind) {
Assert.isTrue(markers.hasNext(),
() -> String.format(
@@ -442,7 +448,7 @@ abstract class NamedParameterUtils {
* @see org.springframework.data.r2dbc.function.BindableOperation#bindNull(io.r2dbc.spi.Statement, java.lang.String, java.lang.Class)
*/
@Override
public void bindNull(Statement<?> statement, String identifier, Class<?> valueType) {
public void bindNull(Statement statement, String identifier, Class<?> valueType) {
List<BindMarker> bindMarkers = getBindMarkers(identifier);
@@ -455,12 +461,7 @@ abstract class NamedParameterUtils {
}
private List<BindMarker> getBindMarkers(String identifier) {
List<BindMarker> bindMarkers = markers.get(identifier);
Assert.notNull(bindMarkers, () -> String.format("Parameter name [%s] is unknown. Known parameters names are: %s",
identifier, markers.keySet()));
return bindMarkers;
return markers.get(identifier);
}
/*

View File

@@ -13,7 +13,7 @@ import org.springframework.data.r2dbc.function.DatabaseClient.BindSpec;
* @param <S> type of the bind specification.
* @author Mark Paluch
*/
class BindSpecAdapter<S extends BindSpec<S>> implements Statement<BindSpecAdapter<S>> {
class BindSpecAdapter<S extends BindSpec<S>> implements Statement {
private S bindSpec;

View File

@@ -323,7 +323,7 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
.getColumnName();
}
private BiConsumer<String, SettableValue> bind(BindableOperation operation, Statement<?> statement) {
private BiConsumer<String, SettableValue> bind(BindableOperation operation, Statement statement) {
return (k, v) -> operation.bind(statement, v);
}