AW: AW: AW: Problem with Date/Time-part

From: René Kulschewski (KU..vu.de)
Date: Fri Feb 25 2005 - 04:20:25 EST

  • Next message: Francesca: "RE: Questions about errors"

    I added the following code to UtilDateType.java (Cayenne 1.2M2) and than it
    works (at least for me):

    case Types.DATE :
               try
                {
                  val = rs.getTimestamp(index);
                } catch (Exception ex){
                  val = rs.getDate(index);
                }
                break;

    It now looks this way:

        public Object materializeObject(ResultSet rs, int index, int type) throws
    Exception {
            Object val = null;

            switch (type) {
                case Types.TIMESTAMP :
                    val = rs.getTimestamp(index);
                    break;
                case Types.DATE :
                        try
                        {
                        val = rs.getTimestamp(index);
                        } catch (Exception ex){
                        val = rs.getDate(index);
                        }
                    break;
                case Types.TIME :
                    val = rs.getTime(index);
                    break;
                default :
                    val = rs.getObject(index);
                    break;
            }

            // all sql time/date classes are subclasses of java.util.Date,
            // so lets cast it to Date,
            // if it is not date, ClassCastException will be thrown,
            // which is what we want
            return (rs.wasNull())
                ? null
                : new java.util.Date(((java.util.Date) val).getTime());
        }

    It looks like that the Oracle JDBC driver reports the type "Date", but it
    cotains also the "time part".

    Andrus, does this fix help you to find a "more general" way to deal with that
    issue and to integrate a fix into Cayenne ?

    Regards
    René

    > -----Ursprüngliche Nachricht-----
    > Von: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Gesendet: Donnerstag, 24. Februar 2005 22:24
    > An: cayenne-use..bjectstyle.org
    > Betreff: Re: AW: AW: Problem with Date/Time-part
    >
    > Ok, then the best thing to do is to submit a bug report in
    > Cayenne Jira.
    > Please include SQL DDL to create a table in question and the
    > test code.
    > We'll check it out.
    >
    > Andrus
    >
    > > Hmm.
    > >
    > > This works (with the same JDBC driver) and gives me the
    > Time part (in
    > > the first "println" of course).
    > >
    > > -->
    > >
    > > import java.sql.CallableStatement;
    > > import java.sql.Connection;
    > > import java.sql.DriverManager;
    > > import java.sql.ResultSet;
    > > import java.sql.SQLException;
    > > import java.util.Date;
    > >
    > >
    > > public class Sqltest {
    > >
    > > public static void main(String[] args) throws SQLException,
    > > ClassNotFoundException {
    > >
    > > CallableStatement cstmt1;
    > > Class.forName("oracle.jdbc.driver.OracleDriver");
    > > Connection
    > >
    > con=DriverManager.getConnection("jdbc:oracle:thin..vu-ora-3:1
    > 521:orc1",
    > > "comavravr", "ivu");
    > >
    > > cstmt1 = con.prepareCall(
    > > "select * from comdeviceevent
    > where id=71381");
    > >
    > > ResultSet rs=cstmt1.executeQuery();
    > > while (rs.next()){
    > > Date d=rs.getTimestamp("txdatetime");
    > > System.out.println(d.toLocaleString());
    > > d=rs.getDate("txdatetime");
    > > System.out.println(d.toLocaleString());
    > > }
    > > cstmt1.close();
    > > }
    > > }
    > >
    > > <--
    > >
    > > So i'm not so sure that it is not Cayenne related.
    > >
    > > Regards
    > > René
    > >
    > >> -----Ursprüngliche Nachricht-----
    > >> Von: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > >> Gesendet: Donnerstag, 24. Februar 2005 19:06
    > >> An: cayenne-use..bjectstyle.org
    > >> Betreff: Re: AW: Problem with Date/Time-part
    > >>
    > >> That's a JDBC-level error. At this point I don't think this is
    > >> anything Cayenne-related. Check that you have driver
    > version matching
    > >> the Oracle version. Try to reproduce the problem from a test
    > >> application going directly through JDBC, and if it still breaks,
    > >> submit a bug to Oracle.
    > >>
    > >> Still strange... Cayenne is being tested on Oracle 9i
    > nightly, and I
    > >> have never seen this problem...
    > >>
    > >> Andrus
    > >>
    > >> > I get the following error:
    > >> >
    > >> > 24.12 18:12:59,360|[ShutdownHook]|INFO |access.QueryLogger
    > >> |
    > >> > - select id, comdeviceevnmeth_id, isacknowledge, comdevice_id,
    > >> txdatetime, rxdatetime, gpstime, gpslongitude, gpslatitude,
    > >> > directionofmotion, velocity, locationangle, locationdescription,
    > >> locationdistance, t.indata.getclobval() indata, creation,
    > creationby,
    > >> > modification, modificationby, isdeleted,
    > >> comdeviceevnstate_id, tour_id
    > >> > from comdeviceevent t where
    > >> > t.comdeviceevnstate_id=1 order by
    > >> t.comdevice_id,t.txdatetime,t.gpstime
    > >> > 24.12 18:12:59,420|[ShutdownHook]|INFO |access.QueryLogger
    > >> |
    > >> > - *** error.
    > >> > java.sql.SQLException: Ungültiger Spaltentyp
    > >> > at
    > >> oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    > >> > at
    > >> >
    > oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at
    > >> oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at
    > >> >
    > >>
    > oracle.jdbc.driver.OracleStatement.getTimestampValue(OracleStatement.
    > >> j
    > >> > ava:498
    > >> > 2)
    > >> > at
    > >> >
    > >> oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResu
    > >> ltSetImpl.java:
    > >> > 689)
    > >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    > Method) at
    > >> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
    > >> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
    > >> > java.lang.reflect.Method.invoke(Unknown Source)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.types.DefaultType.materializeObject(De
    > >> f
    > >> > aultTyp
    > >> > e.java:243)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DefaultResultIterator.readDataRow(Defa
    > >> u
    > >> > ltResul
    > >> > tIterator.java:250)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DefaultResultIterator.nextDataRow(Defa
    > >> u
    > >> > ltResul
    > >> > tIterator.java:194)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DefaultResultIterator.dataRows(Default
    > >> R
    > >> > esultIt
    > >> > erator.java:224)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.jdbc.SQLTemplateSelectExecutionPlan.ex
    > >> e
    > >> > cute(SQ
    > >> > LTemplateSelectExecutionPlan.java:149)
    > >> > at
    > >> >
    > >> org.objectstyle.cayenne.access.DataNode.performQueries(DataNod
    > >> e.java:342)
    > >> > at
    > >> >
    > >> org.objectstyle.cayenne.access.DataDomain.performQueries(DataD
    > >> omain.java:654)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DataContext.performQueries(DataContext.
    > >> > java:14
    > >> > 08)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.Transaction.performQueries(Transaction.
    > >> > java:17
    > >> > 9)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DataContext.performQueries(DataContext.
    > >> > java:13
    > >> > 66)
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.j
    > >> a
    > >> > va:1622
    > >> > )
    > >> > at
    > >> >
    > >>
    > org.objectstyle.cayenne.access.DataContext.performQuery(DataContext.j
    > >> a
    > >> > va:1485
    > >> > )
    > >> > at
    > >> >
    > >>
    > de.ivu.combitour.dao.ComdeviceeventDAO.findUnprocessed(Comdeviceevent
    > >> D
    > >> > AO.java
    > >> > :84)
    > >> > at
    > >> >
    > >>
    > de.ivu.combitour.telematik.CdepController.processEvents(CdepControlle
    > >> r
    > >> > .java:1
    > >> > 11)
    > >> > at de.ivu.combitour.telematik.Cdep.ProcessIdle(Cdep.java:75)
    > >> > at de.ivu.combitour.ShutdownHook$1.run(ShutdownHook.java:25)
    > >> >
    > >> > Thats the statement:
    > >> >
    > >> > String sqlStr = "select id, comdeviceevnmeth_id, isacknowledge,
    > >> comdevice_id, "
    > >> > + "#result('txdatetime'
    > >> > 'java.sql.Timestamp'), "
    > >> > + "#result('rxdatetime'
    > >> > 'java.sql.Timestamp'), "
    > >> > + "#result('gpstime'
    > >> 'java.sql.Timestamp'),"
    > >> > + " gpslongitude, gpslatitude, "
    > >> > + "directionofmotion, velocity,
    > locationangle,
    > >> > locationdescription, "
    > >> > + "locationdistance,
    > >> t.indata.getclobval() indata, "
    > >> > + "#result('creation'
    > >> 'java.sql.Timestamp'), "
    > >> > + "creationby, "
    > >> > + "#result('modification'
    > >> > 'java.sql.Timestamp'), "
    > >> > + "modificationby, isdeleted, "
    > >> > + "comdeviceevnstate_id, tour_id "
    > >> > + "from comdeviceevent t where
    > >> > t.comdeviceevnstate_id=1"
    > >> > + " order by
    > >> > t.comdevice_id,t.txdatetime,t.gpstime";
    > >> >
    > >> > Regards
    > >> > René
    > >> >
    > >> >> -----Ursprüngliche Nachricht-----
    > >> >> Von: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > >> >> Gesendet: Donnerstag, 24. Februar 2005 17:58
    > >> >> An: cayenne-use..bjectstyle.org
    > >> >> Betreff: Re: Problem with Date/Time-part
    > >> >>
    > >> >> Maybe it doesn't, but Oracle driver is a strange beast.
    > >> Could you try
    > >> >> using SQLTemplate with a "#result" directive
    > >> >> (http://objectstyle.org/cayenne/userguide/fetch/sqltemplate-sc
    > >> ripting.html).
    > >> >> In your sqlString variable replace all date columns
    > with scriplets
    > >> like this one:
    > >> >>
    > >> >> #result('creation' 'java.sql.Timestamp')
    > >> >>
    > >> >> Does it change anything?
    > >> >>
    > >> >> Andrus
    > >> >>
    > >> >>
    > >> >> > Hi,
    > >> >> >
    > >> >> > This is a sample. But the access method doesnt matter IMHO,
    > >> >> even if i
    > >> >> > access a object by ObjA.getToObjB() it is the same behaviour.
    > >> >> >
    > >> >> > -->
    > >> >> > public List findUnprocessed() {
    > >> >> >
    > >> >> > String sqlStr = "select id,
    > >> >> comdeviceevnmeth_id, isacknowledge,
    > >> >> > comdevice_id, "
    > >> >> > + "txdatetime, rxdatetime,
    > >> >> gpstime, gpslongitude, gpslatitude, "
    > >> >> > + "directionofmotion, velocity,
    > >> locationangle,
    > >> >> > locationdescription, "
    > >> >> > + "locationdistance,
    > >> >> t.indata.getclobval() indata, creation, "
    > >> >> > + "creationby, modification,
    > >> >> modificationby, isdeleted, "
    > >> >> > +
    > "comdeviceevnstate_id, tour_id "
    > >> >> > + "from comdeviceevent
    > t where t.comdeviceevnstate_id=1"
    > >> >> > + " order by
    > >> >> > t.comdevice_id,t.txdatetime,t.gpstime";
    > >> >> >
    > >> >> > List retval = null;
    > >> >> >
    > >> >> > DataContext ctx
    > >> >> _SingletonDataContext.getInstance().getCtx();
    > >> >> >
    > >> >> > SQLTemplate rsCde = new
    > >> >> SQLTemplate(Comdeviceevent.class, sqlStr,
    > >> >> > true);
    > >> >> >
    > >> >> > retval = ctx.performQuery(rsCde);
    > >> >> >
    > >> >> > return retval;
    > >> >> > }
    > >> >> >
    > >> >> > <--
    > >> >> >
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>
    > >>
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Feb 25 2005 - 04:20:41 EST