Skip to content

Commit 1e75041

Browse files
committed
Consistent references to scalar values vs Parameter objects
See gh-27282
1 parent 08bc7ed commit 1e75041

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Diff for: spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ interface Builder {
163163
interface GenericExecuteSpec {
164164

165165
/**
166-
* Bind a non-{@code null} value to a parameter identified by its
167-
* {@code index}. {@code value} can be either a scalar value or {@link io.r2dbc.spi.Parameter}.
166+
* Bind a non-{@code null} value to a parameter identified by its {@code index}.
168167
* @param index zero based index to bind the parameter to
169-
* @param value either a scalar value or {@link io.r2dbc.spi.Parameter}
168+
* @param value either a scalar value or a {@link io.r2dbc.spi.Parameter}
170169
*/
171170
GenericExecuteSpec bind(int index, Object value);
172171

@@ -180,7 +179,7 @@ interface GenericExecuteSpec {
180179
/**
181180
* Bind a non-{@code null} value to a parameter identified by its {@code name}.
182181
* @param name the name of the parameter
183-
* @param value the value to bind
182+
* @param value either a scalar value or a {@link io.r2dbc.spi.Parameter}
184183
*/
185184
GenericExecuteSpec bind(String name, Object value);
186185

Diff for: spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

+15-20
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,27 @@ class DefaultGenericExecuteSpec implements GenericExecuteSpec {
245245
}
246246

247247
@SuppressWarnings("deprecation")
248+
private Parameter resolveParameter(Object value) {
249+
if (value instanceof Parameter param) {
250+
return param;
251+
}
252+
else if (value instanceof org.springframework.r2dbc.core.Parameter param) {
253+
Object paramValue = param.getValue();
254+
return (paramValue != null ? Parameters.in(paramValue) : Parameters.in(param.getType()));
255+
}
256+
else {
257+
return Parameters.in(value);
258+
}
259+
}
260+
248261
@Override
249262
public DefaultGenericExecuteSpec bind(int index, Object value) {
250263
assertNotPreparedOperation();
251264
Assert.notNull(value, () -> String.format(
252265
"Value at index %d must not be null. Use bindNull(…) instead.", index));
253266

254267
Map<Integer, Parameter> byIndex = new LinkedHashMap<>(this.byIndex);
255-
if (value instanceof Parameter param) {
256-
byIndex.put(index, param);
257-
}
258-
else if (value instanceof org.springframework.r2dbc.core.Parameter param) {
259-
Object pv = param.getValue();
260-
byIndex.put(index, (pv != null ? Parameters.in(pv) : Parameters.in(param.getType())));
261-
}
262-
else {
263-
byIndex.put(index, Parameters.in(value));
264-
}
268+
byIndex.put(index, resolveParameter(value));
265269

266270
return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction);
267271
}
@@ -276,7 +280,6 @@ public DefaultGenericExecuteSpec bindNull(int index, Class<?> type) {
276280
return new DefaultGenericExecuteSpec(byIndex, this.byName, this.sqlSupplier, this.filterFunction);
277281
}
278282

279-
@SuppressWarnings("deprecation")
280283
@Override
281284
public DefaultGenericExecuteSpec bind(String name, Object value) {
282285
assertNotPreparedOperation();
@@ -286,15 +289,7 @@ public DefaultGenericExecuteSpec bind(String name, Object value) {
286289
"Value for parameter %s must not be null. Use bindNull(…) instead.", name));
287290

288291
Map<String, Parameter> byName = new LinkedHashMap<>(this.byName);
289-
if (value instanceof Parameter p) {
290-
byName.put(name, p);
291-
}
292-
else if (value instanceof org.springframework.r2dbc.core.Parameter p) {
293-
byName.put(name, p.hasValue() ? Parameters.in(p.getValue()) : Parameters.in(p.getType()));
294-
}
295-
else {
296-
byName.put(name, Parameters.in(value));
297-
}
292+
byName.put(name, resolveParameter(value));
298293

299294
return new DefaultGenericExecuteSpec(this.byIndex, byName, this.sqlSupplier, this.filterFunction);
300295
}

0 commit comments

Comments
 (0)