Business Components

oracle.jbo.domain
Class Date

oracle.jbo.domain.Date
All Implemented Interfaces:
java.io.Serializable

public class Date
implements java.io.Serializable

This class provides a lightweight wrapper for oracle.sql.DATE, the Java representation of the DATE database type. This wrapper 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.DateDomain 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.DateDomain 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.

  ...
  oracle.jbo.domain.Date tmpDate = null;
  SimpleDateFormat tmpLocalFormat = new SimpleDateFormat();
  SimpleDateFormat tmpLocalFormat2 = new SimpleDateFormat();

  // obtain a date element
  tmpDate = (oracle.jbo.domain.Date) session.getValue("DateElem");

  // test that the date is not null
  if (tmpDate == null)
     {
     // throw an exception
      throw new RuntimeException("Date is invalid.");
      }

  // initialize the date format objects
  tmpLocalFormat.applyPattern("yyyy-MM-dd");
  tmpLocalFormat2.applyPattern("dd-MM-yyyy");

  // convert the date formats yyyy-MM-dd => dd-MM-yyyy
  tmpWhereClause =
  new String(tmpLocalFormat2.format(tmpLocalFormat.parse(tmpDate.toString())));
  ...
 

Another example follows:

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

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

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 = this.getBirth();
  java.sql.Date ts = (java.sql.Date) dateValue();
  // since java.sql.Date is a java.util.Date, then...
  Calendar c = new Calendar(dt);
  ...
 

Since:
JDeveloper 3.0
See Also:
Serialized Form

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.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.sql.Time value)
          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.
 
Method Summary
TypeMethod
 DATE addJulianDays(int julianDay, int julianSec)
          Adds the number of Julian days to a DateDomain.
 DATE addMonths(int months)
          Adds months to a date.
 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.
static CustomDatumFactory getCustomDatumFactory()
          Internal: Applications should not invoke this method.
 java.lang.Object getData()
          Internal: Applications should not invoke 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.
 DATE round(java.lang.String prec)
          Returns a date rounded to a specified precision.
 void setContext(oracle.jbo.domain.DomainOwnerInterface owner, oracle.jbo.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(OracleConnection conn)
          Internal: Applications should not invoke this method.
 NUMBER toNumber()
          Converts this date to an oracle.sql.NUMBER.
 java.lang.String toString()
          For testing purposes only: converts this to a textual representation.
 DATE truncate(java.lang.String prec)
          Returns a date truncated to a specified precision.
 

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.
Method Detail

getCustomDatumFactory

public static CustomDatumFactory getCustomDatumFactory()
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 CustomDatumFactory for the Date Domain.

toDatum

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

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

Parameters:
conn - Not used.
Returns:
A Datum containing DATE object.
Throws:
SQLException - Never.

getData

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

setContext

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

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.

toString

public java.lang.String toString()
For testing purposes only: converts this to a textual representation.

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.
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.
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.
Parameters:
julianDay - number of Julian days to add to Date.
julianSec - number of seconds past midnight.
Returns:
a new Date Domain object.
Throws:
oracle.jbo.domain.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.
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.
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:
oracle.jbo.domain.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:
oracle.jbo.domain.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.
Throws:
oracle.jbo.domain.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.
Parameters:
prec - precision to use while rounding
Throws:
oracle.jbo.domain.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.
Parameters:
day - day of the week the date needs to be advanced
Throws:
oracle.jbo.domain.GenericDomainException -  
See Also:
"oracle.sql.DATE"

toNumber

public NUMBER toNumber()
Converts this date to an oracle.sql.NUMBER.
Returns:
a Date Domain object.
Throws:
oracle.jbo.domain.GenericDomainException -  

truncate

public DATE truncate(java.lang.String prec)
Returns a date truncated to a specified precision.
Parameters:
prec - precision to use while truncating
Returns:
a Date Domain object.
Throws:
oracle.jbo.domain.GenericDomainException -  

main

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

Business Components