Re: Optimistic Locking Progress report 5 - problems with Oracle 9i DATE/TIMESTAMP lockings

From: Mike Kienenberger (mkienen..laska.net)
Date: Thu Feb 12 2004 - 18:46:12 EST

  • Next message: Mike Kienenberger: "Re: Optimistic Locking Progress report 5 - problems with Oracle 9i DATE/TIMESTAMP lockings"

    I'm not sure this is legal.
    I can't use java.sql.Timestamp interchangably with java.util.Date.

    However, I will try to modify just one attribute using this method and see
    what happens.

    >From http://java.sun.com/j2se/1.3/docs/api/java/sql/Timestamp.html:
    =================================
    Note: This type is a composite of a java.util.Date and a separate
    nanoseconds value. Only integral seconds are stored in the java.util.Date
    component. The fractional seconds - the nanos - are separate. The getTime
    method will return only integral seconds. If a time value that includes the
    fractional seconds is desired, you must convert nanos to milliseconds
    (nanos/1000000) and add this to the getTime value. The
    Timestamp.equals(Object) method never returns true when passed a value of
    type java.util.Date because the nanos component of a date is unknown. As a
    result, the Timestamp.equals(Object) method is not symmetric with respect to
    the java.util.Date.equals(Object) method. Also, the hashcode method uses the
    underlying java.util.Data implementation and therefore does not include
    nanos in its computation. Due to the differences between the Timestamp class
    and the java.util.Date class mentioned above, it is recommended that code
    not view Timestamp values generically as an instance of java.util.Date. The
    inheritance relationship between Timestamp and java.util.Date really denotes
    implementation inheritance, and not type inheritance.
    =================================

    Andrus Adamchik <andru..bjectstyle.org> wrote:
    >
    > On Feb 10, 2004, at 11:58 PM, Andrus Adamchik wrote:
    > > UtilDateType and its Oracle-specific subclass - OracleUtilDateType -
    > > maybe a suspect here. Try commenting out this line from your local
    > > version of OracleAdapter.java:
    > >
    > > map.registerType(new OracleUtilDateType());
    >
    > Actually this is not the correct way to prove my suspicion, sorry.
    > Instead you should map your TIMESTAMP column as java.sql.Timestamp (not
    > java.util.Date), and try this:
    >
    > 1. Create new type handler class:
    >
    > public class TestTimestampType extends DefaultType {
    >
    > public TestTimestampType() {
    > super(java.sql.Timestamp.class.getName());
    > }
    >
    > public void setJdbcObject(
    > PreparedStatement st,
    > Object val,
    > int pos,
    > int type,
    > int precision)
    > throws Exception {
    > st.setTimestamp(pos, (java.sql.Timestamp) val);
    > }
    > }
    >
    > 2. Register this handler with OracleAdapter:
    >
    > public class OracleAdapter ...
    > protected void configureExtendedTypes(ExtendedTypeMap map) {
    > super.configureExtendedTypes(map);
    >
    > ...
    > map.registerType(new TestTimestampType());
    > }
    >
    > Andrus
    >



    This archive was generated by hypermail 2.0.0 : Thu Feb 12 2004 - 18:46:17 EST