VerticaDayTimeInterval

  • java.lang.Object

  • com.vertica.dsi.dataengine.utilities.DSITimeSpan

  • com.vertica.jdbc.VerticaDayTimeInterval

  • All Implemented Interfaces: java.lang.Cloneable

public class VerticaDayTimeInterval
extends com.vertica.dsi.dataengine.utilities.DSITimeSpan
implements java.lang.Cloneable

The JDBC representation of the Vertica INTERVAL DAY TO SECOND type. It represents a span of time measured in days, hours, minutes, seconds and nanoseconds.

The JDBC specification does not define first class support for interval data types. There are no java.sql.Types type identifiers for intervals, there is no built in setter on the PreparedStatement interface and no built in getter on the ResultSet interface.

Instead, the Vertica JDBC driver follows the ODBC standard when it can. Each of the 10 day/time interval ranges is identified by the ODBC standard SQL type identifier. Those identifiers are recreated as integer fields in this class, analogous to those defined for the other data types by java.sql.Types.

To insert a day/time interval into the database, create an instance of this class and pass it to PreparedStatement.setObject, optionally passing one of the ODBC SQL types defined by this class as the target type parameter.

To retrieve a VericaDayTimeInterval from the database, select an INTERVAL DAY TO SECOND column, call ResultSet.getObject and cast the result to a VerticaDayTimeInterval

Field Summary

Modifier and Type Field and Description
static int INTERVAL_DAY Deprecated. superseded by VerticaTypes.INTERVAL_DAY
static int INTERVAL_DAY_TO_HOUR Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_HOUR
static int INTERVAL_DAY_TO_MINUTE Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_MINUTE
static int INTERVAL_DAY_TO_SECOND Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_SECOND
static int INTERVAL_HOUR Deprecated. superseded by VerticaTypes.INTERVAL_HOUR
static int INTERVAL_HOUR_TO_MINUTE Deprecated. superseded by VerticaTypes.INTERVAL_HOUR_TO_MINUTE
static int INTERVAL_HOUR_TO_SECOND Deprecated. superseded by VerticaTypes.INTERVAL_HOUR_TO_SECOND
static int INTERVAL_MINUTE Deprecated. superseded by VerticaTypes.INTERVAL_MINUTE
static int INTERVAL_MINUTE_TO_SECOND Deprecated. superseded by VerticaTypes.INTERVAL_MINUTE_TO_SECOND
static int INTERVAL_SECOND Deprecated. superseded by VerticaTypes.INTERVAL_SECOND

Constructor Summary

Constructor and Description
VerticaDayTimeInterval(int day, int hour, int minute, int second, int fraction, int fracPrecision, boolean isNegative)
VerticaDayTimeInterval(int type, int day, int hour, int minute, int second, int fraction, int fracPrecision, boolean isNegative) Constructs a new VerticaDayTimeInterval.

Method Summary

Modifier and Type Method and Description
VerticaDayTimeInterval clone() Returns a deep copy of this VerticaDayTimeInterval.
boolean equals(java.lang.Object obj) Returns true if obj is a VerticaDayTimeInterval and it represents the same span of time as this interval, regardless of which units are set.
int getIntervalType() Gets the ODBC SQL type identifier for this interval.
int getPrecision()
int hashCode() The hash code of an interval is computed first by converting the value of this interval to a number of nanoseconds.
static boolean isDayTimeInterval(int type) A helper method to determine if the provided ODBC interval subtype identifier corresponds to one of the 10 day/time intervals that this class is capable of representing.
void setDay(int day) Sets the days component of this interval.
void setFraction(int fraction, int precision) Sets the fraction component of this interval.
void setHour(int hour) Sets the hours component of this interval.
void setIsNegative(boolean isNegative) Sets the sign of this interval.
void setMinute(int minute) Sets the minutes component of this interval.
void setSecond(int second) Sets the seconds component of this interval.
java.lang.String toString() Returns a string representation of this interval.

Methods inherited from class com.vertica.dsi.dataengine.utilities.DSITimeSpan

getDay, getFraction, getHour, getMinute, getSecond, isNegative, setFraction

