Consistent references to scalar values vs Parameter objects
See gh-27282
This commit is contained in:
@@ -163,10 +163,9 @@ public interface DatabaseClient extends ConnectionAccessor {
|
||||
interface GenericExecuteSpec {
|
||||
|
||||
/**
|
||||
* Bind a non-{@code null} value to a parameter identified by its
|
||||
* {@code index}. {@code value} can be either a scalar value or {@link io.r2dbc.spi.Parameter}.
|
||||
* Bind a non-{@code null} value to a parameter identified by its {@code index}.
|
||||
* @param index zero based index to bind the parameter to
|
||||
* @param value either a scalar value or {@link io.r2dbc.spi.Parameter}
|
||||
* @param value either a scalar value or a {@link io.r2dbc.spi.Parameter}
|
||||
*/
|
||||
GenericExecuteSpec bind(int index, Object value);
|
||||
|
||||
@@ -180,7 +179,7 @@ public interface DatabaseClient extends ConnectionAccessor {
|
||||
/**
|
||||
* Bind a non-{@code null} value to a parameter identified by its {@code name}.
|
||||
* @param name the name of the parameter
|
||||
* @param value the value to bind
|
||||
* @param value either a scalar value or a {@link io.r2dbc.spi.Parameter}
|
||||
*/
|
||||
GenericExecuteSpec bind(String name, Object value);
|
||||
|
||||
|
||||
@@ -245,6 +245,19 @@ final class DefaultDatabaseClient implements DatabaseClient {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Parameter resolveParameter(Object value) {
|
||||
if (value instanceof Parameter param) {
|
||||
return param;
|
||||
}
|
||||
else if (value instanceof org.springframework.r2dbc.core.Parameter param) {
|
||||
Object paramValue = param.getValue();
|
||||
return (paramValue != null ? Parameters.in(paramValue) : Parameters.in(param.getType()));
|
||||
}
|
||||
else {
|
||||
return Parameters.in(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultGenericExecuteSpec bind(int index, Object value) {
|
||||
assertNotPreparedOperation();
|
||||
@@ -252,16 +265,7 @@ final class DefaultDatabaseClient implements DatabaseClient {
|
||||
"Value at index %d must not be null. Use bindNull(…) instead.", index));
|
||||
|
||||
Map<Integer, Parameter> byIndex = new LinkedHashMap<>(this.byIndex);
|
||||
if (value instanceof Parameter param) {
|
||||
byIndex.put(index, param);
|
||||
}
|
||||
else if (value instanceof org.springframework.r2dbc.core.Parameter param) {
|
||||
Object pv = param.getValue();
|
||||
byIndex.put(index, (pv != null ? Parameters.in(pv) : Parameters.in(param.getType())));
|
||||
}
|
||||
else {
|
||||
byIndex.put(index, Parameters.in(value));
|
||||
}
|
||||
byIndex.put(index, resolveParameter(value));
|
||||
|
||||
return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction);
|
||||
}
|
||||
@@ -276,7 +280,6 @@ final class DefaultDatabaseClient implements DatabaseClient {
|
||||
return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public DefaultGenericExecuteSpec bind(String name, Object value) {
|
||||
assertNotPreparedOperation();
|
||||
@@ -286,15 +289,7 @@ final class DefaultDatabaseClient implements DatabaseClient {
|
||||
"Value for parameter %s must not be null. Use bindNull(…) instead.", name));
|
||||
|
||||
Map<String, Parameter> byName = new LinkedHashMap<>(this.byName);
|
||||
if (value instanceof Parameter p) {
|
||||
byName.put(name, p);
|
||||
}
|
||||
else if (value instanceof org.springframework.r2dbc.core.Parameter p) {
|
||||
byName.put(name, p.hasValue() ? Parameters.in(p.getValue()) : Parameters.in(p.getType()));
|
||||
}
|
||||
else {
|
||||
byName.put(name, Parameters.in(value));
|
||||
}
|
||||
byName.put(name, resolveParameter(value));
|
||||
|
||||
return new DefaultGenericExecuteSpec(this.byIndex, byName, this.sqlSupplier, this.filterFunction);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user