|
45 | 45 | */
|
46 | 46 | final class DefaultCodecs implements Codecs {
|
47 | 47 |
|
48 |
| - private static final Integer INTEGER_ONE = Integer.valueOf(1); |
49 |
| - |
50 | 48 | private static final List<Codec<?>> DEFAULT_CODECS = InternalArrays.asImmutableList(
|
51 | 49 | ByteCodec.INSTANCE,
|
52 | 50 | ShortCodec.INSTANCE,
|
@@ -369,18 +367,22 @@ private static Class<?> chooseClass(final MySqlReadableMetadata metadata, Class<
|
369 | 367 | return type.isAssignableFrom(javaType) ? javaType : type;
|
370 | 368 | }
|
371 | 369 |
|
372 |
| - private static Class<?> getDefaultJavaType(final MySqlReadableMetadata metadata, final CodecContext codecContext) { |
373 |
| - final MySqlType type = metadata.getType(); |
374 |
| - final Integer precision = metadata.getPrecision(); |
375 | 370 |
|
376 |
| - if (INTEGER_ONE.equals(precision) && (type == MySqlType.TINYINT || type == MySqlType.TINYINT_UNSIGNED) |
377 |
| - && codecContext.isTinyInt1isBit()) { |
378 |
| - return Boolean.class; |
| 371 | + private static boolean shouldBeTreatedAsBoolean(final @Nullable Integer precision, final MySqlType type, |
| 372 | + final CodecContext context) { |
| 373 | + if (precision == null || precision != 1) { |
| 374 | + return false; |
379 | 375 | }
|
380 |
| - |
381 | 376 | // ref: https://github.com/asyncer-io/r2dbc-mysql/issues/277
|
382 | 377 | // BIT(1) should be treated as Boolean by default.
|
383 |
| - if (INTEGER_ONE.equals(precision) && type == MySqlType.BIT) { |
| 378 | + return type == MySqlType.BIT || type == MySqlType.TINYINT && context.isTinyInt1isBit(); |
| 379 | + } |
| 380 | + |
| 381 | + private static Class<?> getDefaultJavaType(final MySqlReadableMetadata metadata, final CodecContext codecContext) { |
| 382 | + final MySqlType type = metadata.getType(); |
| 383 | + final Integer precision = metadata.getPrecision(); |
| 384 | + |
| 385 | + if (shouldBeTreatedAsBoolean(precision, type, codecContext)) { |
384 | 386 | return Boolean.class;
|
385 | 387 | }
|
386 | 388 |
|
|
0 commit comments