net.sf.farrago.type.runtime
Class SqlDateTimeWithoutTZ

java.lang.Object
  extended by net.sf.farrago.type.runtime.SqlDateTimeWithoutTZ
All Implemented Interfaces:
AssignableValue, DataValue, SpecialDataValue
Direct Known Subclasses:
SqlDateTimeWithoutTZ.SqlDate, SqlDateTimeWithoutTZ.SqlTime, SqlDateTimeWithoutTZ.SqlTimestamp

public abstract class SqlDateTimeWithoutTZ
extends Object
implements AssignableValue, SpecialDataValue

Runtime type for basic date/time/timestamp values without time zone information. All of these types are represented by subclasses of ZonelessDatetime and have a similar internal representation. This class interoperates with java.sql (Jdbc) types since they are commonly used for external data.

TODO: we can probably be smarter about how we allocate Java objects

TODO: precision and milliseconds for TIME and TIMESTAMP

Since:
May 5, 2004
Version:
$Id: //open/dev/farrago/src/net/sf/farrago/type/runtime/SqlDateTimeWithoutTZ.java#34 $
Author:
lee

Nested Class Summary
static class SqlDateTimeWithoutTZ.SqlDate
          SQL date value.
static class SqlDateTimeWithoutTZ.SqlTime
          SQL time value.
static class SqlDateTimeWithoutTZ.SqlTimestamp
          SQL timestamp value.
 
Field Summary
static String ADJUST_PRECISION_METHOD_NAME
          Name of adjustPrecision(int) method.
private  Calendar cal
          Calendar, which holds the client time zone.
static String CEIL_METHOD_NAME
          Name of ceil(org.eigenbase.sql.SqlIntervalQualifier.TimeUnit) method.
static String DateFormatStr
           
private static TimeZone defaultZone
           
static String FLOOR_METHOD_NAME
          Name of floor(org.eigenbase.sql.SqlIntervalQualifier.TimeUnit) method.
private static TimeZone gmtZone
           
static String INTERNAL_TIME_FIELD_NAME
           
 boolean isNull
          Whether this value is null.
private  Calendar tempCal
          The calendar to use as a temporary variable.
static String TimeFormatStr
           
static String TimestampFormatStr
           
 ZonelessDatetime value
          The raw value of this SqlDateTimeWithoutTZ
 
Fields inherited from interface net.sf.farrago.type.runtime.AssignableValue
ASSIGNMENT_METHOD_NAME
 
Constructor Summary
SqlDateTimeWithoutTZ()
          Constructs a runtime object
 
Method Summary
 void adjustPrecision(int precision)
          Adjusts the precision of the value.
 void assignFrom(long l)
          Assigns a value from another object.
 void assignFrom(Object date)
          Assigns a value from another object.
 void assignFrom(String date, String format, TimeZone timeZone)
          Assigns a value from a formatted string, optionally performing timezone translation.
protected abstract  void assignFromString(String s, String format, TimeZone timeZone)
          Assigns the value from a string.
private  void attemptParse(String s, String format, TimeZone timeZone)
          Attempts to parse the string, throwing an understandable exception if an error was detected.
 void ceil(int timeUnitOrdinal)
          Rounds this datetime value up to a unit of time expressed using its ordinal.
 void ceil(SqlIntervalQualifier.TimeUnit timeUnit)
          Rounds this datetime value up to a unit of time.
 void floor(int timeUnitOrdinal)
          Rounds this datetime value down to a unit of time expressed using its ordinal.
 void floor(SqlIntervalQualifier.TimeUnit timeUnit)
          Rounds this datetime value down to a unit of time.
 Calendar getCal()
          Deprecated. please review this code
protected  TimeZone getClientTimeZone()
          Returns the client time zone, as indicated by Calendar
protected abstract  String getFormat()
          Returns the format string for this type.
protected abstract  Object getJdbcValue()
          Gets data, casted as a Jdbc value.
 Object getNullableData()
          Per the NullableValue contract, returns either null or the value of this object as a Jdbc compatible value.
