public class VerticaYearMonthInterval
extends com.vertica.dsi.dataengine.utilities.DSIMonthSpan
implements java.lang.Cloneable
The JDBC representation of the Vertica INTERVAL YEAR TO MONTH
type. It represents
a span of time measured in years and months.
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 3 year/month 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 year/month 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 VericaYearMonthInterval from the database, select an INTERVAL YEAR TO MONTH
column, call ResultSet.getObject
and cast the result to
a VerticaYearMonthInterval
Modifier and Type | Field and Description |
---|---|
static int |
INTERVAL_MONTH
Deprecated.
superseded by
VerticaTypes.INTERVAL_MONTH |
static int |
INTERVAL_YEAR
Deprecated.
superseded by
VerticaTypes.INTERVAL_YEAR |
static int |
INTERVAL_YEAR_TO_MONTH
Deprecated.
superseded by
VerticaTypes.INTERVAL_YEAR_TO_MONTH |
Constructor and Description |
---|
VerticaYearMonthInterval(int year,
int month,
boolean isNegative)
Constructs a new VerticaYearMonthInterval.
|
VerticaYearMonthInterval(int type,
int year,
int month,
boolean isNegative)
Constructs a new VerticaYearMonthInterval.
|
Modifier and Type | Method and Description |
---|---|
VerticaYearMonthInterval |
clone()
Returns a deep copy of this VerticaYearMonthInterval.
|
boolean |
equals(java.lang.Object obj)
Returns true if obj is a VerticaYearMonthInterval
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 |
hashCode()
The hash code of an interval is calculated first
by converting this interval to a number of months.
|
static boolean |
isYearMonthInterval(int type)
A helper method to determine if the provided ODBC interval
subtype identifier corresponds to one of the 3 year/month
intervals that this class is capable of representing.
|
void |
setMonth(int month)
Sets the months component of this interval.
|
void |
setYear(int year)
Sets the years component of this interval.
|
java.lang.String |
toString()
Returns a string representation of this interval.
|
public static final int INTERVAL_YEAR
VerticaTypes.INTERVAL_YEAR
public static final int INTERVAL_YEAR_TO_MONTH
VerticaTypes.INTERVAL_YEAR_TO_MONTH
public static final int INTERVAL_MONTH
VerticaTypes.INTERVAL_MONTH
public VerticaYearMonthInterval(int year, int month, boolean isNegative)
INTERVAL_YEAR_TO_MONTH
.year
- The number of years in this interval. Must be no less than zero.month
- The number of months in this interval. Must be no less than zero.isNegative
- True if this interval is negative, false if positive.java.lang.IllegalArgumentException
- If year or month are negative.public VerticaYearMonthInterval(int type, int year, int month, boolean isNegative)
type
- The ODBC SQL type identifier for this interval.year
- The number of years in this interval. Must be no less than zero.month
- The number of months in this interval. Must be no less than zero.isNegative
- True if this interval is negative, false if positive.java.lang.IllegalArgumentException
- If year or month are negative, or if type is not one of the ODBC SQL type identifiers defined by this class.public void setYear(int year)
setYear
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
year
- A positive number of years.java.lang.IllegalArgumentException
- If year is negative, or if using this many years would cause the interval to overflow.public void setMonth(int month)
setMonth
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
month
- A positive number of months.java.lang.IllegalArgumentException
- If month is negative, or if using this many months would cause the interval to overflow.public int hashCode()
hashCode
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
public boolean equals(java.lang.Object obj)
INTERVAL YEAR
of 1 year is equal to an
INTERVAL YEAR TO MONTH
of 1 year, 0 months,
and an INTERVAL MONTH
of 12 months.equals
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
obj
- An object to compare.public VerticaYearMonthInterval clone()
new VerticaYearMonthInterval(getIntervalType(), getYear(), getMonth(), isNegative())
clone
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
public java.lang.String toString()
toString
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
public int getIntervalType()
getIntervalType
in class com.vertica.dsi.dataengine.utilities.DSIMonthSpan
public static boolean isYearMonthInterval(int type)
type
- An ODBC interval subtype identifier.