Author: ppoddar
Date: Wed Nov 18 22:44:01 2009
New Revision: 881977
URL: http://svn.apache.org/viewvc?rev=881977&view=rev
Log:
Run CriteriaTest on MySQL as well.
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java?rev=881977&r1=881976&r2=881977&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/AbstractCriteriaTestCase.java
Wed Nov 18 22:44:01 2009
@@ -206,7 +206,7 @@
fail("JPQL " + jpql + " failed to execute\r\n" + w);
}
- if (!(dict instanceof DerbyDictionary))
+ if (!(dict instanceof DerbyDictionary || dict instanceof
MySQLDictionary))
return;
for (int i = 0; i < jSQL.size(); i++) {
@@ -229,7 +229,7 @@
fail(w.toString());
}
- if (!(dict instanceof DerbyDictionary))
+ if (!(dict instanceof DerbyDictionary || dict instanceof
MySQLDictionary))
return;
String jSql = jSQL.get(0).trim();
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java?rev=881977&r1=881976&r2=881977&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
Wed Nov 18 22:44:01 2009
@@ -34,6 +34,7 @@
import javax.persistence.criteria.SetJoin;
import javax.persistence.criteria.Subquery;
+import org.apache.openjpa.jdbc.sql.DerbyDictionary;
import
org.apache.openjpa.persistence.criteria.AbstractCriteriaTestCase.QueryDecorator;
import org.apache.openjpa.persistence.embed.Division;
@@ -771,9 +772,12 @@
+ " (select distinct o.id from LineItem i, Order o"
+ " where i.quantity > 10 and o.count > 1000 and i.id = o.id)";
+ String crossJoin = (getDictionary() instanceof DerbyDictionary)
+ ? "JOIN CR_ODR t2 ON (1 = 1)"
+ : "CROSS JOIN CR_ODR t2";
String expectedSQL = "SELECT t0.id FROM CR_ODR t0 WHERE (t0.id IN ("
+ "SELECT DISTINCT t2.id "
- + "FROM CR_ODR t1 JOIN CR_ODR t2 ON (1 = 1), CR_LI t3 WHERE ("
+ + "FROM CR_ODR t1 " + crossJoin + ", CR_LI t3 WHERE ("
+ "t3.quantity > ? AND t2.cnt > ? AND t3.id = t2.id)))";
executeAndCompareSQL(jpql, expectedSQL);
@@ -1086,8 +1090,11 @@
+ " where o1.quantity = "
+ " any(select o2.quantity from in(c.orders) o2)";
+ String crossJoin = getDictionary() instanceof DerbyDictionary
+ ? "JOIN CR_CUST t1 ON (1 = 1)"
+ : "CROSS JOIN CR_CUST t1";
String expectedSQL = "SELECT t0.id, t1.name " +
- "FROM CR_ODR t0 JOIN CR_CUST t1 ON (1 = 1) WHERE (t0.quantity = ANY ("
+
+ "FROM CR_ODR t0 " + crossJoin + " WHERE (t0.quantity = ANY (" +
"SELECT t3.quantity FROM CR_ODR t2, CR_ODR t3 WHERE (t2.id = t3.id)
AND (t1.id = t2.CUSTOMER_ID)))";
executeAndCompareSQL(jpql, expectedSQL);
@@ -1182,8 +1189,11 @@
+ " (select o.quantity*2 from LineItem i, Order o"
+ " where i.quantity > 10 and o.quantity > 1000 and i.id = "
+ "o.id)";
+ String crossJoin = (getDictionary() instanceof DerbyDictionary)
+ ? "JOIN CR_ODR t2 ON (1 = 1)"
+ : "CROSS JOIN CR_ODR t2";
String expectedSQL = "SELECT t0.id FROM CR_ODR t0 WHERE (t0.quantity >
("
- + "SELECT (t2.quantity * ?) FROM CR_ODR t1 JOIN CR_ODR t2 ON (1 =
1), CR_LI t3 WHERE ("
+ + "SELECT (t2.quantity * ?) FROM CR_ODR t1 " + crossJoin + ",
CR_LI t3 WHERE ("
+ "t3.quantity > ? AND t2.quantity > ? AND t3.id = t2.id)))";
executeAndCompareSQL(jpql, expectedSQL);
@@ -1208,10 +1218,13 @@
String jpql = "select o.id from Order o where o.customer.name ="
+ " (select substring(o2.customer.name, 3) from Order o2"
+ " where o.customer.id = o2.customer.id)";
-
+
+ String useCast = (getDictionary() instanceof DerbyDictionary)
+ ? "SUBSTR(CAST((t3.name) AS VARCHAR(1000)), 3) "
+ : "SUBSTRING(t3.name, 3) ";
String expectedSQL = "SELECT t0.id FROM CR_ODR t0 "
+ "INNER JOIN CR_CUST t1 ON t0.CUSTOMER_ID = t1.id WHERE (t1.name
= ("
- + "SELECT SUBSTR(CAST((t3.name) AS VARCHAR(1000)), 3) "
+ + "SELECT " + useCast
+ "FROM CR_ODR t2 INNER JOIN CR_CUST t3 ON t2.CUSTOMER_ID = t3.id "
+ "WHERE (t0.CUSTOMER_ID = t2.CUSTOMER_ID)))";
executeAndCompareSQL(jpql, expectedSQL);
@@ -1280,10 +1293,12 @@
String jpql = "select o.id from Order o where o.customer.name in"
+ " (select CONCAT(o.customer.name, 'XX') from Order o"
+ " where o.quantity > 10)";
-
+ String useCast = getDictionary() instanceof DerbyDictionary
+ ? "(CAST(t1.name AS VARCHAR(1000)) || CAST(? AS VARCHAR(1000))) "
+ : "CONCAT(t1.name,?) ";
String expectedSQL = "SELECT t2.id FROM CR_ODR t2 "
+ "INNER JOIN CR_CUST t3 ON t2.CUSTOMER_ID = t3.id WHERE (t3.name
IN ("
- + "SELECT (CAST(t1.name AS VARCHAR(1000)) || CAST(? AS
VARCHAR(1000))) "
+ + "SELECT " + useCast
+ "FROM CR_ODR t0 INNER JOIN CR_CUST t1 ON t0.CUSTOMER_ID = t1.id
WHERE (t0.quantity > ?)))";
executeAndCompareSQL(jpql, expectedSQL);
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java?rev=881977&r1=881976&r2=881977&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Wed Nov 18 22:44:01 2009
@@ -1406,19 +1406,25 @@
}
public void testCountDistinct() {
- // JPQL Parser does not do well with the following
- String jpql = "select DISTINCT COUNT(a.name) from Account a";
+ String jpql = "select COUNT(DISTINCT a.name) from Account a";
CriteriaQuery<Long> c = cb.createQuery(Long.class);
Root<Account> a = c.from(Account.class);
c.select(cb.countDistinct(a.get(Account_.name)));
- // hence we do not check equivalence against JPQL
- // assertEquivalence(c, jpql);
- // but check against SQL
- String expectedSQL = "SELECT COUNT(DISTINCT t0.name) FROM CR_ACCT t0";
- executeAndCompareSQL(c, expectedSQL);
+ assertEquivalence(c, jpql);
+ }
+
+ public void testCountDistinctOnJoin() {
+ String jpql = "select COUNT(DISTINCT a.b.age) from A a";
+
+ CriteriaQuery<Long> c = cb.createQuery(Long.class);
+ Root<A> a = c.from(A.class);
+ c.select(cb.countDistinct(a.get(A_.b).get(B_.age)));
+
+ assertEquivalence(c, jpql);
}
+
public void testSizeReturnsInteger() {
String jpql = "select SIZE(c.accounts) from Customer c";