persistence@glassfish.java.net

RE: Fix for issue 248

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Wed, 15 Mar 2006 16:24:31 -0500

Hi Mitesh,
        I think we should define a new ExpressionOperator for use by EJBQL. ExpressionOperator.Today is a pre-existing expression that has defined behaviour. If there are current users using it we should not break their code.

Perhaps ExpressionOperator.currentDate, ExpressionOperator.currentTimestamp.

I think your proposal for applying the TO_DATE on Oracle for ExpressionOperator.currentDate would be correct.

What do you think?
--Gordon

-----Original Message-----
From: Mitesh Meswani [mailto:mitesh.meswani_at_Sun.COM]
Sent: Tuesday, March 14, 2006 9:15 PM
To: Tom Ware
Cc: persistence_at_glassfish.dev.java.net
Subject: Fix for issue 248


Hi Tom,
Could you please review the attached fix for issue
248(https://glassfish.dev.java.net/issues/show_bug.cgi?id=248)
It changes the code to use "CURRENT DATE" instead of "CURRENT TIMESTAMP"
for ExpressionOperator.Today. I have tested the change on both db2 as
well as derby

Following is the diff
$ cvs diff
src/java/oracle/toplink/essentials/platform/database/DB2Platform.java
diff -r1.6 DB2Platform.java
467c467
< v.addElement("CURRENT TIMESTAMP");
---
 >         v.addElement("CURRENT DATE");
--------------------------------------------------
I tried to add a test case to cover EJBQL expression CURRENT_DATE  to 
JUnitEJBQLDateTimeTestSuite as follows.
    public void testCurrentDate() {
        List result = createEntityManager().createQuery("SELECT 
OBJECT(o) FROM DateTime o WHERE o.date = CURRENT_DATE").
            getResultList();
        assertTrue("There should be one result", result.size() == 1);
    }
The test passes on derby and db2 but fails on oracle. This is because on 
Oracle ExpressionOperator.Today is mapped to SYSDATE which returns both 
date and time and hence the generated sql (select ... from 
CMP3_DATE_TIME where SQL_DATE = SYSDATE) for above ejbql does not return 
any rows . I think we should switch mapping of ExpressionOperator.Today 
to TO_DATE(SYSDATE) on OraclePlatform. What do you think?
Thanks,
Mitesh