Skip to content

Commit 42045c5

Browse files
committed
Support io.r2dbc.spi.Parameter
Motivation: Should support it Modifications: Modify DefaultCodecs to support Parameter Result: Now support Parameter
1 parent 0472eaa commit 42045c5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.asyncer.r2dbc.mysql.message.NormalFieldValue;
2424
import io.asyncer.r2dbc.mysql.util.InternalArrays;
2525
import io.netty.buffer.ByteBufAllocator;
26+
import io.r2dbc.spi.Parameter;
2627
import reactor.util.annotation.Nullable;
2728

2829
import java.lang.reflect.ParameterizedType;
@@ -169,13 +170,26 @@ public MySqlParameter encode(Object value, CodecContext context) {
169170
requireNonNull(value, "value must not be null");
170171
requireNonNull(context, "context must not be null");
171172

173+
final Object valueToEncode = getValueToEncode(value);
174+
if (null == valueToEncode) {
175+
return encodeNull();
176+
}
177+
172178
for (Codec<?> codec : codecs) {
173-
if (codec.canEncode(value)) {
174-
return codec.encode(value, context);
179+
if (codec.canEncode(valueToEncode)) {
180+
return codec.encode(valueToEncode, context);
175181
}
176182
}
177183

178-
throw new IllegalArgumentException("Cannot encode " + value.getClass());
184+
throw new IllegalArgumentException("Cannot encode " + valueToEncode.getClass());
185+
}
186+
187+
@Nullable
188+
private static Object getValueToEncode(Object value) {
189+
if (value instanceof Parameter) {
190+
return ((Parameter) value).getValue();
191+
}
192+
return value;
179193
}
180194

181195
@Override

0 commit comments

Comments
 (0)