Methods inherited from class java.lang.Object

getClass, notify, notifyAll, wait, wait, wait

Field Detail

INTERVAL_DAY

public static final int INTERVAL_DAY

Deprecated. superseded by VerticaTypes.INTERVAL_DAY The ODBC SQL type identifier for an INTERVAL DAY interval. See Also:Constant Field Values

INTERVAL_DAY_TO_HOUR

public static final int INTERVAL_DAY_TO_HOUR

Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_HOUR The ODBC SQL type identifier for an INTERVAL DAY TO HOUR interval. See Also:Constant Field Values

INTERVAL_DAY_TO_MINUTE

public static final int INTERVAL_DAY_TO_MINUTE

Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_MINUTE The ODBC SQL type identifier for an INTERVAL DAY TO MINUTE interval. See Also:Constant Field Values

INTERVAL_DAY_TO_SECOND

public static final int INTERVAL_DAY_TO_SECOND

Deprecated. superseded by VerticaTypes.INTERVAL_DAY_TO_SECOND The ODBC SQL type identifier for an INTERVAL DAY TO SECOND interval. See Also:Constant Field Values

INTERVAL_HOUR

public static final int INTERVAL_HOUR

Deprecated. superseded by VerticaTypes.INTERVAL_HOUR The ODBC SQL type identifier for an INTERVAL HOUR interval. See Also:Constant Field Values

INTERVAL_HOUR_TO_MINUTE

public static final int INTERVAL_HOUR_TO_MINUTE

Deprecated. superseded by VerticaTypes.INTERVAL_HOUR_TO_MINUTE The ODBC SQL type identifier for an INTERVAL HOUR TO MINUTE interval. See Also:Constant Field Values

INTERVAL_HOUR_TO_SECOND

public static final int INTERVAL_HOUR_TO_SECOND

Deprecated. superseded by VerticaTypes.INTERVAL_HOUR_TO_SECOND The ODBC SQL type identifier for an INTERVAL HOUR TO SECOND interval. See Also:Constant Field Values

INTERVAL_MINUTE

public static final int INTERVAL_MINUTE

Deprecated. superseded by VerticaTypes.INTERVAL_MINUTE The ODBC SQL type identifier for an INTERVAL MINUTE interval. See Also:Constant Field Values

INTERVAL_MINUTE_TO_SECOND

public static final int INTERVAL_MINUTE_TO_SECOND

Deprecated. superseded by VerticaTypes.INTERVAL_MINUTE_TO_SECOND The ODBC SQL type identifier for an INTERVAL MINUTE TO SECOND interval. See Also:Constant Field Values

INTERVAL_SECOND

public static final int INTERVAL_SECOND

Deprecated. superseded by VerticaTypes.INTERVAL_SECOND The ODBC SQL type identifier for an INTERVAL SECOND interval. See Also:Constant Field Values

Constructor Detail

VerticaDayTimeInterval

public VerticaDayTimeInterval(int day,
int hour,
int minute,
int second,
int fraction,
int fracPrecision,
boolean isNegative)

VerticaDayTimeInterval

public VerticaDayTimeInterval(int type,
int day,
int hour,
int minute,
int second,
int fraction,
int fracPrecision,
boolean isNegative)

