Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 2 (11.1.2.1.0)

E17483-02

oracle.jbo.domain
Class Date

java.lang.Object
  extended by oracle.sql.Datum
      extended by oracle.sql.DATE
          extended by oracle.jbo.domain.Date
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, DomainInterface, KeyAttributeInterface, NativeTypeDomainInterface, XMLDomainInterface, XMLDomainWriter, oracle.jdbc.internal.ObjectData, ORAData

public class Date
extends DATE
implements NativeTypeDomainInterface, java.lang.Comparable, XMLDomainWriter, KeyAttributeInterface, ORAData, java.io.Serializable

This class extends oracle.sql.DATE, Oracle's Java representation of the DATE database type. This class allows an instance of the oracle.sql.DATE to be used as an immutable domain object.

The intent of many of the methods in this class is to wrap the corresponding method in the oracle.sql class such that it returns an instance of an oracle.jbo.domain.* object.

The oracle.jbo.domain.Date class is the Java representation of the underlying database type that you must use if you want to exploit the domain feature of Business Components for Java.

Date objects consist of data (a byte array) and a Domain type code. Domain dates extend SQL dates by being convertable to and from JDBC values.

Date/Time Formats Accepted

The oracle.jbo.domain.Date class accepts dates and times in the same format accepted by java.sql.TimeStamp (either a long milliseconds time value or the year, month, day, hour, minute, second, nano format) and java.sql.Date (either a milliseconds time value or the year, month, day format).

Converting Between Date Formats

The following code snippet demonstrates one technique of converting from the date format expressed by oracle.jbo.domain.Date to another format.

   ...
  Date convertedDate = new Date();
  String convertedDateString;

  java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("MM/dd/yyyy");
  convertedDateString = displayDateFormat.format(convertedDate.dateValue());
 

Converting Between Date Classes

The following code snippet demonstrates one technique of converting from an oracle.jbo.domain.Date data item to a java.util.Date data item:

  ...
  oracle.jbo.domain.Date dt = row.getBirthDate();
  java.sql.Date ts = (java.sql.Date) dt.dateValue();
  // since java.sql.Date is a java.util.Date, then...
  Calendar c = Calendar.getInstance();
  c.setTime(dt);
  ...
 

Since:
JDeveloper 3.0
See Also:
Serialized Form
javabean.class
name=Date

Field Summary
static java.sql.Time ZERO_TIME
           
 
Fields inherited from class oracle.sql.DATE
BDA, BDAL, BDT, BHR, BHRL, BMN, BMNL, BMO, BMOL, BSC, BSCL, BUILD_DATE, BYR, BYRL, HRZER0, MIZERO, MSD, SEZERO, TRACE, YR0
 
Constructor Summary
Date()
          Creates a default Date Domain object.
Date(byte[] value)
          Internal: Applications should not invoke this method.
Date(Date value)
          Creates a Date identical to an existing Date.
Date(java.sql.Date value)
          Creates a Date Domain object from a JDBC Date.
Date(DATE value)
          Creates a Date Domain object from an Oracle SQL DATE.
Date(java.sql.Date value, boolean bConvertToUserTZ)
          Creates a Date Domain object from a JDBC Date.
Date(java.sql.Date value, java.util.Calendar cal)
          Creates a Date Domain object from a JDBC Date.
Date(java.lang.Object value)
          Creates a Date Domain object from a JDBC Object.
Date(java.lang.String value)
          Creates a Date Domain object from a Java String.
Date(java.lang.String value, boolean bConvertToUserTZ)
          Creates a Date Domain object from a Java String.
Date(java.lang.String value, java.util.Calendar cal)
          Creates a Date Domain object from a Java String.
Date(java.sql.Time value)
          Creates a Date Domain object from a JDBC Time object.
Date(java.sql.Time value, boolean bConvertToUserTZ)
          Creates a Date Domain object from a JDBC Time object.
Date(java.sql.Time value, java.util.Calendar cal)
          Creates a Date Domain object from a JDBC Time object.
