You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/04/08 22:55:00 UTC

svn commit: r932111 - /openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java

Author: dwoods
Date: Thu Apr  8 20:54:59 2010
New Revision: 932111

URL: http://svn.apache.org/viewvc?rev=932111&view=rev
Log:
OPENJPA-1620 Fix TestJDBCEscapeDate test for MSSQL

Modified:
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java

Modified: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java?rev=932111&r1=932110&r2=932111&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java (original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestJDBCEscapeDate.java Thu Apr  8 20:54:59 2010
@@ -27,6 +27,8 @@ import javax.persistence.Query;
 
 import junit.framework.Assert;
 
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.SQLServerDictionary;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -52,26 +54,46 @@ public class TestJDBCEscapeDate extends 
         em.flush();
         tran.commit();
         em.clear();
+
+        String[] jpql;
+        if (((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance() instanceof SQLServerDictionary){
+            jpql = new String[] {
+                // some changes to the jpql strings had to be made for MSSQL
+                "select a from Employee a where a.hireDate >= {d '2009-08-25'}",
+                "select a from Employee a where a.hireDate >= {d '2009-08-05'}",    // requires yyyy-mm-dd
+                // "select a from Employee a where a.hireTime >= {t '00:00:00'}",   // fails ?
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123'}",
+                // "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1234'}", // more than 3
+                // "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12345'}", // fails
+                // "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123456'}",
+                "select {t '00:00:00'}, a.empId from Employee a",
+            };
+        } else {
+            jpql = new String[] {
+                "select a from Employee a where a.hireDate >= {d '2009-08-25'}",
+                "select a from Employee a where a.hireDate >= {d '2009-8-5'}",
+                "select a from Employee a where a.hireTime >= {t '00:00:00'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1234'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12345'}",
+                "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123456'}",
+                "select {t '00:00:00'}, a.empId from Employee a",
+            };
+        }
         
-        String[] jpql = {
-            "select a from Employee a where a.hireDate >= {d '2009-08-25'}",
-            "select a from Employee a where a.hireDate >= {d '2009-8-5'}",
-            "select a from Employee a where a.hireTime >= {t '00:00:00'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.1234'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.12345'}",
-            "select a from Employee a where a.hireTimestamp >= {ts '2009-08-25 00:00:00.123456'}",
-            "select {t '00:00:00'}, a.empId from Employee a",
-        };
 
         for (int i = 0; i < jpql.length; i++) {
             Query q = em.createQuery(jpql[i]);
             List results = q.getResultList();
-            Assert.assertEquals(1, results.size());
+            Assert.assertEquals("For jpql["+i+"]", 1, results.size());
         }
         
         // Test support in HAVING clause.
@@ -84,10 +106,16 @@ public class TestJDBCEscapeDate extends 
         for (int j = 0; j < havingJpql.length; j++) {
             Query q = em.createQuery(havingJpql[j]);
             List results = q.getResultList();
-            Assert.assertEquals(1, results.size());
+            Assert.assertEquals("For havingJpql["+j+"]", 1, results.size());
         }
         em.getTransaction().begin();
-        String update = "update Employee a set a.hireTimestamp = {ts '2009-08-25 00:00:00.123456'} where a.empId = 1";
+        String update;
+        if (((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance() instanceof SQLServerDictionary) {
+            // more than 3 digits after 00:00:00. fails on MSSQL
+            update = "update Employee a set a.hireTimestamp = {ts '2009-08-25 00:00:00.123'} where a.empId = 1";
+        } else {
+            update = "update Employee a set a.hireTimestamp = {ts '2009-08-25 00:00:00.123456'} where a.empId = 1";
+        }
         Query q = em.createQuery(update);
         int updateCnt = q.executeUpdate();
         em.getTransaction().commit();