Top Description Fields Constructors Methods
org.apache.derby.client.am

public Class DateTime

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.reference.SQLState, .DRDAConstants, java.nio.charset.Charset, java.sql.Date, .Time, .Timestamp, java.util.Calendar, .GregorianCalendar, org.apache.derby.client.net.Typdef

High performance converters from date/time byte encodings to JDBC Date, Time and Timestamp objects.

Using this class for direct date/time conversions from bytes offers superior performance over the alternative method of first constructing a Java String from the encoded bytes, and then using java.sql.Date.valueOf(), java.sql.Time.valueOf() or java.sql.Timestamp.valueOf().

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static final Date

Returns:

Date translated from buffer with specified encoding
dateBytesToDate
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer data
encoding
)

Expected character representation is DERBY string representation of a date, which is in JIS format: yyyy-mm-dd

pack-priv static final Timestamp

Returns:

Timestamp translated from buffer with specified encoding
dateBytesToTimestamp
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
)

Expected character representation is DERBY string representation of a date which is in JIS format: yyyy-mm-dd

public static final int

Returns:

DateTime.dateRepresentationLength. This is the fixed length in bytes taken to represent the date value
dateToDateBytes
(byte[]
bytes in UTF8 encoding of the date
buffer
,
int
write into the buffer from this offset
offset
,
DateTimeValue
date value
date
)

Date is converted to a char representation in JDBC date format: yyyy-mm-dd date format and then converted to bytes using UTF8 encoding

private static Calendar
getCleanCalendar(Calendar
Calendar object to use if non-null.
recyclableCal
)

Return a clean (i.e. all values cleared out) Calendar object that can be used for creating Time, Timestamp, and Date objects.

public static int

Returns:

the timestamp length
getTimestampLength
(boolean
true if the connection supports nanoseconds in timestamps
supportsTimestampNanoseconds
)

Return the length of a timestamp depending on whether timestamps should have full nanosecond precision or be truncated to just microseconds.

private static int

Returns:

The nanoseconds field as parsed from the timestamp string. This cannot be set in the Calendar object but we still want to preserve the value, in case the caller needs it (for example, to create a java.sql.Timestamp with nanosecond precision).
parseTimestampString
(String
Timestamp value to parse, as a String.
timestamp
,
Calendar
Calendar into which to store the parsed fields. Should not be null.
cal
,
boolean
true if the server supports nanoseconds in timestamps
supportsTimestampNanoseconds
)

Parse a String of the form yyyy-mm-dd-hh.mm.ss.ffffff[fff] and store the various fields into the received Calendar object.

pack-priv static final Time

Returns:

Time translated from buffer with specified encoding
timeBytesToTime
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
)

Expected character representation is DERBY string representation of time, which is in the format: hh.mm.ss

pack-priv static final Timestamp

Returns:

Timestamp translated from buffer with specified encoding
timeBytesToTimestamp
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
)

Expected character representation is DERBY string representation of time which is in the format: hh.mm.ss

pack-priv static final Date

Returns:

Date translated from buffer with specified encoding
timestampBytesToDate
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
)

See getTimestampLength() for an explanation of how timestamps are formatted.

pack-priv static final Time

Returns:

Time translated from buffer with specified Encoding
timestampBytesToTime
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
)

See getTimestampLength() for an explanation of how timestamps are formatted.

pack-priv static final Timestamp

Returns:

TimeStamp translated from buffer with specified encoding
timestampBytesToTimestamp
(byte[] buffer, int offset, Calendar recyclableCal, Charset
encoding of buffer
encoding
,
boolean
true if the server supports nanoseconds in timestamps
supportsTimestampNanoseconds
)

See getTimestampLength() for an explanation of how timestamps are formatted.

public static final int

Returns:

DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value
timestampToTimestampBytes
(byte[]
bytes in UTF8 encoding of the timestamp
buffer
,
int
write into the buffer from this offset
offset
,
DateTimeValue
timestamp value
timestamp
,
boolean
true if the server supports nanoseconds in timestamps
supportsTimestampNanoseconds
)

See getTimestampLength() for an explanation of how timestamps are formatted.

public static final int

Returns:

DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the time value
timeToTimeBytes
(byte[]
bytes in UTF8 encoding of the time
buffer
,
int
write into the buffer from this offset
offset
,
DateTimeValue
java.sql.Time value
time
)

java.sql.Time is converted to character representation which is in JDBC time escape format: hh:mm:ss, which is the same as JIS time format in DERBY string representation of a time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dateRepresentationLengthback to summary
private static final int dateRepresentationLength
timeRepresentationLengthback to summary
private static final int timeRepresentationLength
timestampRepresentationLengthback to summary
private static final int timestampRepresentationLength

Constructor Detail

DateTimeback to summary
private DateTime()

Method Detail