Date(java.sql.Timestamp value)
          Creates a Date Domain object from a JDBC Timestamp object.
Date(java.sql.Timestamp value, boolean bConvertToUserTZ)
          Creates a Date Domain object from a JDBC Timestamp object.
Date(java.sql.Timestamp value, java.util.Calendar cal)
          Creates a Date Domain object from a JDBC Timestamp object.
 
Method Summary
 DATE addJulianDays(int julianDay, int julianSec)
          Adds the number of Julian days to a DateDomain.
 DATE addMonths(int months)
          Adds months to a date.
 int compareTo(java.lang.Object n)
           
 Number diffInMonths(Date date)
          Calculates the difference between two dates in months.
 NUMBER diffInMonths(DATE date)
          Calculates the difference between two dates in months.
 boolean equals(java.lang.Object other)
          Tests this for equality with another object.
static DATE fromJulianDays(int julianDay, int julianSec)
          Converts given Julian days and seconds to a date.
static DATE fromText(java.lang.String datestr, java.lang.String fmt, java.lang.String lang)
          Converts a formatted string to a date.
static DATE getCurrentDate()
          Gets current date and time.
 java.lang.Object getData()
          Internal: Applications should not invoke this method.
 java.lang.Object getNativeObject()
           
static ORADataFactory getORADataFactory()
          Internal: Applications should not invoke this method.
 Node getSerializedDomainXML(Document xmlDoc)
          Creates the xml node in the given xml document for this domain's data in hex format of the byte[] representation of the data.
 java.util.Date getValue()
          Return a java.util.Date object with this domain's value.
 Node getXMLContentNode(Document xmlDoc)
          Creates the xml node in the given xml document for this domain's data.
static XMLDomainReaderFactory getXMLDomainFactory(java.lang.Class attrClass)
          Internal: Applications should not use this method.
 int hashCode()
          Computes a hash code for this.
 DATE lastDayOfMonth()
          Returns a date intialized to the last day of the month.
static void main(java.lang.String[] argv)
          Internal: Applications should not invoke this method.
static long parseISO8601FormatString(java.lang.String value)
          Utility method to parse date strings in ISO8601 formats.
 java.lang.String printXMLDefinition(java.util.Hashtable allDefs, java.io.PrintWriter pw, boolean bContainees)
          Prints the DTD info for this domain in the given print writer.
 DATE round(java.lang.String prec)
          Returns a date rounded to a specified precision.
 void setContext(DomainOwnerInterface owner, Transaction trans, java.lang.Object ctx)
          Internal: Applications should not invoke this method.
 DATE setDayOfWeek(int day)
          Returns a date initialized to a date advanced to the week of the day specified.
static Date toDate(java.lang.String value)
          Converts an Oracle Date expressed as a string to a Java Date.
 Datum toDatum(java.sql.Connection conn)
          Internal: Applications should not invoke this method.
 NUMBER toNumber()
          Converts this date to an oracle.sql.NUMBER.
 java.lang.String toString()
           
 DATE truncate(java.lang.String prec)
          Returns a date truncated to a specified precision.
 
Methods inherited from class oracle.sql.DATE
checkValidity, compareTo, dateValue, dateValue, diffInJulianDays, isConvertibleTo, makeJdbcArray, numberToJulianDays, parseFormat, stringValue, timestampValue, timestampValue, timeValue, timeValue, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toDate, toDate, toJdbc, toJulianDays, toString, toText, toText, toTime, toTime, toTimestamp, toTimestamp
 
Methods inherited from class oracle.sql.Datum
asciiStreamValue, bigDecimalValue, binaryStreamValue, booleanValue, byteValue, characterStreamValue, compareBytes, doubleValue, floatValue, getBytes, getLength, getStream, intValue, longValue, setBytes, setShareBytes, shareBytes, stringValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface oracle.jbo.domain.KeyAttributeInterface
getBytes, setBytes
 

Field Detail

ZERO_TIME

public static final java.sql.Time ZERO_TIME
Constructor Detail

Date

