mirror of https://github.com/apache/openjpa.git
OPENJPA-1620 Fix TestJDBCEscapeDate test for MSSQL
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@932111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cf752cbc09
commit
b7010472cc
|
@ -27,6 +27,8 @@ import javax.persistence.Query;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
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;
|
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,26 +54,46 @@ public class TestJDBCEscapeDate extends SingleEMFTestCase {
|
||||||
em.flush();
|
em.flush();
|
||||||
tran.commit();
|
tran.commit();
|
||||||
em.clear();
|
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++) {
|
for (int i = 0; i < jpql.length; i++) {
|
||||||
Query q = em.createQuery(jpql[i]);
|
Query q = em.createQuery(jpql[i]);
|
||||||
List results = q.getResultList();
|
List results = q.getResultList();
|
||||||
Assert.assertEquals(1, results.size());
|
Assert.assertEquals("For jpql["+i+"]", 1, results.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test support in HAVING clause.
|
// Test support in HAVING clause.
|
||||||
|
@ -84,10 +106,16 @@ public class TestJDBCEscapeDate extends SingleEMFTestCase {
|
||||||
for (int j = 0; j < havingJpql.length; j++) {
|
for (int j = 0; j < havingJpql.length; j++) {
|
||||||
Query q = em.createQuery(havingJpql[j]);
|
Query q = em.createQuery(havingJpql[j]);
|
||||||
List results = q.getResultList();
|
List results = q.getResultList();
|
||||||
Assert.assertEquals(1, results.size());
|
Assert.assertEquals("For havingJpql["+j+"]", 1, results.size());
|
||||||
}
|
}
|
||||||
em.getTransaction().begin();
|
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);
|
Query q = em.createQuery(update);
|
||||||
int updateCnt = q.executeUpdate();
|
int updateCnt = q.executeUpdate();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
Loading…
Reference in New Issue