dateBytesToDateback to summary
pack-priv static final Date dateBytesToDate(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

Expected character representation is DERBY string representation of a date, which is in JIS format: yyyy-mm-dd

Parameters
encoding:Charset

encoding of buffer data

Returns:Date

Date translated from buffer with specified encoding

dateBytesToTimestampback to summary
pack-priv static final Timestamp dateBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

Expected character representation is DERBY string representation of a date which is in JIS format: yyyy-mm-dd

Parameters
encoding:Charset

encoding of buffer

Returns:Timestamp

Timestamp translated from buffer with specified encoding

dateToDateBytesback to summary
public static final int dateToDateBytes(byte[] buffer, int offset, DateTimeValue date) throws SqlException

Date is converted to a char representation in JDBC date format: yyyy-mm-dd date format and then converted to bytes using UTF8 encoding

Parameters
buffer:byte[]

bytes in UTF8 encoding of the date

offset:int

write into the buffer from this offset

date:DateTimeValue

date value

Returns:int

DateTime.dateRepresentationLength. This is the fixed length in bytes taken to represent the date value

Exceptions
SqlException:
on error
getCleanCalendarback to summary
private static Calendar getCleanCalendar(Calendar recyclableCal)

Return a clean (i.e. all values cleared out) Calendar object that can be used for creating Time, Timestamp, and Date objects. If the received Calendar object is non-null, then just clear that and return it.

Parameters
recyclableCal:Calendar

Calendar object to use if non-null.

getTimestampLengthback to summary
public static int getTimestampLength(boolean supportsTimestampNanoseconds)

Return the length of a timestamp depending on whether timestamps should have full nanosecond precision or be truncated to just microseconds. java.sql.Timestamp is converted to a character representation which is a DERBY string representation of a timestamp converted to bytes using UTF8 encoding. For Derby 10.6 and above, this is yyyy-mm-dd-hh.mm.ss.fffffffff. For Derby 10.5 and below, this is yyyy-mm-dd-hh.mm.ss.ffffff. See DERBY-2602. and then converted to bytes using UTF8 encoding

Parameters
supportsTimestampNanoseconds:boolean

true if the connection supports nanoseconds in timestamps

Returns:int

the timestamp length

parseTimestampStringback to summary
private static int parseTimestampString(String timestamp, Calendar cal, boolean supportsTimestampNanoseconds)

Parse a String of the form yyyy-mm-dd-hh.mm.ss.ffffff[fff] and store the various fields into the received Calendar object.

Parameters
timestamp:String

Timestamp value to parse, as a String.

cal:Calendar

Calendar into which to store the parsed fields. Should not be null.

supportsTimestampNanoseconds:boolean

true if the server supports nanoseconds in timestamps

Returns:int

The nanoseconds field as parsed from the timestamp string. This cannot be set in the Calendar object but we still want to preserve the value, in case the caller needs it (for example, to create a java.sql.Timestamp with nanosecond precision).

timeBytesToTimeback to summary
pack-priv static final Time timeBytesToTime(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

Expected character representation is DERBY string representation of time, which is in the format: hh.mm.ss

Parameters
encoding:Charset

encoding of buffer

Returns:Time

Time translated from buffer with specified encoding

timeBytesToTimestampback to summary
pack-priv static final Timestamp timeBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

Expected character representation is DERBY string representation of time which is in the format: hh.mm.ss

Parameters
encoding:Charset

encoding of buffer

Returns:Timestamp

Timestamp translated from buffer with specified encoding

timestampBytesToDateback to summary
pack-priv static final Date timestampBytesToDate(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters
encoding:Charset

encoding of buffer

Returns:Date

Date translated from buffer with specified encoding

timestampBytesToTimeback to summary
pack-priv static final Time timestampBytesToTime(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding)

See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters
encoding:Charset

encoding of buffer

Returns:Time

Time translated from buffer with specified Encoding

timestampBytesToTimestampback to summary
pack-priv static final Timestamp timestampBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, Charset encoding, boolean supportsTimestampNanoseconds)

See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters
encoding:Charset

encoding of buffer

supportsTimestampNanoseconds:boolean

true if the server supports nanoseconds in timestamps

Returns:Timestamp

TimeStamp translated from buffer with specified encoding

timestampToTimestampBytesback to summary
public static final int timestampToTimestampBytes(byte[] buffer, int offset, DateTimeValue timestamp, boolean supportsTimestampNanoseconds) throws SqlException

See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters
buffer:byte[]

bytes in UTF8 encoding of the timestamp

offset:int

write into the buffer from this offset

timestamp:DateTimeValue

timestamp value

supportsTimestampNanoseconds:boolean

true if the server supports nanoseconds in timestamps

Returns:int

DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value

Exceptions
SqlException:
on error
timeToTimeBytesback to summary
public static final int timeToTimeBytes(byte[] buffer, int offset, DateTimeValue time)

java.sql.Time is converted to character representation which is in JDBC time escape format: hh:mm:ss, which is the same as JIS time format in DERBY string representation of a time. The char representation is converted to bytes using UTF8 encoding.

Parameters
buffer:byte[]

bytes in UTF8 encoding of the time

offset:int

write into the buffer from this offset

time:DateTimeValue

java.sql.Time value

Returns:int

DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the time value