public Date()
Creates a default Date Domain object.

This constructor does not create a null date: use one of the NullValue() constructors.


Date

public Date(byte[] value)
Internal: Applications should not invoke this method.

Creates a Date Domain object from the given byte array.

Parameters:
value - a value returned by a previous call to getBytes() on an SQL object compatable with Date.

Date

public Date(DATE value)
Creates a Date Domain object from an Oracle SQL DATE.

Parameters:
value - a DATE SQL object.

Date

public Date(Date value)
Creates a Date identical to an existing Date.

Parameters:
value - a Date Domain object.

Date

public Date(java.sql.Date value)
Creates a Date Domain object from a JDBC Date.

Parameters:
value - a DATE SQL object.

Date

public Date(java.sql.Time value)
Creates a Date Domain object from a JDBC Time object.

Parameters:
value - a Time SQL object.

Date

public Date(java.sql.Timestamp value)
Creates a Date Domain object from a JDBC Timestamp object.

Parameters:
value - a TimeStamp SQL object.

Date

public Date(java.lang.Object value)
     throws java.sql.SQLException
Creates a Date Domain object from a JDBC Object.

Parameters:
value - an Object that is an instance of Date, Time, Timestamp, or String.
Throws:
java.sql.SQLException - if the object is not of one of the recognized classes.

Date

public Date(java.lang.String value)
Creates a Date Domain object from a Java String.

Parameters:
value - a textual representation of a Date.

Date

public Date(java.sql.Date value,
            boolean bConvertToUserTZ)
Creates a Date Domain object from a JDBC Date.

Parameters:
value - a DATE SQL object.
bConvertToUserTZ - if this flag is true then the date is converted to the user time zone. User Time zone is obtained from the ADF Context. It is typically configured in the application settings.

Date

public Date(java.sql.Date value,
            java.util.Calendar cal)
Creates a Date Domain object from a JDBC Date.

Parameters:
value - a DATE SQL object.
cal - converts the value to the timezone in the cal argument.

Date

public Date(java.sql.Time value,
            boolean bConvertToUserTZ)
Creates a Date Domain object from a JDBC Time object.

Parameters:
value - a Time SQL object.
bConvertToUserTZ - if this flag is true then the date is converted to the user time zone. User Time zone is obtained from the ADF Context. It is typically configured in the application settings.

Date

public Date(java.sql.Time value,
            java.util.Calendar cal)
Creates a Date Domain object from a JDBC Time object.

Parameters:
value - a Time SQL object.
cal - converts the value to the timezone in the cal argument.

Date

public Date(java.sql.Timestamp value,
            boolean bConvertToUserTZ)
Creates a Date Domain object from a JDBC Timestamp object.

Parameters:
value - a TimeStamp SQL object.
bConvertToUserTZ - if this flag is true then the date is converted to the user time zone. User Time zone is obtained from the ADF Context. It is typically configured in the application settings.

Date

public Date(java.sql.Timestamp value,
            java.util.Calendar cal)
Creates a Date Domain object from a JDBC Timestamp object.

Parameters:
value - a TimeStamp SQL object.
cal - converts the value to the timezone in the cal argument.

Date

public Date(java.lang.String value,
            boolean bConvertToUserTZ)
Creates a Date Domain object from a Java String.

Parameters:
value - a textual representation of a Date.
bConvertToUserTZ - if this flag is true then the date is converted to the user time zone. User Time zone is obtained from the ADF Context. It is typically configured in the application settings.

Date

public Date(java.lang.String value,
            java.util.Calendar cal)
Creates a Date Domain object from a Java String.

Parameters:
value - a textual representation of a Date.
cal - converts the value to the timezone in the cal argument.
Method Detail

getORADataFactory

public static ORADataFactory getORADataFactory()
Internal: Applications should not invoke this method.

Initializes the Date Domain.

This method is invoked when JBO is initialized. Applications should not call this method directly.

Returns:
the ORADataFactory for the Date Domain.

toDatum

