org.apache.derby.client.am
Class DateTime

java.lang.Object
  extended by org.apache.derby.client.am.DateTime

public class DateTime
extends java.lang.Object

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
private static int dateRepresentationLength
           
private static int timeRepresentationLength
           
private static int timestampRepresentationLength
           
 
Constructor Summary
private DateTime()
           
 
Method Summary
static java.sql.Date dateBytesToDate(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          Expected character representation is DERBY string representation of a date, which is in JIS format: yyyy-mm-dd
static java.sql.Timestamp dateBytesToTimestamp(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          Expected character representation is DERBY string representation of a date which is in JIS format: yyyy-mm-dd
static int dateToDateBytes(byte[] buffer, int offset, DateTimeValue 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 java.util.Calendar getCleanCalendar(java.util.Calendar recyclableCal)
          Return a clean (i.e. all values cleared out) Calendar object that can be used for creating Time, Timestamp, and Date objects.
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.
private static int parseTimestampString(java.lang.String timestamp, java.util.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.
static java.sql.Time timeBytesToTime(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          Expected character representation is DERBY string representation of time, which is in the format: hh.mm.ss
static java.sql.Timestamp timeBytesToTimestamp(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          Expected character representation is DERBY string representation of time which is in the format: hh.mm.ss
static java.sql.Date timestampBytesToDate(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          See getTimestampLength() for an explanation of how timestamps are formatted.
static java.sql.Time timestampBytesToTime(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding)
          See getTimestampLength() for an explanation of how timestamps are formatted.
static java.sql.Timestamp timestampBytesToTimestamp(byte[] buffer, int offset, java.util.Calendar recyclableCal, java.lang.String encoding, boolean supportsTimestampNanoseconds)
          See getTimestampLength() for an explanation of how timestamps are formatted.
static int timestampToDateBytes(byte[] buffer, int offset, java.sql.Timestamp timestamp)
          java.sql.Timestamp is converted to character representation that is in JDBC date escape format: yyyy-mm-dd, which is the same as JIS date format in DERBY string representation of a date.
static int timestampToTimeBytes(byte[] buffer, int offset, java.sql.Timestamp timestamp)
          java.sql.Timestamp is converted to character representation in JDBC time escape format: hh:mm:ss, which is the same as JIS time format in DERBY string representation of a time.
static int timestampToTimestampBytes(byte[] buffer, int offset, DateTimeValue timestamp, boolean supportsTimestampNanoseconds)
          See getTimestampLength() for an explanation of how timestamps are formatted.
static 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dateRepresentationLength

private static final int dateRepresentationLength
See Also:
Constant Field Values

timeRepresentationLength

private static final int timeRepresentationLength
See Also:
Constant Field Values

timestampRepresentationLength

private static final int timestampRepresentationLength
See Also:
Constant Field Values
Constructor Detail

DateTime

private DateTime()
Method Detail

dateBytesToDate

public static final java.sql.Date dateBytesToDate(byte[] buffer,
                                                  int offset,
                                                  java.util.Calendar recyclableCal,
                                                  java.lang.String encoding)
                                           throws java.io.UnsupportedEncodingException
Expected character representation is DERBY string representation of a date, which is in JIS format: yyyy-mm-dd

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer data
Returns:
Date translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

timeBytesToTime

public static final java.sql.Time timeBytesToTime(byte[] buffer,
                                                  int offset,
                                                  java.util.Calendar recyclableCal,
                                                  java.lang.String encoding)
                                           throws java.io.UnsupportedEncodingException
Expected character representation is DERBY string representation of time, which is in the format: hh.mm.ss

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
Returns:
Time translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

timestampBytesToTimestamp

public static final java.sql.Timestamp timestampBytesToTimestamp(byte[] buffer,
                                                                 int offset,
                                                                 java.util.Calendar recyclableCal,
                                                                 java.lang.String encoding,
                                                                 boolean supportsTimestampNanoseconds)
                                                          throws java.io.UnsupportedEncodingException
See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
supportsTimestampNanoseconds - true if the server supports nanoseconds in timestamps
Returns:
TimeStamp translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

parseTimestampString

private static int parseTimestampString(java.lang.String timestamp,
                                        java.util.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 - Timestamp value to parse, as a String.
cal - Calendar into which to store the parsed fields. Should not be null.
supportsTimestampNanoseconds - true if the server supports nanoseconds in timestamps
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).

dateToDateBytes

public static final int dateToDateBytes(byte[] buffer,
                                        int offset,
                                        DateTimeValue date)
                                 throws SqlException,
                                        java.io.UnsupportedEncodingException
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 - bytes in UTF8 encoding of the date
offset - write into the buffer from this offset
date - date value
Returns:
DateTime.dateRepresentationLength. This is the fixed length in bytes taken to represent the date value
Throws:
SqlException
java.io.UnsupportedEncodingException - if UTF8 Encoding is not supported

timeToTimeBytes

public static final int timeToTimeBytes(byte[] buffer,
                                        int offset,
                                        DateTimeValue time)
                                 throws java.io.UnsupportedEncodingException
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 - bytes in UTF8 encoding of the time
offset - write into the buffer from this offset
time - java.sql.Time value
Returns:
DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the time value
Throws:
java.io.UnsupportedEncodingException

timestampToTimestampBytes

public static final int timestampToTimestampBytes(byte[] buffer,
                                                  int offset,
                                                  DateTimeValue timestamp,
                                                  boolean supportsTimestampNanoseconds)
                                           throws SqlException,
                                                  java.io.UnsupportedEncodingException
See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters:
buffer - bytes in UTF8 encoding of the timestamp
offset - write into the buffer from this offset
timestamp - timestamp value
supportsTimestampNanoseconds - true if the server supports nanoseconds in timestamps
Returns:
DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value
Throws:
SqlException
java.io.UnsupportedEncodingException

dateBytesToTimestamp

public static final java.sql.Timestamp dateBytesToTimestamp(byte[] buffer,
                                                            int offset,
                                                            java.util.Calendar recyclableCal,
                                                            java.lang.String encoding)
                                                     throws java.io.UnsupportedEncodingException
Expected character representation is DERBY string representation of a date which is in JIS format: yyyy-mm-dd

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
Returns:
Timestamp translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

timeBytesToTimestamp

public static final java.sql.Timestamp timeBytesToTimestamp(byte[] buffer,
                                                            int offset,
                                                            java.util.Calendar recyclableCal,
                                                            java.lang.String encoding)
                                                     throws java.io.UnsupportedEncodingException
Expected character representation is DERBY string representation of time which is in the format: hh.mm.ss

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
Returns:
Timestamp translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

timestampBytesToDate

public static final java.sql.Date timestampBytesToDate(byte[] buffer,
                                                       int offset,
                                                       java.util.Calendar recyclableCal,
                                                       java.lang.String encoding)
                                                throws java.io.UnsupportedEncodingException
See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
Returns:
Date translated from buffer with specified encoding
Throws:
java.io.UnsupportedEncodingException

timestampBytesToTime

public static final java.sql.Time timestampBytesToTime(byte[] buffer,
                                                       int offset,
                                                       java.util.Calendar recyclableCal,
                                                       java.lang.String encoding)
                                                throws java.io.UnsupportedEncodingException
See getTimestampLength() for an explanation of how timestamps are formatted.

Parameters:
buffer -
offset -
recyclableCal -
encoding - encoding of buffer
Returns:
Time translated from buffer with specified Encoding
Throws:
java.io.UnsupportedEncodingException

getCleanCalendar

private static java.util.Calendar getCleanCalendar(java.util.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 object to use if non-null.

timestampToDateBytes

public static final int timestampToDateBytes(byte[] buffer,
                                             int offset,
                                             java.sql.Timestamp timestamp)
                                      throws SqlException,
                                             java.io.UnsupportedEncodingException
java.sql.Timestamp is converted to character representation that is in JDBC date escape format: yyyy-mm-dd, which is the same as JIS date format in DERBY string representation of a date. and then converted to bytes using UTF8 encoding.

Parameters:
buffer -
offset - write into the buffer from this offset
timestamp - timestamp value
Returns:
DateTime.dateRepresentationLength. This is the fixed length in bytes, that is taken to represent the timestamp value as a date.
Throws:
SqlException
java.io.UnsupportedEncodingException

timestampToTimeBytes

public static final int timestampToTimeBytes(byte[] buffer,
                                             int offset,
                                             java.sql.Timestamp timestamp)
                                      throws java.io.UnsupportedEncodingException
java.sql.Timestamp is converted to character representation 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 then converted to bytes using UTF8 encoding and written out into the buffer

Parameters:
buffer -
offset - write into the buffer from this offset
timestamp - timestamp value
Returns:
DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the timestamp value as Time.
Throws:
java.io.UnsupportedEncodingException

getTimestampLength

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 - true if the connection supports nanoseconds in timestamps

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.