Constructs a new VerticaDayTimeInterval. Parameters:type - The ODBC SQL type identifier for this interval.day - The number of days in this interval. Must be no less than zero.hour - The number of hours in this interval. Must be no less than zero.minute - The number of minutes in this interval. Must be no less than zero.second - The number of seconds in this interval. Must be no less than zero.fraction - The fractional seconds in this interval. Must be no less than zero.fracPrecision - The precision of the fractional seconds, 6 or less (database can't store more).isNegative - True if this interval is negative, false if positive. Throws: java.lang.IllegalArgumentException - If any of the parameters are negative, or if type is not one of the ODBC SQL type identifiers defined by this class.

Method Detail

getPrecision

public int getPrecision()

setDay

public void setDay(int day)

Sets the days component of this interval. If this interval has no day component, it will be converted to the closest unit representable by the type. Any fraction on the converted value is rounded down.

Overrides setDay in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:day - A positive number of days. Throws: java.lang.IllegalArgumentException - If day is negative, or if using this many days would cause the interval to overflow.

setHour

public void setHour(int hour)

Sets the hours component of this interval. If this interval has no hour component, it will be converted to the closest unit representable by the type. Any fraction on the converted value is rounded down.

Overrides setHour in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:hour - A positive number of hours. Throws: java.lang.IllegalArgumentException - If hour is negative, or if using this many hours would cause the interval to overflow.

setMinute

public void setMinute(int minute)

Sets the minutes component of this interval. If this interval has no minute component, it will be converted to the closest unit representable by the type. Any fraction on the converted value is rounded down.

Overrides setMinute in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:minute - A positive number of minutes. Throws: java.lang.IllegalArgumentException - If minute is negative, or if using this many minutes would cause the interval to overflow.

setSecond

public void setSecond(int second)

Sets the seconds component of this interval. If this interval has no minute component, it will be converted to the closest unit representable by the type. Any fraction on the converted value is rounded down.

Overrides setSecond in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:second - A positive number of seconds. Throws: java.lang.IllegalArgumentException - If second is negative, or if using this many seconds would cause the interval to overflow.

setFraction

public void setFraction(int fraction,
int precision)

Sets the fraction component of this interval. If this interval has no fraction component, it will be converted to the closest unit representable by the type. Parameters:fraction - A positive number of microseconds.precision - The precision to use for this interval. Throws: java.lang.IllegalArgumentException - If fraction is negative, or if using this many microseconds would cause the interval to overflow.

setIsNegative

public void setIsNegative(boolean isNegative)

Sets the sign of this interval.

Overrides setIsNegative in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:isNegative - true if this interval is negative, false otherwise.

hashCode

public int hashCode()

The hash code of an interval is computed first by converting the value of this interval to a number of nanoseconds. Since the hash code must fit in an integer, It is possible that this calculation will overflow. Regardless of whether or not there was overflow, this number is then multiplied by -1 if this interval negative.

Overrides hashCode in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Returns A hash code for this interval.

equals

public boolean equals(java.lang.Object obj)

Returns true if obj is a VerticaDayTimeInterval and it represents the same span of time as this interval, regardless of which units are set.

Overrides equals in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Parameters:obj - An object to compare. Returns true if obj has the same sign, day, hour, minute, second and fraction as this interval.

clone

public VerticaDayTimeInterval clone()

Returns a deep copy of this VerticaDayTimeInterval. Equivalent to calling new VerticaDayTimeInterval(getIntervalType(), getDay(), getHour(), getMinute(), getSecond(), getFraction(), isNegative())

Overrides clone in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Returns A copy of this interval.

toString

public java.lang.String toString()

Returns a string representation of this interval. The format of this string is the same format that is recognized by the driver and database. Fields outside this interval's range (as defined by the ODBC type identifier) are not included in the String.

Overrides toString in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Returns The string representation of this interval.

getIntervalType

public int getIntervalType()

Gets the ODBC SQL type identifier for this interval. An interval's range can be determined by comparing the return value of this method with the INTERVAL_* constants defined in this class.

Overrides getIntervalType in class com.vertica.dsi.dataengine.utilities.DSITimeSpan Returns The ODBC SQL type identifier for this interval.

isDayTimeInterval

public static boolean isDayTimeInterval(int type)

A helper method to determine if the provided ODBC interval subtype identifier corresponds to one of the 10 day/time intervals that this class is capable of representing.

The SQL_DATETIME_SUB column of the ResultSet returned by DatabaseMetaData.getColumns() will contain an ODBC interval subtype when the column is an interval. When this happens, the object returned by the driver when selecting that column will be a VerticaDayTimeInterval when the subtype is one of the 10 interval subtypes defined in this class. This helper method checks the provided type to see if it matches one of those 10 types. Parameters:type - An ODBC interval subtype identifier. Returns true if type corresponds to one of the 10 day/time interval types representable by a VerticaDayTimeInterval.