static Class getPrimitiveClass()
           
 Object getSpecialData()
          Return data to result sets as ZonelessDatetime so that it may be properly localized by a Jdbc driver or client application.
protected  Calendar getTempCal()
          Gets a temporary calendar object, initialized with this object's time zone and milliseconds value.
protected abstract  String getTypeName()
          Returns the name of this type: DATE, TIME, or TIMESTAMP.
protected  TimeZone getValueTimeZone()
          Returns the time zone used to store the value
 boolean isNull()
           
 void setCal(Calendar cal)
          Deprecated. please review this code
 void setNull(boolean b)
          (Optionally) implements NullableValue
 String toString()
          Returns a string in default format representing the datetime.
 String toString(String format)
          Deprecated. please review this code
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DateFormatStr

public static final String DateFormatStr
See Also:
Constant Field Values

TimeFormatStr

public static final String TimeFormatStr
See Also:
Constant Field Values

TimestampFormatStr

public static final String TimestampFormatStr
See Also:
Constant Field Values

gmtZone

private static final TimeZone gmtZone

defaultZone

private static final TimeZone defaultZone

INTERNAL_TIME_FIELD_NAME

public static final String INTERNAL_TIME_FIELD_NAME
See Also:
Constant Field Values

ADJUST_PRECISION_METHOD_NAME

public static final String ADJUST_PRECISION_METHOD_NAME
Name of adjustPrecision(int) method.

See Also:
Constant Field Values

FLOOR_METHOD_NAME

public static final String FLOOR_METHOD_NAME
Name of floor(org.eigenbase.sql.SqlIntervalQualifier.TimeUnit) method.

See Also:
Constant Field Values

CEIL_METHOD_NAME

public static final String CEIL_METHOD_NAME
Name of ceil(org.eigenbase.sql.SqlIntervalQualifier.TimeUnit) method.

See Also:
Constant Field Values

cal

private Calendar cal
Calendar, which holds the client time zone. It defaults to null, which implies that no explicit time zone has been set.


tempCal

private Calendar tempCal
The calendar to use as a temporary variable. This calendar's time zone is set to the value time zone.


value

public ZonelessDatetime value
The raw value of this SqlDateTimeWithoutTZ


isNull

public boolean isNull
Whether this value is null.

Constructor Detail

SqlDateTimeWithoutTZ

public SqlDateTimeWithoutTZ()
Constructs a runtime object

Method Detail

getPrimitiveClass

public static Class getPrimitiveClass()
Returns:
long.class

getJdbcValue

protected abstract Object getJdbcValue()
Gets data, casted as a Jdbc value.


setNull

public void setNull(boolean b)
(Optionally) implements NullableValue


getNullableData

public Object getNullableData()
Per the NullableValue contract, returns either null or the value of this object as a Jdbc compatible value. The Jdbc value is constructed relative to the server default time zone.

Specified by:
getNullableData in interface DataValue
Returns:
an Object representation of this value's data, or null if this value is null

getSpecialData

public Object getSpecialData()
Return data to result sets as ZonelessDatetime so that it may be properly localized by a Jdbc driver or client application.

Specified by:
getSpecialData in interface SpecialDataValue
Returns:
an Object representation of this value's data, or null if this value is null

isNull

public boolean isNull()
Returns:
whether the value has been set to null

assignFrom

public void assignFrom(Object date)
Assigns a value from another object.

The Object may be a Long or long if it is being intialized from a constant, or being translated from a Fennel value. If so, then the Fennel type must match the Farrago type. It is legal to assign a ZonelessDate to a ZonelessDate and a ZonelessTime to a ZonelessTime, but it is not valid to assign a Timestamp to either, or vice versa.

Specified by:
assignFrom in interface AssignableValue
Parameters:
date - value to assign, or null to set null

assignFrom

public void assignFrom(String date,
                       String format,
                       TimeZone timeZone)
Assigns a value from a formatted string, optionally performing timezone translation.

