openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r923589 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persisten...
Date Tue, 16 Mar 2010 06:11:19 GMT
Author: fancy
Date: Tue Mar 16 06:11:18 2010
New Revision: 923589

URL: http://svn.apache.org/viewvc?rev=923589&view=rev
Log:
OPENJPA-1573: Incorrect SQL for HAVING = entity variable

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.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
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=923589&r1=923588&r2=923589&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
Tue Mar 16 06:11:18 2010
@@ -189,6 +189,12 @@ public class PCPath
         if (_cid)
             return;
 
+        Action last = _actions == null ? null : (Action) _actions.getLast();
+        if (last != null && last.op == Action.VAR && ((String)last.data).equals(last.var))
{
+            _cid = true;
+            return;
+        }            
+            
         // treat it just like a unique variable
         Action action = new Action();
         action.op = Action.VAR;

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=923589&r1=923588&r2=923589&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
Tue Mar 16 06:11:18 2010
@@ -35,8 +35,6 @@ import javax.persistence.criteria.SetJoi
 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;
 
 /**
  * Tests type-strict version of Criteria API.
@@ -658,17 +656,16 @@ public class TestJPQLSubquery extends Cr
         String jpql = "select c from Customer c left join c.orders o where exists"
             + " (select o2 from c.orders o2 where o2 = o)";
 
-        String expectedSQL = "SELECT t0.id, t0.accountNum, t5.id, t5.city, t5.country, t5.county,
"
-            + "t5.state, t5.street, t6.userid, t6.DTYPE, t6.age, t6.compName, t6.creditRating,
t6.name, "
-            + "t5.zipCode, t0.balanceOwed, t0.creditRating, t0.filledOrderCount, t0.firstName,
t0.lastName, "
+        String expectedSQL = "SELECT t0.id, t0.accountNum, t4.id, t4.city, t4.country, t4.county,
"
+            + "t4.state, t4.street, t5.userid, t5.DTYPE, t5.age, t5.compName, t5.creditRating,
t5.name, "
+            + "t4.zipCode, t0.balanceOwed, t0.creditRating, t0.filledOrderCount, t0.firstName,
t0.lastName, "
             + "t0.name, t0.status "
             + "FROM CR_CUST t0 "
             + "LEFT OUTER JOIN CR_ODR t1 ON t0.id = t1.CUSTOMER_ID "
-            + "LEFT OUTER JOIN CR_ODR t2 ON t0.id = t2.CUSTOMER_ID "
-            + "LEFT OUTER JOIN CR_ADDR t5 ON t0.ADDRESS_ID = t5.id "
-            + "LEFT OUTER JOIN CompUser t6 ON t5.id = t6.ADD_ID WHERE (EXISTS ("
-            + "SELECT t4.id FROM CR_ODR t3, CR_ODR t4 WHERE (t2.id = t4.id AND t3.id = t4.id)
"
-            + "AND (t0.id = t3.CUSTOMER_ID)))";
+            + "LEFT OUTER JOIN CR_ADDR t4 ON t0.ADDRESS_ID = t4.id "
+            + "LEFT OUTER JOIN CompUser t5 ON t4.id = t5.ADD_ID WHERE (EXISTS (" 
+            + "SELECT t3.id FROM CR_ODR t2, CR_ODR t3 WHERE (t1.id = t3.id AND t2.id = t3.id)
"
+            + "AND (t0.id = t2.CUSTOMER_ID)))";
 
         executeAndCompareSQL(jpql, expectedSQL);
 
@@ -711,17 +708,16 @@ public class TestJPQLSubquery extends Cr
         String jpql = "select c from Customer c left join c.orders o where not exists"
             + " (select o2 from c.orders o2 where o2 = o)";
 
-        String expectedSQL = "SELECT t0.id, t0.accountNum, t5.id, t5.city, t5.country, t5.county,
"
-            + "t5.state, t5.street, t6.userid, t6.DTYPE, t6.age, t6.compName, t6.creditRating,
t6.name, "
-            + "t5.zipCode, t0.balanceOwed, t0.creditRating, t0.filledOrderCount, t0.firstName,
t0.lastName, "
+        String expectedSQL = "SELECT t0.id, t0.accountNum, t4.id, t4.city, t4.country, t4.county,
"
+            + "t4.state, t4.street, t5.userid, t5.DTYPE, t5.age, t5.compName, t5.creditRating,
t5.name, "
+            + "t4.zipCode, t0.balanceOwed, t0.creditRating, t0.filledOrderCount, t0.firstName,
t0.lastName, "
             + "t0.name, t0.status "
             + "FROM CR_CUST t0 "
             + "LEFT OUTER JOIN CR_ODR t1 ON t0.id = t1.CUSTOMER_ID "
-            + "LEFT OUTER JOIN CR_ODR t2 ON t0.id = t2.CUSTOMER_ID "
-            + "LEFT OUTER JOIN CR_ADDR t5 ON t0.ADDRESS_ID = t5.id "
-            + "LEFT OUTER JOIN CompUser t6 ON t5.id = t6.ADD_ID WHERE (NOT (EXISTS ("
-            + "SELECT t4.id FROM CR_ODR t3, CR_ODR t4 WHERE (t2.id = t4.id AND t3.id = t4.id)
"
-            + "AND (t0.id = t3.CUSTOMER_ID))))";
+            + "LEFT OUTER JOIN CR_ADDR t4 ON t0.ADDRESS_ID = t4.id "
+            + "LEFT OUTER JOIN CompUser t5 ON t4.id = t5.ADD_ID WHERE (NOT (EXISTS ("
+            + "SELECT t3.id FROM CR_ODR t2, CR_ODR t3 WHERE (t1.id = t3.id AND t2.id = t3.id)
"
+            + "AND (t0.id = t2.CUSTOMER_ID))))";
 
         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=923589&r1=923588&r2=923589&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
Tue Mar 16 06:11:18 2010
@@ -1085,9 +1085,8 @@ public class TestTypesafeCriteria extend
     public void testValues1() {
         String sql = "SELECT t0.name, t2.id, t2.label FROM CR_ITEM t0 "
             + "INNER JOIN CR_ITEM_photos t1 ON t0.id = t1.ITEM_ID "
-            + "INNER JOIN CR_ITEM_photos t3 ON t0.id = t3.ITEM_ID "
-            + "INNER JOIN CR_PHT t2 ON t1.VALUE_ID = t2.id WHERE " + 
-            "((t3.VALUE_ID = ? OR t3.VALUE_ID = ? OR t3.VALUE_ID = ? OR t3.VALUE_ID = ? OR
t3.VALUE_ID = ?) "
+            + "INNER JOIN CR_PHT t2 ON t1.VALUE_ID = t2.id WHERE " +
+            "((t1.VALUE_ID = ? OR t1.VALUE_ID = ? OR t1.VALUE_ID = ? OR t1.VALUE_ID = ? OR
t1.VALUE_ID = ?) "
             + "AND 0 < (SELECT COUNT(*) FROM CR_ITEM_photos WHERE CR_ITEM_photos.ITEM_ID
= t0.id))";
 
         CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
@@ -1167,10 +1166,9 @@ public class TestTypesafeCriteria extend
             + "INNER JOIN CR_PHT t2 ON t1.VALUE_ID = t2.id WHERE "
             + "(0 = (SELECT COUNT(*) FROM CR_ITEM_photos t3 WHERE "
             + "(t3.VALUE_ID = ? OR t3.VALUE_ID = ? OR t3.VALUE_ID = ? OR t3.VALUE_ID = ?
OR t3.VALUE_ID = ?) "
-            + "AND (t0.id = t3.ITEM_ID) AND t0.id = t3.ITEM_ID) "
+            + "AND t0.id = t1.ITEM_ID) "
             + "AND 0 < (SELECT COUNT(*) FROM CR_ITEM_photos WHERE CR_ITEM_photos.ITEM_ID
= t0.id))";
         
-        
         CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
         Root<Item> item = q.from(Item.class);
         MapJoin<Item, String, Photo> photo = item.join(Item_.photos);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java?rev=923589&r1=923588&r2=923589&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java
Tue Mar 16 06:11:18 2010
@@ -65,6 +65,44 @@ public class TestSpec10_1_26 extends SQL
         rsAllDepartment3 = getAll(Department3.class);
     }
 
+    public void testHavingClauseWithEntityExpression() throws Exception {
+        EntityManager em = emf.createEntityManager();
+        Employee1 e1 = em.find(Employee1.class, 1);
+        em.clear();
+        String query = "select e from Department1 d, " +
+            " in (d.empMap) e " +
+            "group by e " +
+            "having e = ?1"; 
+        Query q = em.createQuery(query); 
+        q.setParameter(1, e1);
+        List<Employee1> rs = (List<Employee1>) q.getResultList();
+        Employee1 e2 = rs.get(0);
+        assertEquals(e1.getEmpId(), e2.getEmpId());
+
+        em.clear();
+        query = "select e from Department1 d, " +
+            " in (d.empMap) e " +
+            "group by e " +
+            "having e <> ?1"; 
+        q = em.createQuery(query); 
+        q.setParameter(1, e1);
+        rs = (List<Employee1>) q.getResultList();
+        Employee1 e3 = rs.get(0);
+        assertNotEquals(e1.getEmpId(), e3.getEmpId());
+
+        em.clear();
+        query = "select value(e) from Department1 d, " +
+            " in (d.empMap) e " +
+            "group by value(e) " +
+            "having value(e) = ?1"; 
+        q = em.createQuery(query); 
+        q.setParameter(1, e1);
+        rs = (List<Employee1>) q.getResultList();
+        Employee1 e4 = rs.get(0);
+        assertEquals(e1.getEmpId(), e4.getEmpId());
+        em.close();
+    }
+
     @AllowFailure
     public void testQueryInMemoryQualifiedId() throws Exception {
         queryQualifiedId(true);



Mime
View raw message