From d533e1efbabe6235bdd3f0f8848070839691c9a7 Mon Sep 17 00:00:00 2001 From: Mirro Mutth Date: Mon, 18 Mar 2024 10:29:51 +0900 Subject: [PATCH] Remove PrimitiveCodec --- .../mysql/codec/AbstractPrimitiveCodec.java | 3 +- .../r2dbc/mysql/codec/DefaultCodecs.java | 11 +++--- .../r2dbc/mysql/codec/PrimitiveCodec.java | 35 ------------------- 3 files changed, 6 insertions(+), 43 deletions(-) delete mode 100644 r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/PrimitiveCodec.java diff --git a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/AbstractPrimitiveCodec.java b/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/AbstractPrimitiveCodec.java index 499a5fc98..a3844d28e 100644 --- a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/AbstractPrimitiveCodec.java +++ b/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/AbstractPrimitiveCodec.java @@ -25,7 +25,7 @@ * * @param the boxed type of handling primitive data. */ -abstract class AbstractPrimitiveCodec implements PrimitiveCodec { +abstract class AbstractPrimitiveCodec implements Codec { private final Class primitiveClass; @@ -44,7 +44,6 @@ public final boolean canDecode(MySqlReadableMetadata metadata, Class target) return (target.isAssignableFrom(boxedClass) || target.equals(primitiveClass)) && doCanDecode(metadata); } - @Override public final Class getPrimitiveClass() { return primitiveClass; } diff --git a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java b/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java index 793253858..d76b398e2 100644 --- a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java +++ b/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/DefaultCodecs.java @@ -108,9 +108,8 @@ private DefaultCodecs(List> codecs) { fastPath.putIfAbsent(mainClass, codec); } - if (codec instanceof PrimitiveCodec) { - // Primitive codec must be class-based codec, cannot support ParameterizedType. - PrimitiveCodec c = (PrimitiveCodec) codec; + if (codec instanceof AbstractPrimitiveCodec) { + AbstractPrimitiveCodec c = (AbstractPrimitiveCodec) codec; fastPath.putIfAbsent(c.getPrimitiveClass(), c); } else if (codec instanceof ParameterizedCodec) { @@ -230,7 +229,7 @@ public MySqlParameter encode(Object value, CodecContext context) { } for (Codec codec : codecs) { - if (codec.canEncode(valueToEncode)) { + if (codec != fast && codec.canEncode(valueToEncode)) { return codec.encode(valueToEncode, context); } } @@ -293,7 +292,7 @@ private T decodeNormal(NormalFieldValue value, MySqlReadableMetadata metadat } for (Codec codec : codecs) { - if (codec.canDecode(metadata, type)) { + if (codec != fast && codec.canDecode(metadata, type)) { @SuppressWarnings("unchecked") Codec c = (Codec) codec; return c.decode(value.getBufferSlice(), metadata, type, binary, context); @@ -327,7 +326,7 @@ private T decodeMassive(LargeFieldValue value, MySqlReadableMetadata metadat } for (MassiveCodec codec : massiveCodecs) { - if (codec.canDecode(metadata, type)) { + if (codec != fast && codec.canDecode(metadata, type)) { @SuppressWarnings("unchecked") MassiveCodec c = (MassiveCodec) codec; return c.decodeMassive(value.getBufferSlices(), metadata, type, binary, context); diff --git a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/PrimitiveCodec.java b/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/PrimitiveCodec.java deleted file mode 100644 index a880825a3..000000000 --- a/r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/codec/PrimitiveCodec.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2023 asyncer.io projects - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.asyncer.r2dbc.mysql.codec; - -/** - * Base class considers primitive class for {@link Codec} implementations. It should be an internal - * abstraction. - *

- * Primitive types should never return {@code null} when decoding. - * - * @param the boxed type that is handled by this codec. - */ -interface PrimitiveCodec extends Codec { - - /** - * Gets the primitive {@link Class}, such as {@link Integer#TYPE}, etc. - * - * @return the primitive {@link Class}. - */ - Class getPrimitiveClass(); -}