public Datum toDatum(java.sql.Connection conn)
              throws java.sql.SQLException
Internal: Applications should not invoke this method.

Converts this Date Domain object back into an SQL DATE object.

Specified by:
toDatum in interface ORAData
Parameters:
conn - OracleConnection Not used.
Returns:
A Datum containing DATE object.
Throws:
SQLException - Never.
java.sql.SQLException

getNativeObject

public java.lang.Object getNativeObject()
Specified by:
getNativeObject in interface NativeTypeDomainInterface

getValue

public java.util.Date getValue()
Return a java.util.Date object with this domain's value. This method may be used to access the value for this domain in EL-expressions.

javabean.property

getData

public java.lang.Object getData()
Internal: Applications should not invoke this method.

Specified by:
getData in interface DomainInterface
Returns:
a formatted value object.

compareTo

public int compareTo(java.lang.Object n)
Specified by:
compareTo in interface java.lang.Comparable

setContext

public void setContext(DomainOwnerInterface owner,
                       Transaction trans,
                       java.lang.Object ctx)
Internal: Applications should not invoke this method.

Specified by:
setContext in interface DomainInterface

toDate

public static Date toDate(java.lang.String value)
Converts an Oracle Date expressed as a string to a Java Date. The Java date can be either an java.sql.Timestamp or an java.sql.Date.

Returns:
returns a java.sql.Date object.

parseISO8601FormatString

public static long parseISO8601FormatString(java.lang.String value)
Utility method to parse date strings in ISO8601 formats. Note that we only support a subset of the representations:
Format Example
YYYY-MM-DDThh:mm:ss 2010-08-08T05:34:27 Calendar date and local time
YYYY-MM-DDThh:mm:ss?hh:mm 2010-08-08T05:34:27-07:00 Calendar date and local time and UTC offset
YYYY-MM-DDThh:mm:ssZ 2010-08-08T12:34:27Z Calendar date and UTC time
YYYY-MM-DDThh:mm:ss.sss 2010-08-08T05:34:27.213 Calendar date and local time with milliseconds (three decimals for the fraction)
YYYY-MM-DDThh:mm:ss.sss?hh:mm 2010-08-08T05:34:27.213-07:00 Calendar date and local time with milliseconds and UTC offset
YYYY-MM-DDThh:mm:ss.sssZ 2010-08-08T12:34:27.213Z Calendar date and UTC time with milliseconds

Parameters:
value -
Returns:
long
Throws:
java.lang.IllegalArgumentException - if the date string is not parsable using the above ISO8601 formats

toString

public java.lang.String toString()
Overrides:
toString in class DATE

equals

public boolean equals(java.lang.Object other)
Tests this for equality with another object. The argument is converted to a Date object, if necessary.

Overrides:
equals in class Datum
Parameters:
other - an arbitrary Object.
Returns:
true if conversion was successful and the converted argument is identical to this.

hashCode

public int hashCode()
Computes a hash code for this.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this.

addJulianDays

public DATE addJulianDays(int julianDay,
                          int julianSec)
Adds the number of Julian days to a DateDomain. Returns a new Date Domain object initalized to the DATE values added to the Julian days.

Overrides:
addJulianDays in class DATE
Parameters:
julianDay - number of Julian days to add to Date.
julianSec - number of seconds past midnight.
Returns:
a new Date Domain object.
Throws:
GenericDomainException

addMonths

public DATE addMonths(int months)
Adds months to a date. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Overrides:
addMonths in class DATE
Parameters:
months - integer number of months to add to date
Returns:
new Date object initialized to the Date value added to months. Months can be negative to perform month subtraction.
See Also:
"oracle.sql.DATE"

diffInMonths

public Number diffInMonths(Date date)
Calculates the difference between two dates in months. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Parameters:
date - Date to be subtracted as a DateDomain.
Returns:
Number difference in months.
See Also:
"oracle.sql.DATE"

diffInMonths

