Package org.mariadb.jdbc.plugin.codec
Class BigDecimalCodec
java.lang.Object
org.mariadb.jdbc.plugin.codec.BigDecimalCodec
- All Implemented Interfaces:
Codec<BigDecimal>
Big decimal codec
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BigDecimalCodecdefault instancestatic final intMaximum length of a numeric string the driver will accept before parsing it into aBigDecimal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIf codec can decode this a server datatype to a java class typebooleanCan Codec encode the java object typeCodec native typedecodeBinary(org.mariadb.jdbc.client.ReadableByteBuf buf, MutableInt length, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context) Decode from a mysql packet binary encoded a value to codec java typedecodeText(org.mariadb.jdbc.client.ReadableByteBuf buf, MutableInt length, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context) Decode from a mysql packet text encoded a value to codec java typevoidencodeBinary(Writer encoder, org.mariadb.jdbc.client.Context context, BigDecimal value, Calendar cal, Long maxLength) Binary encode value to writervoidencodeText(Writer encoder, org.mariadb.jdbc.client.Context context, BigDecimal value, Calendar cal, Long length) Text encode value to writerintgetApproximateTextProtocolLength(BigDecimal value, Long length) Get approximate text length, or -1 if unknownintReturn server encoding data typestatic BigDecimalparseBigDecimal(String str) Parse a numeric string into aBigDecimal, rejecting inputs longer thanMAX_BIG_DECIMAL_STRING_LENGTHcharacters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mariadb.jdbc.plugin.Codec
canEncodeLongData, encodeData, encodeLongData
-
Field Details
-
INSTANCE
default instance -
MAX_BIG_DECIMAL_STRING_LENGTH
public static final int MAX_BIG_DECIMAL_STRING_LENGTHMaximum length of a numeric string the driver will accept before parsing it into aBigDecimal. Comfortably above any legitimate numeric encoding (MariaDB DECIMAL maxes out at 65 digits, ASCII-formatted doubles fit in ~25 chars), while small enough that the O(n²) cost ofnew BigDecimal(String)stays sub-millisecond even for an at-cap input. Inputs longer than this are rejected withSQLDataExceptionso attacker-controlled text columns can't be turned into a CPU-exhaustion vector.- See Also:
-
-
Constructor Details
-
BigDecimalCodec
public BigDecimalCodec()
-
-
Method Details
-
parseBigDecimal
Parse a numeric string into aBigDecimal, rejecting inputs longer thanMAX_BIG_DECIMAL_STRING_LENGTHcharacters. Use this helper everywhere the driver would otherwise callnew BigDecimal(<userControlledString>).- Parameters:
str- numeric text- Returns:
- parsed BigDecimal
- Throws:
SQLDataException- ifstris longer than the capNumberFormatException- ifstrisn't a valid number (caller may catch and rewrap with column-specific context)
-
className
Description copied from interface:CodecCodec native type- Specified by:
classNamein interfaceCodec<BigDecimal>- Returns:
- code native return type
-
canDecode
Description copied from interface:CodecIf codec can decode this a server datatype to a java class type- Specified by:
canDecodein interfaceCodec<BigDecimal>- Parameters:
column- server datatypetype- java return class- Returns:
- true if codec can decode it
-
canEncode
Description copied from interface:CodecCan Codec encode the java object type- Specified by:
canEncodein interfaceCodec<BigDecimal>- Parameters:
value- java object type- Returns:
- true if codec can encode java type
-
decodeText
public BigDecimal decodeText(org.mariadb.jdbc.client.ReadableByteBuf buf, MutableInt length, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context) throws SQLDataException Description copied from interface:CodecDecode from a mysql packet text encoded a value to codec java type- Specified by:
decodeTextin interfaceCodec<BigDecimal>- Parameters:
buf- mysql packet bufferlength- encoded value lengthcolumn- server column metadatacal- calendarcontext- connection context- Returns:
- decoded value
- Throws:
SQLDataException- if unexpected error occurs during decoding
-
decodeBinary
public BigDecimal decodeBinary(org.mariadb.jdbc.client.ReadableByteBuf buf, MutableInt length, org.mariadb.jdbc.client.ColumnDecoder column, Calendar cal, org.mariadb.jdbc.client.Context context) throws SQLDataException Description copied from interface:CodecDecode from a mysql packet binary encoded a value to codec java type- Specified by:
decodeBinaryin interfaceCodec<BigDecimal>- Parameters:
buf- mysql packet bufferlength- encoded value lengthcolumn- server column metadatacal- calendarcontext- connection context- Returns:
- decoded value
- Throws:
SQLDataException- if unexpected error occurs during decoding
-
encodeText
public void encodeText(Writer encoder, org.mariadb.jdbc.client.Context context, BigDecimal value, Calendar cal, Long length) throws IOException Description copied from interface:CodecText encode value to writer- Specified by:
encodeTextin interfaceCodec<BigDecimal>- Parameters:
encoder- writercontext- connection contextvalue- value to encodecal- calendarlength- maximum value length- Throws:
IOException- if any socket error occurs
-
getApproximateTextProtocolLength
Description copied from interface:CodecGet approximate text length, or -1 if unknown- Specified by:
getApproximateTextProtocolLengthin interfaceCodec<BigDecimal>- Parameters:
value- parameter objectlength- max length- Returns:
- max length if known, -1 if unknown
-
encodeBinary
public void encodeBinary(Writer encoder, org.mariadb.jdbc.client.Context context, BigDecimal value, Calendar cal, Long maxLength) throws IOException Description copied from interface:CodecBinary encode value to writer- Specified by:
encodeBinaryin interfaceCodec<BigDecimal>- Parameters:
encoder- writercontext- connection contextvalue- value to encodecal- calendarmaxLength- maximum value length- Throws:
IOException- if any socket error occurs
-
getBinaryEncodeType
public int getBinaryEncodeType()Description copied from interface:CodecReturn server encoding data type- Specified by:
getBinaryEncodeTypein interfaceCodec<BigDecimal>- Returns:
- server encoding data type
-