org.tentackle.db
Class OracleHelper

java.lang.Object
  extended by org.tentackle.db.OracleHelper

public class OracleHelper
extends Object

Oracle-specific utility methods.

Date-conversion: Oracle does not use an index on a DATE-column if passed as a Timestamp-variable via a prepared statement, even if used in conjunction with an SQL-hint /*+ INDEX(...) In such cases the TO_DATE-function must be explicitly used.

 Example:

      if (getDb().isOracle()) {
        query.add(" AND m." + FIELD_ZEITPUNKT + ">=" + OracleHelper.timestampString(par.vonZeitpunkt));
      }
      else  {
        query.add(" AND m." + FIELD_ZEITPUNKT + ">=?", par.vonZeitpunkt);
      }


 or:
      if (getDb().isOracle()) {
        query.add(" AND m." + FIELD_ZEITPUNKT + ">=TO_DATE(?,'" + OracleHelper.ORA_TIMESTAMP_FORMAT + "')", 
                  OracleHelper.timestampFormat.format(par.vonZeitpunkt));
      }
      else  {
        query.add(" AND m." + FIELD_ZEITPUNKT + ">=?", par.vonZeitpunkt);
      }
 
Rule: if possible use TIMESTAMP column type for a Timestamp-java attribute. In such a case at least Oracle 10 uses the correct index and you don't need OracleHelper.

Author:
harald

Field Summary
static DateFormat dateFormat
           
static String emptyString
           
static String ORA_DATE_FORMAT
           
static String ORA_TIME_FORMAT
           
static String ORA_TIMESTAMP_FORMAT
           
static DateFormat timeFormat
           
static DateFormat timestampFormat
           
 
Constructor Summary
OracleHelper()
           
 
Method Summary
static String dateString(Date date)
          Converts a date to a string.
static String timestampString(Timestamp timestamp)
          Converts a timestamp to a string.
static String timeString(Time time)
          Converts a time to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORA_DATE_FORMAT

public static final String ORA_DATE_FORMAT
See Also:
Constant Field Values

ORA_TIME_FORMAT

public static final String ORA_TIME_FORMAT
See Also:
Constant Field Values

ORA_TIMESTAMP_FORMAT

public static final String ORA_TIMESTAMP_FORMAT
See Also:
Constant Field Values

dateFormat

public static final DateFormat dateFormat

timeFormat

public static final DateFormat timeFormat

timestampFormat

public static final DateFormat timestampFormat

emptyString

public static final String emptyString
See Also:
Constant Field Values
Constructor Detail

OracleHelper

public OracleHelper()
Method Detail

dateString

public static String dateString(Date date)
Converts a date to a string.

Parameters:
date - the date
Returns:
a TO_DATE-date-string

timeString

public static String timeString(Time time)
Converts a time to a string.

Parameters:
time - the time
Returns:
a TO_DATE-time-string

timestampString

public static String timestampString(Timestamp timestamp)
Converts a timestamp to a string.

Parameters:
timestamp - the timestamp
Returns:
a TO_DATE-timestamp-string


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de