Package org.mariadb.jdbc.plugin.codec
Class LocalDateTimeCodec
- java.lang.Object
-
- org.mariadb.jdbc.plugin.codec.LocalDateTimeCodec
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.EnumSet<DataType>COMPATIBLE_TYPESstatic LocalDateTimeCodecINSTANCEdefault instancestatic java.time.format.DateTimeFormatterMARIADB_LOCAL_DATE_TIMEformatterstatic java.time.format.DateTimeFormatterTIMESTAMP_FORMATtimestamp with fractional part formatterstatic java.time.format.DateTimeFormatterTIMESTAMP_FORMAT_NO_FRACTIONALtimestamp without fractional part formatter
-
Constructor Summary
Constructors Constructor Description LocalDateTimeCodec()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidadjustNanoPrecision(int[] parts, int nanoLength)booleancanDecode(ColumnDecoder column, java.lang.Class<?> type)If codec can decode this a server datatype to a java class typebooleancanEncode(java.lang.Object value)Can Codec encode the java object typejava.lang.StringclassName()Codec native typejava.time.LocalDateTimedecodeBinary(ReadableByteBuf buf, MutableInt length, ColumnDecoder column, java.util.Calendar cal, Context context)Decode from a mysql packet binary encoded a value to codec java typejava.time.LocalDateTimedecodeText(ReadableByteBuf buf, MutableInt length, ColumnDecoder column, java.util.Calendar cal, Context context)Decode from a mysql packet text encoded a value to codec java typevoidencodeBinary(Writer encoder, Context context, java.time.LocalDateTime value, java.util.Calendar cal, java.lang.Long maxLength)Binary encode value to writervoidencodeText(Writer encoder, Context context, java.time.LocalDateTime value, java.util.Calendar cal, java.lang.Long maxLen)Text encode value to writerprivate static java.time.LocalDateTimefromConnectionTimeZone(java.time.LocalDateTime ldt, java.util.Calendar cal, Context context)Apply timezone handling when DECODING a DATETIME/TIMESTAMP wall-clock value as a LocalDateTime.intgetApproximateTextProtocolLength(java.time.LocalDateTime value, java.lang.Long length)Get approximate text length, or -1 if unknownintgetBinaryEncodeType()Return server encoding data typeprivate static booleanisDelimiter(byte b)private static booleanisDigit(byte b)static booleanisZeroTimestamp(int[] parts)(package private) static java.time.LocalDateTimelocalDateTimeOf(int year, int month, int dayOfMonth, int hour, int minutes, int seconds, int nanos)LocalDateTime from server values, or SQLDataException when they cannot be represented (zero day or month, permitted by the server when sql_mode doesn't contain NO_ZERO_IN_DATE).static int[]parseTextTimestamp(ReadableByteBuf buf, MutableInt length)private static java.time.LocalDateTimetoConnectionTimeZone(java.time.LocalDateTime ldt, java.util.Calendar cal, Context context)Inverse offromConnectionTimeZone(java.time.LocalDateTime, java.util.Calendar, org.mariadb.jdbc.client.Context), applied when ENCODING a LocalDateTime.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mariadb.jdbc.plugin.Codec
canEncodeLongData, encodeData, encodeLongData
-
-
-
-
Field Detail
-
INSTANCE
public static final LocalDateTimeCodec INSTANCE
default instance
-
TIMESTAMP_FORMAT
public static final java.time.format.DateTimeFormatter TIMESTAMP_FORMAT
timestamp with fractional part formatter
-
TIMESTAMP_FORMAT_NO_FRACTIONAL
public static final java.time.format.DateTimeFormatter TIMESTAMP_FORMAT_NO_FRACTIONAL
timestamp without fractional part formatter
-
MARIADB_LOCAL_DATE_TIME
public static final java.time.format.DateTimeFormatter MARIADB_LOCAL_DATE_TIME
formatter
-
COMPATIBLE_TYPES
private static final java.util.EnumSet<DataType> COMPATIBLE_TYPES
-
-
Method Detail
-
parseTextTimestamp
public static int[] parseTextTimestamp(ReadableByteBuf buf, MutableInt length)
-
isDelimiter
private static boolean isDelimiter(byte b)
-
isDigit
private static boolean isDigit(byte b)
-
adjustNanoPrecision
private static void adjustNanoPrecision(int[] parts, int nanoLength)
-
isZeroTimestamp
public static boolean isZeroTimestamp(int[] parts)
-
localDateTimeOf
static java.time.LocalDateTime localDateTimeOf(int year, int month, int dayOfMonth, int hour, int minutes, int seconds, int nanos) throws java.sql.SQLDataExceptionLocalDateTime from server values, or SQLDataException when they cannot be represented (zero day or month, permitted by the server when sql_mode doesn't contain NO_ZERO_IN_DATE).- Parameters:
year- yearmonth- monthdayOfMonth- day of monthhour- hourminutes- minutesseconds- secondsnanos- nanoseconds- Returns:
- LocalDateTime
- Throws:
java.sql.SQLDataException- if the value is not a valid date-time
-
className
public java.lang.String className()
Description copied from interface:CodecCodec native type
-
canDecode
public boolean canDecode(ColumnDecoder column, java.lang.Class<?> type)
Description copied from interface:CodecIf codec can decode this a server datatype to a java class type
-
canEncode
public boolean canEncode(java.lang.Object value)
Description copied from interface:CodecCan Codec encode the java object type
-
decodeText
public java.time.LocalDateTime decodeText(ReadableByteBuf buf, MutableInt length, ColumnDecoder column, java.util.Calendar cal, Context context) throws java.sql.SQLDataException
Description copied from interface:CodecDecode from a mysql packet text encoded a value to codec java type- Specified by:
decodeTextin interfaceCodec<java.time.LocalDateTime>- Parameters:
buf- mysql packet bufferlength- encoded value lengthcolumn- server column metadatacal- calendarcontext- connection context- Returns:
- decoded value
- Throws:
java.sql.SQLDataException- if unexpected error occurs during decoding
-
decodeBinary
public java.time.LocalDateTime decodeBinary(ReadableByteBuf buf, MutableInt length, ColumnDecoder column, java.util.Calendar cal, Context context) throws java.sql.SQLDataException
Description copied from interface:CodecDecode from a mysql packet binary encoded a value to codec java type- Specified by:
decodeBinaryin interfaceCodec<java.time.LocalDateTime>- Parameters:
buf- mysql packet bufferlength- encoded value lengthcolumn- server column metadatacal- calendarcontext- connection context- Returns:
- decoded value
- Throws:
java.sql.SQLDataException- if unexpected error occurs during decoding
-
fromConnectionTimeZone
private static java.time.LocalDateTime fromConnectionTimeZone(java.time.LocalDateTime ldt, java.util.Calendar cal, Context context)Apply timezone handling when DECODING a DATETIME/TIMESTAMP wall-clock value as a LocalDateTime. By default the value is returned verbatim (LocalDateTime is zoneless). Only whenpureLocalDateTime=falseandpreserveInstantsis set (no Calendar) is the instant converted from the connection time zone to the JVM default. A Calendar has no effect on a zoneless LocalDateTime.
-
toConnectionTimeZone
private static java.time.LocalDateTime toConnectionTimeZone(java.time.LocalDateTime ldt, java.util.Calendar cal, Context context)Inverse offromConnectionTimeZone(java.time.LocalDateTime, java.util.Calendar, org.mariadb.jdbc.client.Context), applied when ENCODING a LocalDateTime. By default, the value is sent verbatim. Only whenpureLocalDateTime=falseandpreserveInstantsis set (no Calendar) is the value, taken as a JVM-default-zone wall-clock, converted to the connection time zone before being sent (so it round-trips to the same instant).
-
encodeText
public void encodeText(Writer encoder, Context context, java.time.LocalDateTime value, java.util.Calendar cal, java.lang.Long maxLen) throws java.io.IOException
Description copied from interface:CodecText encode value to writer- Specified by:
encodeTextin interfaceCodec<java.time.LocalDateTime>- Parameters:
encoder- writercontext- connection contextvalue- value to encodecal- calendarmaxLen- maximum value length- Throws:
java.io.IOException- if any socket error occurs
-
getApproximateTextProtocolLength
public int getApproximateTextProtocolLength(java.time.LocalDateTime value, java.lang.Long length)Description copied from interface:CodecGet approximate text length, or -1 if unknown- Specified by:
getApproximateTextProtocolLengthin interfaceCodec<java.time.LocalDateTime>- Parameters:
value- parameter objectlength- max length- Returns:
- max length if known, -1 if unknown
-
encodeBinary
public void encodeBinary(Writer encoder, Context context, java.time.LocalDateTime value, java.util.Calendar cal, java.lang.Long maxLength) throws java.io.IOException
Description copied from interface:CodecBinary encode value to writer- Specified by:
encodeBinaryin interfaceCodec<java.time.LocalDateTime>- Parameters:
encoder- writercontext- connection contextvalue- value to encodecal- calendarmaxLength- maximum value length- Throws:
java.io.IOException- if any socket error occurs
-
getBinaryEncodeType
public int getBinaryEncodeType()
Description copied from interface:CodecReturn server encoding data type- Specified by:
getBinaryEncodeTypein interfaceCodec<java.time.LocalDateTime>- Returns:
- server encoding data type
-
-