Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public final Class SQLTimestamp

extends DataType
implements DateTimeDataValue
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.types.DateTimeDataValue, org.apache.derby.iapi.types.DataValueDescriptor, org.apache.derby.iapi.types.Orderable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.Formatable, org.apache.derby.iapi.services.io.TypedFormat, java.io.Externalizable, java.io.Serializable
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.db.DatabaseContext, org.apache.derby.iapi.services.io.StoredFormatIds, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.i18n.LocaleFinder, org.apache.derby.iapi.services.cache.ClassSize, org.apache.derby.iapi.util.StringUtil, java.sql.Date, .Time, .Timestamp, .ResultSet, .SQLException, .PreparedStatement, java.util.Calendar, .GregorianCalendar, java.io.ObjectOutput, .ObjectInput, .IOException, java.text.DateFormat, .ParseException

This contains an instance of a SQL Timestamp object.

SQLTimestamp is stored in 3 ints - an encoded date, an encoded time and nanoseconds encodedDate = 0 indicates a null WSCTimestamp SQLTimestamp is similar to SQLTimestamp, but it does conserves space by not keeping a GregorianCalendar object PERFORMANCE OPTIMIZATION: We only instantiate the value field when required due to the overhead of the Date methods. Thus, use isNull() instead of "value == null" and getTimestamp() instead of using value directly.

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv static final char
private static final char[]
private static final char[]
private static final char[]
private int
private int
private static final char[]
pack-priv static final int
private static final char
private static final char
pack-priv static final int
private int
private static final char
private static final char
pack-priv static final int
private static final char[]
private static final char[]

Constructor Summary

AccessConstructor and Description
public
SQLTimestamp()

no-arg constructor required by Formattable

public
SQLTimestamp(Timestamp
the Timestamp value to be represented by this instance
value
,
Calendar
the time zone of the calendar is used to construct the database timestamp value
cal
)

Create a new SQLTimestamp instance that represents the specified Timestamp in the time zone of the given Calendar.

public
SQLTimestamp(Timestamp
the Timestamp value to be represented by this instance
value
)

Create a new SQLTimestamp instance that represents the specified Timestamp in the local time zone.

pack-priv
SQLTimestamp(int encodedDate, int encodedTime, int nanos)

public
public
SQLTimestamp(String timestampStr, boolean isJDBCEscape, LocaleFinder localeFinder)

Construct a timestamp from a string.

public
SQLTimestamp(String timestampStr, boolean isJDBCEscape, LocaleFinder localeFinder, Calendar cal)

Construct a timestamp from a string.

Method Summary

Modifier and TypeMethod and Description
private void
addInternal(int calIntervalType, int count, SQLTimestamp tsResult)