If format is null, uses the default format string of this type, as per getFormat().

If timeZone is not null, performs translation assuming that the input string is in that time zone. For example, assignFrom('06:00', 'HH:mm', TimeZone.PST) returns the Time value '14:00', because '06:00 PST' equals '14:00 GMT'.

timeZone is ignored for date values.

Parameters:
date - string
format - format string, as per SimpleDateFormat, or null
timeZone - target timezone
See Also:
assignFrom(Object)

assignFrom

public void assignFrom(long l)
Assigns a value from another object.

See Also:
assignFrom(Object)

attemptParse

private void attemptParse(String s,
                          String format,
                          TimeZone timeZone)
Attempts to parse the string, throwing an understandable exception if an error was detected.


assignFromString

protected abstract void assignFromString(String s,
                                         String format,
                                         TimeZone timeZone)
Assigns the value from a string.

Parameters:
s - a string representing a datetime in the given format
format - format string as per SimpleDateFormat, not null
timeZone - target timezone

getCal

public Calendar getCal()
Deprecated. please review this code

Gets a calendar with the time and time zone of this value. The calendar returned is not the internal calendar of this SqlDateTimeWithoutTZ. TODO: does anyone use this? Currently it returns a copy of a Calendar with the value time zone and the milliseconds.


setCal

public void setCal(Calendar cal)
Deprecated. please review this code

Assigns the time and time zone from a Calendar value. TODO: Does anyone use this? If so, we want to be careful about the meaning of this.cal. Elsewhere we use it for "client time zone" but here we seem to be using it to mean "value time zone". Or if we indeed mean "client time zone", then we should not be setting the milliseconds time value.

Parameters:
cal - calendar value to assign from

toString

public String toString(String format)
Deprecated. please review this code

Returns a string in the specified datetime format TODO: does anyone use this?


getClientTimeZone

protected TimeZone getClientTimeZone()
Returns the client time zone, as indicated by Calendar


getValueTimeZone

protected TimeZone getValueTimeZone()
Returns the time zone used to store the value


toString

public String toString()
Returns a string in default format representing the datetime.

Overrides:
toString in class Object

getFormat

protected abstract String getFormat()
Returns the format string for this type.


getTypeName

protected abstract String getTypeName()
Returns the name of this type: DATE, TIME, or TIMESTAMP.


floor

public void floor(SqlIntervalQualifier.TimeUnit timeUnit)
Rounds this datetime value down to a unit of time. All smaller units of time are zeroed also.

For example, floor(MINUTE) applied to TIMESTAMP '2006-07-03 12:34:56.7' returns TIMESTAMP '2006-07-03 12:00:00.0'.

Parameters:
timeUnit - Time unit

floor

public void floor(int timeUnitOrdinal)
Rounds this datetime value down to a unit of time expressed using its ordinal. Called by generated code.

Parameters:
timeUnitOrdinal - Ordinal of SqlIntervalQualifier.TimeUnit value

ceil

public void ceil(SqlIntervalQualifier.TimeUnit timeUnit)
Rounds this datetime value up to a unit of time. All smaller units of time are zeroed.

For example, ceil(MINUTE) applied to TIMESTAMP '2006-07-03 12:34:56.7' returns TIMESTAMP '2006-07-03 13:00:00.0'.

Parameters:
timeUnit - Time unit

ceil

public void ceil(int timeUnitOrdinal)
Rounds this datetime value up to a unit of time expressed using its ordinal. Called by generated code.

Parameters:
timeUnitOrdinal - Ordinal of SqlIntervalQualifier.TimeUnit value

adjustPrecision

public void adjustPrecision(int precision)
Adjusts the precision of the value.

For example, adjustPrecision(2) applied to the value TIME '12:34:56.789' rounds to 10 milliseconds, and returns TIME '12:34:56.79'.

Parameters:
precision - Number of digits to keep the right of the decimal point in the seconds value

getTempCal

protected Calendar getTempCal()
Gets a temporary calendar object, initialized with this object's time zone and milliseconds value.