public NUMBER diffInMonths(DATE date)
Calculates the difference between two dates in months. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Overrides:
diffInMonths in class DATE
Parameters:
date - Date to be subtracted, as an oracle.sql.DATE.
Returns:
Number difference in months.
See Also:
"oracle.sql.DATE"

getCurrentDate

public static DATE getCurrentDate()
Gets current date and time. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Returns:
a Date object
See Also:
"oracle.sql.DATE"

fromJulianDays

public static DATE fromJulianDays(int julianDay,
                                  int julianSec)
Converts given Julian days and seconds to a date. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Parameters:
julianDay - Number of Julian days
julianSec - Number of seconds past midnight
Returns:
new Date Domain object initialized based on the number of Julian days.
Throws:
GenericDomainException
See Also:
"oracle.sql.DATE"

fromText

public static DATE fromText(java.lang.String datestr,
                            java.lang.String fmt,
                            java.lang.String lang)
Converts a formatted string to a date. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object. param datestr text to convert

Parameters:
fmt - format
lang - the NLS language the conversion is to be performed in, null indicates use default.
Throws:
GenericDomainException
See Also:
"oracle.sql.DATE"

lastDayOfMonth

public DATE lastDayOfMonth()
Returns a date intialized to the last day of the month. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Overrides:
lastDayOfMonth in class DATE
Throws:
GenericDomainException
See Also:
"oracle.sql.DATE"

round

public DATE round(java.lang.String prec)
Returns a date rounded to a specified precision. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Overrides:
round in class DATE
Parameters:
prec - precision to use while rounding
Throws:
GenericDomainException
See Also:
"oracle.sql.DATE"

setDayOfWeek

public DATE setDayOfWeek(int day)
Returns a date initialized to a date advanced to the week of the day specified. Overrides the oracle.sql.DATE method of the same name to return a Date Domain object.

Overrides:
setDayOfWeek in class DATE
Parameters:
day - day of the week the date needs to be advanced
Throws:
GenericDomainException
See Also:
"oracle.sql.DATE"

toNumber

public NUMBER toNumber()
Converts this date to an oracle.sql.NUMBER.

Overrides:
toNumber in class DATE
Returns:
a Date Domain object.
Throws:
GenericDomainException

truncate

public DATE truncate(java.lang.String prec)
Returns a date truncated to a specified precision.

Overrides:
truncate in class DATE
Parameters:
prec - precision to use while truncating
Returns:
a Date Domain object.
Throws:
GenericDomainException

printXMLDefinition

public java.lang.String printXMLDefinition(java.util.Hashtable allDefs,
                                           java.io.PrintWriter pw,
                                           boolean bContainees)
Prints the DTD info for this domain in the given print writer. Returns the DTD string to be added to this domain's container entity/domain.

The allDefs hashtable contains predefined XML definitions and is passed by whatever calls this method.

Specified by:
printXMLDefinition in interface XMLDomainInterface
Parameters:
allDefs - a hashtable of predefined XML definitions passed from whatever calls this method.
pw - print writer into which the defnition is being printed.
bContainees - if true, prints definitions of contained objects.

getXMLContentNode

public Node getXMLContentNode(Document xmlDoc)
Creates the xml node in the given xml document for this domain's data.

Specified by:
getXMLContentNode in interface XMLDomainInterface
Parameters:
xmlDoc - name of the XML document in which the node should be created.

getSerializedDomainXML

public Node getSerializedDomainXML(Document xmlDoc)
Creates the xml node in the given xml document for this domain's data in hex format of the byte[] representation of the data.

Specified by:
getSerializedDomainXML in interface XMLDomainWriter
Parameters:
xmlDoc - name of the XML document in which the node should be created.

getXMLDomainFactory

public static XMLDomainReaderFactory getXMLDomainFactory(java.lang.Class attrClass)
Internal: Applications should not use this method.


main

public static void main(java.lang.String[] argv)
                 throws java.sql.SQLException
Internal: Applications should not invoke this method.

Throws:
java.sql.SQLException

Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 2 (11.1.2.1.0)

E17483-02

Copyright © 1997, 2011, Oracle. All rights reserved.