public DataValueDescriptor
cloneValue(boolean
any streams representing the data value will be materialized if true, the data value will be kept as a stream if possible if false
forceMaterialization
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.cloneValue.

Clone this DataValueDescriptor.

public int
compare(DataValueDescriptor
The Orderable to compare this one to.
other
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of index positioning.

public boolean
compare(int
Orderable.ORDER_OP_EQUALS means do an = comparison. Orderable.ORDER_OP_LESSTHAN means compare this < other. Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.
op
,
DataValueDescriptor
The DataValueDescriptor to compare this one to.
other
,
boolean
True means to treat nulls as ordered values, that is, treat SQL null as equal to null, and less than all other values. False means to treat nulls as unknown values, that is, the result of any comparison with a null is the UNKNOWN truth value.
orderedNulls
,
boolean
The return value to use if the result of the comparison is the UNKNOWN truth value. In other words, if orderedNulls is false, and a null is involved in the comparison, return unknownRV. This parameter is not used orderedNulls is true.
unknownRV
)

Overrides org.apache.derby.iapi.types.DataType.compare.

Implements org.apache.derby.iapi.types.DataValueDescriptor.compare.

Compare this Orderable with a given Orderable for the purpose of qualification and sorting.

private static int

Returns:

the encodedDate
computeEncodedDate
(Date
the value to convert
value
,
Calendar currentCal)

computeEncodedDate sets the date in a Calendar object and then uses the SQLDate function to compute an encoded date The encoded date is year << 16 + month << 8 + date

private static int

Returns:

the encodedTime
computeEncodedTime
(Date
the value to convert
value
,
Calendar currentCal)

computeEncodedTime extracts the hour, minute and seconds from a java.util.Date value and encodes them as hour << 16 + minute << 8 + second using the SQLTime function for encoding the data

public static DateTimeDataValue
computeTimestampFunction(DataValueDescriptor operand, DataValueFactory dvf)

Compute the SQL timestamp function.

public int
estimateMemoryUsage()

Implements org.apache.derby.iapi.types.DataValueDescriptor.estimateMemoryUsage.

Estimate the memory usage in bytes of the data value and the overhead of the class.

public Date
getDate(Calendar
calendar for object creation
cal
)

Overrides org.apache.derby.iapi.types.DataType.getDate.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getDate.

getDate returns the date portion of the timestamp Time is set to 00:00:00.0 Since Date is a JDBC object we use the JDBC definition for the time portion.

public NumberDataValue
getDate(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getDate.

Get the day of the month.

public NumberDataValue
getHours(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getHours.

Get the hour of the day out of a time or timestamp.

public int
getLength()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getLength.

Gets the length of the data value.

public NumberDataValue
getMinutes(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getMinutes.

Get the minute of the hour out of a time or timestamp.

public NumberDataValue
getMonth(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getMonth.

Get the month number out of a date.

public DataValueDescriptor
getNewNull()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getNewNull.

Get a new null value of the same type as this data value.

public Object
getObject()

Overrides org.apache.derby.iapi.types.DataType.getObject.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getObject.

Gets the value in the data value descriptor as a Java Object.

public NumberDataValue
getSeconds(NumberDataValue
The result of the previous call to this method, null if not called yet.
source
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getSeconds.

Get the second of the minute out of a time or timestamp.

public String
getString()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getString.

Gets the value in the data value descriptor as a String.

public Time
getTime(Calendar
calendar for object creation
cal
)

Overrides org.apache.derby.iapi.types.DataType.getTime.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getTime.

getTime returns the time portion of the timestamp Date is set to 1970-01-01 Since Time is a JDBC object we use the JDBC definition for the date portion.

public Timestamp

Returns:

The value field.
getTimestamp
(Calendar
calendar for object creation
cal
)

Overrides org.apache.derby.iapi.types.DataType.getTimestamp.

Implements org.apache.derby.iapi.types.DataValueDescriptor.getTimestamp.

Get the value field.

public int
public String
getTypeName()

Implements org.apache.derby.iapi.types.DataValueDescriptor.getTypeName.

Get the SQL name of the datatype

public NumberDataValue
getYear(NumberDataValue
The result of the previous call to this method, null if not called yet.
result
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.getYear.

Get the year number out of a date.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final boolean

Returns:

Whether or not value is logically null.
isNull
()

Implements org.apache.derby.iapi.services.io.Storable.isNull.

Check if the value is null.

pack-priv NumberDataValue
pack-priv NumberDataValue
pack-priv static int[]

Returns:

{encodedDate, encodedTime, nanosecond} array.
parseDateOrTimestamp
(DateTimeParser
a DateTimeParser initialized with a string.
parser
,
boolean
If true then an error will be thrown if the time is missing. If false then the time may be omitted.
timeRequired
)

Parse a timestamp or a date.

pack-priv static int
parseDateTimeInteger(String str, int start, int ndigits)

pack-priv static int[]

Returns:

a {encodedDate, encodedTime} array.
parseLocalTimestamp
(String
the timestamp string, with trailing blanks removed.
str
,
LocaleFinder localeFinder, Calendar cal)

Parse a localized timestamp.

private void
parseTimestamp(String timestampStr, boolean isJDBCEscape, LocaleFinder localeFinder, Calendar cal)

pack-priv static SQLTimestamp

Returns:

the corresponding timestamp, using the current date if datetime is a time, or time 00:00:00 if datetime is a date.
promote
(DateTimeDataValue dateTime, Date currentDate)

Promotes a DateTimeDataValue to a timestamp.

public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public void
restoreToNull()

Implements org.apache.derby.iapi.services.io.Storable.restoreToNull.

Restore this object to its (SQL)null value.

private void
protected void
setFrom(DataValueDescriptor
The DataValueDescriptor that holds the value to which we want to set this DataValueDescriptor's value.
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setFrom.

Set the value of this DataValueDescriptor based on the value of the specified DataValueDescriptor.

public void
setInto(PreparedStatement ps, int position)

Overrides org.apache.derby.iapi.types.DataType.setInto.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setInto.

Set this value into a PreparedStatement.

private void
setNumericTimestamp(Timestamp value, Calendar cal)

Set the encoded values for the timestamp

pack-priv void
setObject(Object theValue)

Overrides org.apache.derby.iapi.types.DataType.setObject.

Set the value from a correctly typed Timestamp object.

public void
setValue(Date
The Date value to set this DataValueDescriptor to
value
,
Calendar
The time zone from the calendar is used to construct the database date value
cal
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor.

public void
setValue(Timestamp
The Timestamp value to set this DataValueDescriptor to
value
,
Calendar
The time zone from the calendar is used to construct the database timestamp value
cal
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor.

public void
setValue(String
The String value to set this DataValueDescriptor to
theValue
)

Overrides org.apache.derby.iapi.types.DataType.setValue.

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValue.

Set the value of this DataValueDescriptor.

public void
setValueFromResultSet(ResultSet
The specified ResultSet.
resultSet
,
int
The 1-based column # into the resultSet.
colNumber
,
boolean
Whether or not the column is nullable (No need to call wasNull() if not)
isNullable
)

Implements org.apache.derby.iapi.types.DataValueDescriptor.setValueFromResultSet.

Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet.

public DateTimeDataValue

Returns:

startTime + intervalCount intervals, as a timestamp
timestampAdd
(int
One of FRAC_SECOND_INTERVAL, SECOND_INTERVAL, MINUTE_INTERVAL, HOUR_INTERVAL, DAY_INTERVAL, WEEK_INTERVAL, MONTH_INTERVAL, QUARTER_INTERVAL, or YEAR_INTERVAL
intervalType
,
NumberDataValue
The number of intervals to add
count
,
Date
Used to convert time to timestamp
currentDate
,
DateTimeDataValue
If non-null a DateTimeDataValue that can be used to hold the result. If null then generate a new holder
resultHolder
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.timestampAdd.

Add a number of intervals to a datetime value.

public NumberDataValue

Returns:

the number of intervals by which this datetime is greater than time1
timestampDiff
(int
One of FRAC_SECOND_INTERVAL, SECOND_INTERVAL, MINUTE_INTERVAL, HOUR_INTERVAL, DAY_INTERVAL, WEEK_INTERVAL, MONTH_INTERVAL, QUARTER_INTERVAL, or YEAR_INTERVAL
intervalType
,
DateTimeDataValue time1, Date
Used to convert time to timestamp
currentDate
,
NumberDataValue
If non-null a NumberDataValue that can be used to hold the result. If null then generate a new holder
resultHolder
)

Implements org.apache.derby.iapi.types.DateTimeDataValue.timestampDiff.

Finds the difference between two datetime values as a number of intervals.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public int
public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from org.apache.derby.iapi.types.DataType:
checkHostVariablecloneHoldercoalescecomparecomparecompareTodataTypeConversionequalsequalsflipgenericSetObjectgetBooleangetBytegetBytesgetDoublegetFloatgetIntgetLonggetShortgetStreamgetTraceStringgetTypeNamegreaterOrEqualsgreaterThanhasStreamininvalidFormatisNotNullisNullOplessOrEqualslessThannormalizenotEqualsoutOfRangereadExternalFromArrayrecyclesetBigDecimalsetIntosetObjectForCastsetToNullsetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuesetValuethrowLangSetMismatchthrowLangSetMismatchtypeToBigDecimal