openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r781621 [1/3] - 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/src/main/java/org/apache/openjpa/persiste...
Date Wed, 03 Jun 2009 23:44:59 GMT
Author: faywang
Date: Wed Jun  3 23:44:58 2009
New Revision: 781621

URL: http://svn.apache.org/viewvc?rev=781621&view=rev
Log:
OPENJPA-1013: subquery support

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java   (with props)
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpressionBuilder.java   (with props)
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java   (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?rev=781621&r1=781620&r2=781621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java Wed Jun  3 23:44:58 2009
@@ -439,14 +439,16 @@
         if (val instanceof Lit) {
             Lit lit = (Lit) val;
             StringBuffer value = new StringBuffer();
-            if (lit.getParseType() == Literal.TYPE_SQ_STRING)
+            int pType = lit.getParseType(); 
+            if (pType == Literal.TYPE_SQ_STRING ||
+                pType == Literal.TYPE_STRING)
                 value.append("'").append(lit.getValue().toString()).append("'");
-            else if (lit.getParseType() == Literal.TYPE_BOOLEAN) {
+            else if (pType == Literal.TYPE_BOOLEAN) {
                 if ((Boolean) lit.getValue())
                     value.append("1");
                 else
                     value.append("0");
-            } else if (lit.getParseType() == Literal.TYPE_ENUM) {
+            } else if (pType == Literal.TYPE_ENUM) {
                 lit.setRaw(true);
                 return val;
             } else

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java?rev=781621&r1=781620&r2=781621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/Address.java Wed Jun  3 23:44:58 2009
@@ -25,6 +25,7 @@
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 
+
 /**
  * Used for testing Criteria API.
  * The fields are sometimes not declared as there is no validation yet during 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java?rev=781621&r1=781620&r2=781621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerDetails.java Wed Jun  3 23:44:58 2009
@@ -19,11 +19,24 @@
 package org.apache.openjpa.persistence.criteria;
 
 public class CustomerDetails {
-    int id;
+    long id;
     
     int status;
     
     int quantity;
+
+    public CustomerDetails() {}
+    
+    public CustomerDetails(long id, int status) {
+        this.id = id;
+        this.status = status;
+    }
+    
+    public CustomerDetails(long id, int status, int quantity) {
+        this.id = id;
+        this.status = status;
+        this.quantity = quantity;
+    }
     
     public int getStatus() {
         return status;
@@ -33,11 +46,11 @@
         this.status = status;
     }
     
-    public int getId() {
+    public long getId() {
         return id;
     }
     
-    public void setId(int id) {
+    public void setId(long id) {
         this.id = id;
     }
     

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java?rev=781621&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java Wed Jun  3 23:44:58 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.criteria;
+
+public class CustomerFullName {
+    public String firstName;
+    
+    public String lastName;
+    
+    public CustomerFullName() {}
+    
+    public CustomerFullName(String firstName, String lastName) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+    }
+    
+    public String getLastName() {
+        return lastName;
+    }
+    
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+    
+    public String getFirstName() {
+        return firstName;
+    }
+    
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+}
+

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CustomerFullName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java?rev=781621&r1=781620&r2=781621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java Wed Jun  3 23:44:58 2009
@@ -266,7 +266,6 @@
         em.clear();
     }
 
-    @AllowFailure(message="JPQL generates two queries, Criteria only one")
     public void testNullExprUsingCriteria() {
         String query =
             "SELECT o.name FROM CompUser o WHERE o.age IS NOT NULL AND " +
@@ -289,7 +288,6 @@
         em.clear();
     }
     
-    @AllowFailure(message="Invalid SQL for Criteria")
     public void testNullExpr2UsingCriteria() {
         String query =
             "SELECT o.name FROM CompUser o WHERE o.address.country IS NULL";
@@ -407,12 +405,10 @@
         em.clear();
     }
     
-    @AllowFailure(message="new() in projection is badly broken")
     public void testConstructorExprUsingCriteria() {
         String query =
             "SELECT NEW org.apache.openjpa.persistence.common.apps.MaleUser(" +
-            "c.name, " + 
-            "c.computerName, c.address, c.age, c.userid)" +
+            "c.name, c.computerName, c.address, c.age, c.userid)" +
             " FROM CompUser c WHERE c.name = 'Seetha'";
         CriteriaQuery q = cb.create();
         q = cb.create();
@@ -433,11 +429,10 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testConcatSubStringFunc1() {
         String query = "select " +
             "CONCAT('Ablahum', SUBSTRING(e.name, LOCATE('e', e.name), 4)) " +
-            "From CompUer e WHERE e.name='Seetha'";
+            "From CompUser e WHERE e.name='Seetha'";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
@@ -455,30 +450,29 @@
         em.clear();
     }
     
-    @AllowFailure
     public void testConcatSubStringFunc2() {
         String query = "select e.address From CompUser e where " +
-        		"e.computerName = " +
+            "e.name = 'Seetha' AND e.computerName = " +
             "CONCAT('Ablahum', SUBSTRING(e.name, LOCATE('e', e.name), 4)) ";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(e.get(CompUser_.address));
-        q.where(cb.equal(
-            e.get(CompUser_.computerName),
-            cb.concat("Ablahum", 
-                cb.substring(
-                    e.get(CompUser_.name), 
-                    cb.locate(e.get(CompUser_.name), "e"), 
-                    cb.literal(4)
-                 )
-            ))
-         );
+        q.where(cb.and(cb.equal(e.get(CompUser_.name), "Seetha"),
+                cb.equal(
+                e.get(CompUser_.computerName),
+                cb.concat("Ablahum", 
+                    cb.substring(
+                        e.get(CompUser_.name), 
+                        cb.locate(e.get(CompUser_.name), "e"), 
+                        cb.literal(4)
+                     )
+                )))
+             );
         assertEquivalence(q, query);
         em.clear();
     }
 
-    @AllowFailure
     public void testConcatSubStringFunc3() {
         String query = "select " +
             "CONCAT('XYZ', SUBSTRING(e.name, LOCATE('e', e.name))) " +
@@ -499,31 +493,31 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testConcatSubStringFunc4() {
-        String query = "select e.nicknames from CompUser e where e.name = " +
+        String query = "select e.age from CompUser e where " + 
+            "e.name = 'Seetha' AND e.computerName = " +
             "CONCAT('XYZ', SUBSTRING(e.name, LOCATE('e', e.name))) ";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
-        q.select(e.get(CompUser_.nicknames));
-        q.where(cb.equal(
-            e.get(CompUser_.name),
-            cb.concat("XYZ", 
-                cb.substring(
-                    e.get(CompUser_.name), 
-                    cb.locate(e.get(CompUser_.name), "e") 
-                )
-            ))
-        );
+        q.select(e.get(CompUser_.age));
+        q.where(cb.and(cb.equal(e.get(CompUser_.name), "Seetha"),
+                cb.equal(
+                e.get(CompUser_.computerName),
+                cb.concat("XYZ", 
+                    cb.substring(
+                        e.get(CompUser_.name), 
+                        cb.locate(e.get(CompUser_.name), "e") 
+                    )
+                )))
+            );
         assertEquivalence(q, query);
         em.clear();
     }
 
-    @AllowFailure
     public void testConcatFunc() {
         String query = "select " +
-            "CONCAT('', '') From CompUser WHERE e.name='Seetha'";
+            "CONCAT('', '') From CompUser e WHERE e.name='Seetha'";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
@@ -533,7 +527,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTrimFunc1() {
         String query = "select Trim(e.computerName) From CompUser e " +
         		"WHERE e.name='Shannon '";
@@ -546,20 +539,18 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTrimFunc2() {
-        String query = "select e.name From CompUser e where Trim(e.name) =" +
-        		"'Shannon'";
+        String query = "select e.computerName From CompUser e where " + 
+            "Trim(e.name) = 'Shannon '";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
-        q.where(cb.equal(cb.trim(e.get(CompUser_.computerName)), "Shannon"));
-        q.select(e.get(CompUser_.name));
+        q.where(cb.equal(cb.trim(e.get(CompUser_.name)), "Shannon"));
+        q.select(e.get(CompUser_.computerName));
         assertEquivalence(q, query);
         em.clear();
     }
 
-    @AllowFailure
     public void testLowerFunc1() {
         String query = "select LOWER(e.name) From CompUser e WHERE " +
         		"e.computerName='UNIX'";
@@ -572,7 +563,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testLowerFunc2() {
         String query = "select e.age From CompUser e where LOWER(e.name)" +
         		" ='ugo'";
@@ -585,7 +575,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testUpperFunc1() {
         String query = "select UPPER(e.name) From CompUser e WHERE " +
         		"e.computerName='PC'";
@@ -598,33 +587,31 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testUpperFunc2() {
-        String query = "select e.nicknames from CompUser e where " +
-        		"UPPER(e.name)='UGO'";
+        String query = "select e.age from CompUser e where " +
+            "UPPER(e.name)='UGO'";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.where(cb.equal(cb.upper(e.get(CompUser_.name)), "UGO"));
-        q.select(e.get(CompUser_.nicknames));
+        q.select(e.get(CompUser_.age));
         assertEquivalence(q, query);
         em.clear();
     }
 
-    @AllowFailure
     public void testLengthFunc() {
         String query = "SELECT o.name FROM CompUser o " + 
             "WHERE LENGTH(o.address.country) = 3";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
-        q.where(cb.equal(cb.length(e.get(CompUser_.name)), 3));
+        q.where(cb.equal(cb.length(e.get(CompUser_.address).
+            get(Address_.country)), 3));
         q.select(e.get(CompUser_.name));
         assertEquivalence(q, query);
         em.clear();
     }
 
-    @AllowFailure
     public void testArithmFunc1() {
         String query =
             "select ABS(e.age) From CompUser e WHERE e.name='Seetha'";
@@ -637,7 +624,6 @@
         em.clear();
     }
     
-    @AllowFailure
     public void testArithmFunc2() {
         String query =
             "select SQRT(e.age) From CompUser e WHERE e.name='Seetha'";
@@ -677,7 +663,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testGroupByHavingClause() {
         String query =
             "SELECT c.name FROM CompUser c GROUP BY c.name HAVING c.name " +
@@ -690,18 +675,9 @@
         q.having(cb.like(e.get(CompUser_.name), "S%"));
         q.select(e.get(CompUser_.name));
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(3, result.size());
-        assertTrue(result.contains("Shannon "));
-        assertTrue(result.contains("Shade"));
-        assertTrue(result.contains("Seetha"));
-
         em.clear();
     }
 
-    @AllowFailure
     public void testOrderByClause() {
         String query =
             "SELECT c.name FROM CompUser c WHERE c.name LIKE 'S%' " +
@@ -714,18 +690,9 @@
         q.select(e.get(CompUser_.name));
         q.orderBy(cb.asc(e.get(CompUser_.name)));
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(3, result.size());
-        assertTrue(result.contains("Shannon "));
-        assertTrue(result.contains("Seetha"));
-        assertTrue(result.contains("Shade"));
-
         em.clear();
     }
 
-    @AllowFailure
     public void testAVGAggregFunc() {
         //To be Tested: AVG, COUNT, MAX, MIN, SUM
         String query = "SELECT AVG(e.age) FROM CompUser e";
@@ -734,16 +701,9 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.avg(e.get(CompUser_.age)));
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        assertTrue(result.contains(25));
-
         em.clear();
     }
 
-    @AllowFailure
     public void testCOUNTAggregFunc() {
         String query = "SELECT COUNT(c.name) FROM CompUser c";
 
@@ -752,16 +712,9 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.count(e.get(CompUser_.name)));
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        assertTrue(result.contains(6l));
-
         em.clear();
     }
 
-    @AllowFailure
     public void testMAXAggregFunc() {
         String query = "SELECT DISTINCT MAX(c.age) FROM CompUser c";
 
@@ -770,16 +723,10 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.max(e.get(CompUser_.age))).distinct(true);
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        assertTrue(result.contains(36));
-
         em.clear();
     }
 
-    @AllowFailure
+    @AllowFailure(message="criteria does not generate Optimize for 1 row")
     public void testMINAggregFunc() {
         String query = "SELECT DISTINCT MIN(c.age) FROM CompUser c";
 
@@ -788,16 +735,9 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.min(e.get(CompUser_.age))).distinct(true);
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        assertTrue(result.contains(10));
-
         em.clear();
     }
 
-    @AllowFailure
     public void testSUMAggregFunc() {
         String query = "SELECT SUM(c.age) FROM CompUser c";
 
@@ -806,12 +746,6 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.sum(e.get(CompUser_.age)));
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        assertTrue(result.contains(153l));
-
         em.clear();
     }
 
@@ -819,7 +753,7 @@
     @AllowFailure
     public void testTypeExpression1() {
         String query = "SELECT e FROM CompUser e where TYPE(e) in (?1, ?2) " +
-        		"ORDER By e.name";
+            "ORDER By e.name";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
@@ -861,7 +795,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTypeExpression4() {
         String query = "SELECT e FROM CompUser e where TYPE(e) = MaleUser";
         CriteriaQuery q = cb.create();
@@ -873,7 +806,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTypeExpression5() {
         String query = "SELECT e FROM CompUser e where TYPE(e) in (MaleUser)";
         CriteriaQuery q = cb.create();
@@ -885,10 +817,9 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTypeExpression6() {
         String query = "SELECT e FROM CompUser e where TYPE(e) not in " +
-        		"(MaleUser, FemaleUser)";
+            "(MaleUser, FemaleUser)";
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
@@ -910,7 +841,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTypeExpression8() {
         String query = "SELECT MaleUser FROM Address a";
         CriteriaQuery q = cb.create();
@@ -921,7 +851,6 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testTypeExpression9() {
         String query = "SELECT "
                 + " CASE TYPE(e) WHEN FemaleUser THEN 'Female' "
@@ -935,10 +864,8 @@
         em.clear();
     }
 
-    @AllowFailure
     public void testCoalesceExpressions() {
-        startTx(em);
-        String query = "SELECT e.name, "
+         String query = "SELECT e.name, "
                 + "COALESCE (e.address.country, 'Unknown')"
                 + " FROM CompUser e ORDER BY e.name DESC";
 
@@ -949,18 +876,10 @@
                 .value("Unknown"));
         q.orderBy(cb.desc(e.get(CompUser_.name)));
         assertEquivalence(q, query);
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(rs.size() - 1);
-        assertEquals("the name is not famzy", "Famzy", result[0]);
-        assertEquals("Unknown", result[1]);
-
-        endTx(em);
         em.clear();
     }
 
-    @AllowFailure
     public void testNullIfExpressions() {
-        startTx(em);
         String query = "SELECT e.name, NULLIF (e.address.country, 'USA')"
                 + " FROM CompUser e ORDER BY e.name DESC";
         CriteriaQuery q = cb.create();
@@ -969,22 +888,14 @@
                 Address_.country), "USA"));
         q.orderBy(cb.desc(e.get(CompUser_.name)));
         assertEquivalence(q, query);
-
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(1);
-        assertEquals("the name is not shannon ", "Shannon ", result[0]);
-        assertNull("is not null", result[1]);
-
-        endTx(em);
         em.clear();
     }
 
-    @AllowFailure
     public void testSimpleCaseExpression1() {
-        String query = "SELECT e.name, e.age+1 as cage, "
+        String query = "SELECT e.name, e.age+1, "
                 + "CASE e.address.country WHEN 'USA' THEN 'us' "
-                + " ELSE 'non-us' END as d2, e.address.country "
-                + " FROM CompUser e ORDER BY cage, d2 DESC";
+                + " ELSE 'non-us' END, e.address.country "
+                + " FROM CompUser e";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         Expression<Integer> cage = cb.sum(e.get(CompUser_.age), 1);
@@ -993,21 +904,15 @@
                 "us").otherwise("non-us");
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
-        q.orderBy(cb.asc(cage), cb.desc(d2));
         assertEquivalence(q, query);
-
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(rs.size() - 1);
-        assertEquals("the name is not seetha", "Seetha", result[0]);
     }
 
-    @AllowFailure
     public void testSimpleCaseExpression2() {
-        String query = "SELECT e.name, e.age+1 as cage, "
+        String query = "SELECT e.name, e.age+1, "
                 + "CASE e.address.country WHEN 'USA'"
                 + " THEN 'United-States' "
-                + " ELSE e.address.country  END as d2," + " e.address.country "
-                + " FROM CompUser e ORDER BY cage, d2 DESC";
+                + " ELSE e.address.country  END," + " e.address.country "
+                + " FROM CompUser e";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         Expression cage = cb.sum(e.get(CompUser_.age), 1);
@@ -1017,42 +922,29 @@
                 e.get(CompUser_.address).get(Address_.country));
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
-        q.orderBy(cb.asc(cage), cb.desc(d2));
         assertEquivalence(q, query);
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(rs.size() - 1);
-        assertEquals("the name is not seetha", "Seetha", result[0]);
     }
 
-    @AllowFailure
     public void testSimpleCaseExpression3() {
         String query = "SELECT e.name, "
                 + " CASE TYPE(e) WHEN FemaleUser THEN 'Female' "
-                + " ELSE 'Male' END as result"
+                + " ELSE 'Male' END"
                 + " FROM CompUser e WHERE e.name like 'S%' "
                 + " ORDER BY e.name DESC";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
-        q.select(cb.selectCase(e.type()).when(FemaleUser.class, "Female")
-                .otherwise("Male"));
+        q.select(e.get(CompUser_.name), 
+            cb.selectCase(e.type()).when(FemaleUser.class, "Female")
+            .otherwise("Male"));
         q.where(cb.like(e.get(CompUser_.name), "S%"));
-        q.orderBy(cb.asc(e.get(CompUser_.name)));
+        q.orderBy(cb.desc(e.get(CompUser_.name)));
         assertEquivalence(q, query);
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(0);
-        assertEquals("the result is not female", "Female", result[1]);
-        assertEquals("the name is not shannon", "Shannon ", result[0]);
-        result = (Object[]) rs.get(2);
-        assertEquals("the result is not male", "Male", result[1]);
-        assertEquals("the name is not seetha", "Seetha", result[0]);
     }
 
-    @AllowFailure
     public void testSimpleCaseExpression4() {
-        // boolean literal in case expression
         String query = "SELECT e.name, CASE e.address.country WHEN 'USA'"
-                + " THEN true ELSE false  END as b,"
-                + " e.address.country FROM CompUser e order by b";
+                + " THEN true ELSE false END,"
+                + " e.address.country FROM CompUser e";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         Expression b = cb.selectCase(
@@ -1060,21 +952,14 @@
                 true).otherwise(false);
         q.select(e.get(CompUser_.name), b, e.get(CompUser_.address).get(
                 Address_.country));
-        q.where(cb.like(e.get(CompUser_.name), "S%"));
-        q.orderBy(cb.asc(b));
         assertEquivalence(q, query);
-        List rs = em.createQuery(q).getResultList();
-
-        Object[] result = (Object[]) rs.get(rs.size() - 1);
-        assertEquals(result[1], 1);
     }
 
-    @AllowFailure
     public void testGeneralCaseExpression1() {
         String query = "SELECT e.name, e.age, "
                 + " CASE WHEN e.age > 30 THEN e.age - 1 "
                 + " WHEN e.age < 15 THEN e.age + 1 ELSE e.age + 0 "
-                + " END AS cage FROM CompUser e ORDER BY cage";
+                + " END FROM CompUser e";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         Expression cage = cb.selectCase().when(cb.gt(e.get(CompUser_.age), 30),
@@ -1083,18 +968,16 @@
                 cb.sum(e.get(CompUser_.age), 1)).otherwise(
                 cb.sum(e.get(CompUser_.age), 0));
         q.select(e.get(CompUser_.name), e.get(CompUser_.age), cage);
-        q.orderBy(cb.asc(cage));
         assertEquivalence(q, query);
     }
 
-    @AllowFailure
     public void testGeneralCaseExpression2() {
-        String query = "SELECT e.name, e.age+1 as cage, "
+        String query = "SELECT e.name, e.age+1, "
                 + "CASE WHEN e.address.country = 'USA' "
                 + " THEN 'United-States' "
-                + " ELSE 'Non United-States'  END as d2,"
+                + " ELSE 'Non United-States'  END,"
                 + " e.address.country "
-                + " FROM CompUser e ORDER BY cage, d2 DESC";
+                + " FROM CompUser e";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         Expression d2 = cb.selectCase()
@@ -1106,29 +989,21 @@
         Expression cage = cb.sum(e.get(CompUser_.age), 1);
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
-        q.orderBy(cb.asc(cage), cb.desc(d2));
         assertEquivalence(q, query);
-
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(rs.size() - 1);
-        assertEquals("the name is not seetha", "Seetha", result[0]);
-        assertEquals("the country is not 'Non United-States'",
-                "Non United-States", result[2]);
     }
 
-    @AllowFailure
     public void testGeneralCaseExpression3() {
         String query = " select e.name, "
-                + "CASE WHEN e.age = 11 THEN "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.POOR"
-                + " WHEN e.age = 35 THEN "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.GOOD"
-                + " ELSE "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.EXCELLENT"
-                + " END FROM CompUser e ORDER BY e.age";
+            + "CASE WHEN e.age = 11 THEN "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.POOR"
+            + " WHEN e.age = 35 THEN "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.GOOD"
+            + " ELSE "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.EXCELLENT"
+            + " END FROM CompUser e ORDER BY e.age";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(e.get(CompUser_.name), cb.selectCase().when(
@@ -1139,10 +1014,6 @@
 
         q.orderBy(cb.asc(e.get(CompUser_.age)));
         assertEquivalence(q, query);
-        List rs = em.createQuery(q).getResultList();
-        Object[] result = (Object[]) rs.get(0);
-        assertEquals("the name is not Jacob", "Jacob", result[0]);
-        assertEquals("the credit rating is not 'POOR'", "POOR", result[1]);
     }
 
     // not sure how to write CriteriaQuery for
@@ -1150,19 +1021,19 @@
     @AllowFailure
     public void testGeneralCaseExpression4() {
         String query = "select e.name, e.creditRating from CompUser e "
-                + "where e.creditRating = "
-                + "(select "
-                + "CASE WHEN e1.age = 11 THEN "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.POOR"
-                + " WHEN e1.age = 35 THEN "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.GOOD"
-                + " ELSE "
-                + "org.apache.openjpa.persistence.criteria.CompUser$" +
-                		"CreditRating.EXCELLENT"
-                + " END from CompUser e1"
-                + " where e.userid = e1.userid) ORDER BY e.age";
+            + "where e.creditRating = "
+            + "(select "
+            + "CASE WHEN e1.age = 11 THEN "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.POOR"
+            + " WHEN e1.age = 35 THEN "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.GOOD"
+            + " ELSE "
+            + "org.apache.openjpa.persistence.criteria.CompUser$" 
+            + "CreditRating.EXCELLENT"
+            + " END from CompUser e1"
+            + " where e.userid = e1.userid) ORDER BY e.age";
         CriteriaQuery q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(e.get(CompUser_.name), e.get(CompUser_.creditRating));

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=781621&r1=781620&r2=781621&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 Jun  3 23:44:58 2009
@@ -116,7 +116,7 @@
         CriteriaQuery c = cb.create();
         Root<Account> account = c.from(Account.class);
         c.where(cb.in(account.get(Account_.name)).value("X").value("Y").value(
-                "Z"));
+        "Z"));
         assertEquivalence(c, jpql);
     }
 
@@ -186,26 +186,26 @@
     @AllowFailure(message = "Extra joins created in Criteria")
     public void testMultiLevelJoins() {
         String jpql = "SELECT c FROM Customer c JOIN c.orders o "
-                + "JOIN o.lineItems i WHERE i.product.productType = 'printer'";
+            + "JOIN o.lineItems i WHERE i.product.productType = 'printer'";
 
         CriteriaQuery c = cb.create();
         Root<Customer> cust = c.from(Customer.class);
         Join<Customer, Order> order = cust.join(Customer_.orders);
         Join<Order, LineItem> item = order.join(Order_.lineItems);
         c.select(cust.get(Customer_.name))
-            .where(cb.equal(item.get(LineItem_.product).
-            get(Product_.productType), "printer"));
-        
+            .where(cb.equal(item.get(LineItem_.product)
+            .get(Product_.productType), "printer"));
+
         assertEquivalence(c, jpql);
     }
 
     public void testJoinsNotPresentInWhereClause() {
         String jpql = "SELECT c FROM Customer c LEFT JOIN c.orders o "
-                + "WHERE c.status = 1";
+            + "WHERE c.status = 1";
         CriteriaQuery c = cb.create();
         Root<Customer> cust = c.from(Customer.class);
         Join<Customer, Order> order = cust
-                .join(Customer_.orders, JoinType.LEFT);
+        .join(Customer_.orders, JoinType.LEFT);
         c.where(cb.equal(cust.get(Customer_.status), 1)).select(cust);
 
         assertEquivalence(c, jpql);
@@ -214,7 +214,7 @@
     @AllowFailure(message = "Fetch joins not implemented")
     public void testFetchJoins() {
         String jpql = "SELECT d FROM Department LEFT JOIN FETCH d.employees "
-                + "WHERE d.deptNo = 1";
+            + "WHERE d.deptNo = 1";
         CriteriaQuery q = cb.create();
         Root<Department> d = q.from(Department.class);
         d.fetch(Department_.employees, JoinType.LEFT);
@@ -226,8 +226,8 @@
     @AllowFailure(message = "Invalid SQL is generated")
     public void testJoinedPathInProjection() {
         String jpql = "SELECT p.vendor FROM Employee e JOIN "
-                + "e.contactInfo.phones p "
-                + "WHERE e.contactInfo.address.zipCode = '95054'";
+            + "e.contactInfo.phones p "
+            + "WHERE e.contactInfo.address.zipCode = '95054'";
         CriteriaQuery q = cb.create();
         Root<Employee> emp = q.from(Employee.class);
         Join<Contact, Phone> phone = emp.join(Employee_.contactInfo).join(
@@ -243,7 +243,7 @@
     public void testKeyExpression() {
         String jpql =
             "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) "
-                + "LIKE '%egret%'";
+            + "LIKE '%egret%'";
         CriteriaQuery q = cb.create();
         Root<Item> item = q.from(Item.class);
         MapJoin<Item, String, Photo> photo = item.join(Item_.photos);
@@ -256,12 +256,12 @@
     @AllowFailure(message = "Index expression not implemented")
     public void testIndexExpression() {
         String jpql = "SELECT t FROM CreditCard c JOIN c.transactionHistory t "
-                + "WHERE c.customer.accountNum = 321987 AND INDEX(t) BETWEEN 0 "
-                + "AND 9";
+            + "WHERE c.customer.accountNum = 321987 AND INDEX(t) BETWEEN 0 "
+            + "AND 9";
         CriteriaQuery q = cb.create();
         Root<CreditCard> c = q.from(CreditCard.class);
         ListJoin<CreditCard, TransactionHistory> t = c
-                .join(CreditCard_.transactionHistory);
+        .join(CreditCard_.transactionHistory);
         q.select(t).where(
                 cb.equal(c.get(CreditCard_.customer).get(Customer_.accountNum),
                         321987), cb.between(t.index(), 0, 9));
@@ -278,65 +278,64 @@
         assertEquivalence(q, jpql);
     }
 
-//    @AllowFailure(message = "broken")
-//    public void testExpressionInProjection() {
-//        String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, "
-//                + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a"
-//                + "WHERE a.state = 'CA' AND a.county = 'Santa Clara'";
-//        CriteriaQuery q = cb.create();
-//        Root<Customer> cust = q.from(Customer.class);
-//        Join<Customer, Order> order = cust.join(Customer_.orders);
-//        Join<Customer, Address> address = cust.join(Customer_.address);
-//        q.where(cb.equal(address.get(Address_.state), "CA"), cb.equal(address
-//                .get(Address_.county), "Santa Clara"));
-//        q.select(order.get(Order_.quantity), cb.prod(order
-//                .get(Order_.totalCost), 1.08), address.get(Address_.zipCode));
-//
-//        assertEquivalence(q, jpql);
-//    }
-
-    // @AllowFailure(message =
-    // "Type expression was working with Fay. Now refactored and broken")
-    // public void testTypeExpression() {
-    // String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
-    // CriteriaQuery q = cb.create();
-    // Root<Employee> emp = q.from(Employee.class);
-    // q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-
-    // @AllowFailure(message = "Index expression not implemented")
-    // public void testIndexExpressionAndLietral() {
-    // String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
-    // + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
-    // CriteriaQuery q = cb.create();
-    // Root<Course> course = q.from(Course.class);
-    // ListJoin<Course, Student> w = course.join(Course_.studentWaitList);
-    // q.where(cb.equal(course.get(Course_.name), "Calculus"),
-    // cb.equal(w.index(), 0)).select(w.get(Student_.name));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-
-    // @AllowFailure(message = "SQL for Criteria has extra join")
-    // public void testAggregateInProjection() {
-    // String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
-    // + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
-    // CriteriaQuery q = cb.create();
-    // Root<Order> o = q.from(Order.class);
-    // Join<Order, LineItem> i = o.join(Order_.lineItems);
-    // Join<Order, Customer> c = o.join(Order_.customer);
-    // q.where(cb.equal(c.get(Customer_.lastName), "Smith"), cb.equal(c
-    // .get(Customer_.firstName), "John"));
-    // q.select(cb.sum(i.get(LineItem_.price)));
-    //
-    // assertEquivalence(q, jpql);
-    // }
+    @AllowFailure(message = "broken")
+    public void testExpressionInProjection() {
+        String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, "
+            + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a"
+            + "WHERE a.state = 'CA' AND a.county = 'Santa Clara'";
+        CriteriaQuery q = cb.create();
+        Root<Customer> cust = q.from(Customer.class);
+        Join<Customer, Order> order = cust.join(Customer_.orders);
+        Join<Customer, Address> address = cust.join(Customer_.address);
+        q.where(cb.equal(address.get(Address_.state), "CA"), cb.equal(address
+                .get(Address_.county), "Santa Clara"));
+        q.select(order.get(Order_.quantity), cb.prod(order
+                .get(Order_.totalCost), 1.08), address.get(Address_.zipCode));
+
+        assertEquivalence(q, jpql);
+    }
+
+    public void testTypeExpression() {
+        String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
+        CriteriaQuery q = cb.create();
+        Root<Employee> emp = q.from(Employee.class);
+        q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message = "Index expression not implemented")
+    public void testIndexExpressionAndLietral() {
+        String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
+            + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
+        CriteriaQuery q = cb.create();
+        Root<Course> course = q.from(Course.class);
+        ListJoin<Course, Student> w = course.join(Course_.studentWaitList);
+        q.where(cb.equal(course.get(Course_.name), "Calculus"),
+                cb.equal(w.index(), 0)).select(w.get(Student_.name));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message = "SQL for Criteria has extra join")
+    public void testAggregateInProjection() {
+        String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i " + 
+            "JOIN o.customer c WHERE c.lastName = 'Smith' AND " + 
+            "c.firstName = 'John'";
+        CriteriaQuery q = cb.create();
+        Root<Order> o = q.from(Order.class);
+        Join<Order, LineItem> i = o.join(Order_.lineItems);
+        Join<Order, Customer> c = o.join(Order_.customer);
+        q.where(cb.equal(c.get(Customer_.lastName), "Smith"), cb.equal(c
+                .get(Customer_.firstName), "John"));
+        q.select(cb.sum(i.get(LineItem_.price)));
+
+        assertEquivalence(q, jpql);
+    }
 
     public void testSizeExpression() {
         String jpql = "SELECT SIZE(d.employees) FROM Department d "
-                + "WHERE d.name = 'Sales'";
+            + "WHERE d.name = 'Sales'";
         CriteriaQuery q = cb.create();
         Root<Department> d = q.from(Department.class);
         q.where(cb.equal(d.get(Department_.name), "Sales"));
@@ -348,134 +347,114 @@
     public void testCaseExpression() {
         String jpql =
             "SELECT e.name, CASE WHEN e.rating = 1 THEN e.salary * 1.1 "
-                + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * "
-                + "1.01 END "
-                + "FROM Employee e WHERE e.department.name = 'Engineering'";
+            + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * "
+            + "1.01 END "
+            + "FROM Employee e WHERE e.department.name = 'Engineering'";
         CriteriaQuery q = cb.create();
         Root<Employee> e = q.from(Employee.class);
         q.where(cb.equal(e.get(Employee_.department).get(Department_.name),
-                "Engineering"));
+        "Engineering"));
         q.select(e.get(Employee_.name), cb.selectCase().when(
                 cb.equal(e.get(Employee_.rating), 1),
                 cb.prod(e.get(Employee_.salary), 1.1)).when(
-                cb.equal(e.get(Employee_.rating), 2),
-                cb.prod(e.get(Employee_.salary), 1.2)).otherwise(
-                cb.prod(e.get(Employee_.salary), 1.01)));
+                        cb.equal(e.get(Employee_.rating), 2),
+                        cb.prod(e.get(Employee_.salary), 1.2)).otherwise(
+                                cb.prod(e.get(Employee_.salary), 1.01)));
 
         assertEquivalence(q, jpql);
     }
 
-    // @AllowFailure(message = "Extra Joins created")
-    // public void testExpression1() {
-    // String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, "
-    // + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a "
-    // + "WHERE a.state = 'CA' AND a.county = 'Santa Clara'";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> cust = q.from(Customer.class);
-    // Join<Customer, Order> order = cust.join(Customer_.orders);
-    // Join<Customer, Address> address = cust.join(Customer_.address);
-    // q.where(cb.equal(address.get(Address_.state), "CA"), cb.equal(address
-    // .get(Address_.county), "Santa Clara"));
-    // q.select(order.get(Order_.quantity), cb.prod(order
-    // .get(Order_.totalCost), 1.08), address.get(Address_.zipCode));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message = "Type expression in projection not implemented")
-    // public void testExpression2() {
-    // String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
-    // CriteriaQuery q = cb.create();
-    // Root<Employee> emp = q.from(Employee.class);
-    // q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message = "Index expression not implemented")
-    // public void testExpression3() {
-    // String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
-    // + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
-    // CriteriaQuery q = cb.create();
-    // Root<Course> course = q.from(Course.class);
-    // ListJoin<Course, Student> w = course.join(Course_.studentWaitList);
-    // q.where(cb.equal(course.get(Course_.name), "Calculus"),
-    // cb.equal(w.index(), 0)).select(w.get(Student_.name));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message = "Generates extra Join")
-    // public void testExpression4() {
-    // String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN "
-    // + "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
-    // CriteriaQuery q = cb.create();
-    // Root<Order> o = q.from(Order.class);
-    // Join<Order, LineItem> i = o.join(Order_.lineItems);
-    // Join<Order, Customer> c = o.join(Order_.customer);
-    // q.where(cb.equal(c.get(Customer_.lastName), "Smith"), cb.equal(c
-    // .get(Customer_.firstName), "John"));
-    // q.select(cb.sum(i.get(LineItem_.price)));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-
-    public void testExpression5() {
-        String jpql = "SELECT SIZE(d.employees) FROM Department d "
-                + "WHERE d.name = 'Sales'";
+    @AllowFailure(message = "Extra Joins created")
+    public void testExpression1() {
+        String jpql = "SELECT o.quantity, o.totalCost*1.08 AS taxedCost, "
+            + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a "
+            + "WHERE a.state = 'CA' AND a.county = 'Santa Clara'";
         CriteriaQuery q = cb.create();
-        Root<Department> d = q.from(Department.class);
-        q.where(cb.equal(d.get(Department_.name), "Sales"));
-        q.select(cb.size(d.get(Department_.employees)));
+        Root<Customer> cust = q.from(Customer.class);
+        Join<Customer, Order> order = cust.join(Customer_.orders);
+        Join<Customer, Address> address = cust.join(Customer_.address);
+        q.where(cb.equal(address.get(Address_.state), "CA"), cb.equal(address
+                .get(Address_.county), "Santa Clara"));
+        q.select(order.get(Order_.quantity), cb.prod(order
+                .get(Order_.totalCost), 1.08), address.get(Address_.zipCode));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message = "Index expression not implemented")
+    public void testExpression3() {
+        String jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
+            + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
+        CriteriaQuery q = cb.create();
+        Root<Course> course = q.from(Course.class);
+        ListJoin<Course, Student> w = course.join(Course_.studentWaitList);
+        q.where(cb.equal(course.get(Course_.name), "Calculus"),
+                cb.equal(w.index(), 0)).select(w.get(Student_.name));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message = "Generates extra Join")
+    public void testExpression4() {
+        String jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i " + 
+            "JOIN o.customer c WHERE c.lastName = 'Smith' AND " + 
+            "c.firstName = 'John'";
+        CriteriaQuery q = cb.create();
+        Root<Order> o = q.from(Order.class);
+        Join<Order, LineItem> i = o.join(Order_.lineItems);
+        Join<Order, Customer> c = o.join(Order_.customer);
+        q.where(cb.equal(c.get(Customer_.lastName), "Smith"), cb.equal(c
+                .get(Customer_.firstName), "John"));
+        q.select(cb.sum(i.get(LineItem_.price)));
 
         assertEquivalence(q, jpql);
     }
 
     public void testGeneralCaseExpression() {
         String jpql = "SELECT e.name, CASE "
-                + "WHEN e.rating = 1 THEN e.salary * 1.1 "
-                + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * "
-                + "1.01 END "
-                + "FROM Employee e WHERE e.department.name = 'Engineering'";
+            + "WHEN e.rating = 1 THEN e.salary * 1.1 "
+            + "WHEN e.rating = 2 THEN e.salary * 1.2 ELSE e.salary * "
+            + "1.01 END "
+            + "FROM Employee e WHERE e.department.name = 'Engineering'";
         CriteriaQuery q = cb.create();
         Root<Employee> e = q.from(Employee.class);
         q.where(cb.equal(e.get(Employee_.department).get(Department_.name),
-                "Engineering"));
+        "Engineering"));
         q.select(e.get(Employee_.name), cb.selectCase().when(
                 cb.equal(e.get(Employee_.rating), 1),
                 cb.prod(e.get(Employee_.salary), 1.1)).when(
-                cb.equal(e.get(Employee_.rating), 2),
-                cb.prod(e.get(Employee_.salary), 1.2)).otherwise(
-                cb.prod(e.get(Employee_.salary), 1.01)));
+                        cb.equal(e.get(Employee_.rating), 2),
+                        cb.prod(e.get(Employee_.salary), 1.2)).otherwise(
+                                cb.prod(e.get(Employee_.salary), 1.01)));
 
         assertEquivalence(q, jpql);
     }
 
     public void testSimpleCaseExpression1() {
         String jpql = "SELECT e.name, CASE e.rating "
-                + "WHEN 1 THEN e.salary * 1.1 "
-                + "WHEN 2 THEN e.salary * 1.2 ELSE e.salary * 1.01 END "
-                + "FROM Employee e WHERE e.department.name = 'Engineering'";
+            + "WHEN 1 THEN e.salary * 1.1 "
+            + "WHEN 2 THEN e.salary * 1.2 ELSE e.salary * 1.01 END "
+            + "FROM Employee e WHERE e.department.name = 'Engineering'";
         CriteriaQuery q = cb.create();
         Root<Employee> e = q.from(Employee.class);
         q.where(cb.equal(e.get(Employee_.department).get(Department_.name),
-                "Engineering"));
+        "Engineering"));
         q.select(e.get(Employee_.name), cb.selectCase(e.get(Employee_.rating))
                 .when(1, cb.prod(e.get(Employee_.salary), 1.1)).when(2,
                         cb.prod(e.get(Employee_.salary), 1.2)).otherwise(
-                        cb.prod(e.get(Employee_.salary), 1.01)));
+                                cb.prod(e.get(Employee_.salary), 1.01)));
 
         assertEquivalence(q, jpql);
     }
 
     public void testSimpleCaseExpression2() {
         String jpql = "SELECT e.name, CASE e.rating WHEN 1 THEN 10 "
-                + "WHEN 2 THEN 20 ELSE 30 END "
-                + "FROM Employee e WHERE e.department.name = 'Engineering'";
+            + "WHEN 2 THEN 20 ELSE 30 END "
+            + "FROM Employee e WHERE e.department.name = 'Engineering'";
         CriteriaQuery q = cb.create();
         Root<Employee> e = q.from(Employee.class);
         q.where(cb.equal(e.get(Employee_.department).get(Department_.name),
-                "Engineering"));
+        "Engineering"));
         q.select(e.get(Employee_.name), cb.selectCase(e.get(Employee_.rating))
                 .when(1, 10).when(2, 20).otherwise(30));
         assertEquivalence(q, jpql);
@@ -483,7 +462,7 @@
 
     public void testLiterals() {
         String jpql = "SELECT p FROM Person p where 'Joe' MEMBER OF " +
-        		"p.nickNames";
+        "p.nickNames";
         CriteriaQuery q = cb.create();
         Root<Person> p = q.from(Person.class);
         q.select(p).where(
@@ -492,7 +471,6 @@
         assertEquivalence(q, jpql);
     }
 
-    // @AllowFailure(message = "Parameters not implemented")
     public void testParameters1() {
         String jpql = "SELECT c FROM Customer c Where c.status = :stat";
         CriteriaQuery q = cb.create();
@@ -505,7 +483,7 @@
 
     public void testParameters2() {
         String jpql = "SELECT c FROM Customer c Where c.status = :stat AND "
-                + "c.name = :name";
+            + "c.name = :name";
         CriteriaQuery q = cb.create();
         Root<Customer> c = q.from(Customer.class);
         Parameter<Integer> param1 = cb.parameter(Integer.class, "stat");
@@ -527,21 +505,22 @@
         assertEquivalence(q, jpql, new Object[] { 1 });
     }
 
-    // @AllowFailure(message="add QuotedNumbersInQueries=true otherwise " + 
-    // "AbstractExpressionBuilder.convertTypes() compliants")
-    // public void testParameters4() {
-    // String jpql = "SELECT c FROM Customer c Where c.status = ?1 AND "
-    // + "c.name = ?2";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Parameter<Integer> param1 = cb.parameter(Integer.class);
-    // Parameter<Integer> param2 = cb.parameter(Integer.class);
-    // q.select(c).where(
-    // cb.and(cb.equal(c.get(Customer_.status), param1), cb.equal(c
-    // .get(Customer_.name), param2)));
-    // assertEquivalence(q, jpql, new Object[] { 1, "test" });
-    // }
-
+    @AllowFailure(message="add QuotedNumbersInQueries=true otherwise " + 
+    "AbstractExpressionBuilder.convertTypes() compliants")
+    public void testParameters4() {
+        String jpql = "SELECT c FROM Customer c Where c.status = ?1 AND "
+            + "c.name = ?2";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        Parameter<Integer> param1 = cb.parameter(Integer.class);
+        Parameter<Integer> param2 = cb.parameter(Integer.class);
+        q.select(c).where(
+                cb.and(cb.equal(c.get(Customer_.status), param1), cb.equal(c
+                        .get(Customer_.name), param2)));
+        assertEquivalence(q, jpql, new Object[] { 1, "test" });
+    }
+    
+    @AllowFailure(message = "Criteria API does not allow collection parameter")
     public void testParameters5() {
         String jpql = "SELECT c FROM Customer c Where c.status IN (:coll)";
         CriteriaQuery q = cb.create();
@@ -551,147 +530,176 @@
         List vals = new ArrayList();
         vals.add(1);
         vals.add(2);
+        assertEquivalence(q, jpql, new String[] {"coll"}, 
+            new Object[] {vals});
+    }
+    
+    @AllowFailure(message="Value() expression not implemented")
+    public void testSelectList1() {
+        String jpql = "SELECT v.location.street, KEY(i).title, VALUE(i) FROM "
+            + "VideoStore v JOIN v.videoInventory i WHERE v.location.zipCode = "
+            + "'94301' AND VALUE(i) > 0";
+        CriteriaQuery q = cb.create();
+        Root<VideoStore> v = q.from(VideoStore.class);
+        MapJoin<VideoStore, Movie, Integer> inv = v
+        .join(VideoStore_.videoInventory);
+        q.where(cb.equal(v.get(VideoStore_.location).get(Address_.zipCode),
+        "94301"), cb.gt(inv.value(), 0));
+        q.select(v.get(VideoStore_.location).get(Address_.street), inv.key()
+                .get(Movie_.title), inv.value());
+
+        assertEquivalence(q, jpql);
+    }
+
+    public void testNewConstruct() {
+        String jpql = "SELECT NEW CustomerDetails(c.id, c.status) FROM "
+            + "Customer c";
+        
+        CriteriaQuery q = cb.create();
+
+        Root<Customer> c = q.from(Customer.class);
+        q.select(cb.select(CustomerDetails.class, c.get(Customer_.id), 
+                c.get(Customer_.status))
+        );
+        assertEquivalence(q, jpql);
+    }
+    
+    @AllowFailure(message="new() in projection with join is broken")
+    public void testNewConstruct1() {
+        String jpql =
+            "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM "
+            + "Customer c JOIN c.orders o WHERE o.quantity > 100";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        q.where(cb.gt(o.get(Order_.quantity), 100));
+        q.select(cb.select(CustomerDetails.class, c.get(Customer_.id), c
+                .get(Customer_.status), o.get(Order_.quantity)));
+
+        assertEquivalence(q, jpql);
+    }
 
-        // assertEquivalence(q, jpql, new String[] {"coll"}, new Object[]
-        // {vals});
+    @AllowFailure(message="JPQL does not support multiple constructors")
+    public void testNewConstruct2() {
+        String jpql = "SELECT NEW CustomerDetails(c.id, c.status), " +
+                "NEW CustomerFullName(c.firstName, c.lastName) FROM "
+            + "Customer c";
+        
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        q.select(cb.select(CustomerDetails.class, c.get(Customer_.id), 
+                c.get(Customer_.status)),
+                cb.select(CustomerFullName.class, c.get(Customer_.firstName), 
+                c.get(Customer_.lastName))
+        );
+        assertEquivalence(q, jpql);
+    }
+
+    
+    
+    public void testSubqueries1() {
+        String jpql = "SELECT goodCustomer FROM Customer goodCustomer WHERE "
+            + "goodCustomer.balanceOwed < (SELECT AVG(c.balanceOwed) " 
+            + " FROM "
+            + "Customer c)";
+        CriteriaQuery q = cb.create();
+        Root<Customer> goodCustomer = q.from(Customer.class);
+        Subquery<Double> sq = q.subquery(Double.class);
+        Root<Customer> c = sq.from(Customer.class);
+        q.where(cb.lt(goodCustomer.get(Customer_.balanceOwed), sq.select(cb
+                .avg(c.get(Customer_.balanceOwed)))));
+        q.select(goodCustomer);
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message="SQL is incorrect for JPQL, correct for Criteria")
+    public void testSubqueries2() {
+        String jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
+            + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp ="
+            + " emp.spouse)";
+        CriteriaQuery q = cb.create();
+        Root<Employee> emp = q.from(Employee.class);
+        Subquery<Employee> sq = q.subquery(Employee.class);
+        Root<Employee> spouseEmp = sq.from(Employee.class);
+        sq.select(spouseEmp);
+        sq.where(cb.equal(spouseEmp, emp.get(Employee_.spouse)));
+        q.where(cb.exists(sq));
+        q.select(emp).distinct(true);
+
+        assertEquivalence(q, jpql);
+    }
+
+    public void testSubqueries3() {
+        String jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
+            + "SELECT m.salary FROM Manager m WHERE m.department = "
+            + "emp.department)";
+        CriteriaQuery q = cb.create();
+        Root<Employee> emp = q.from(Employee.class);
+        q.select(emp);
+        Subquery<BigDecimal> sq = q.subquery(BigDecimal.class);
+        Root<Manager> m = sq.from(Manager.class);
+        sq.select(m.get(Manager_.salary));
+        sq.where(cb.equal(m.get(Manager_.department), emp
+                .get(Employee_.department)));
+        q.where(cb.gt(emp.get(Employee_.salary), cb.all(sq)));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message="SQL is incorrect for JPQL, correct for " + 
+        "Criteria is correct with redundant outer joins")
+    public void testSubqueries4() {
+        String jpql = "SELECT c FROM Customer c WHERE "
+            + "(SELECT COUNT(o) FROM c.orders o) > 10";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c1 = q.from(Customer.class);
+        q.select(c1);
+        Subquery<Long> sq3 = q.subquery(Long.class);
+        Root<Customer> c2 = sq3.correlate(c1);
+        Join<Customer, Order> o = c2.join(Customer_.orders);
+        q.where(cb.gt(sq3.select(cb.count(o)), 10));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure(message="Subqueries not implemented")
+    public void testSubqueries5() {
+        String jpql = "SELECT o FROM Order o WHERE 10000 < ALL ("
+            + "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
+        CriteriaQuery q = cb.create();
+        Root<Order> o = q.from(Order.class);
+        q.select(o);
+        Subquery<Integer> sq = q.subquery(Integer.class);
+        Root<Order> osq = sq.correlate(o);
+        Join<Order, Customer> c = osq.join(Order_.customer);
+        Join<Customer, Account> a = c.join(Customer_.accounts);
+        sq.select(a.get(Account_.balance));
+        q.where(cb.lt(cb.literal(10000), cb.all(sq)));
+
+        assertEquivalence(q, jpql);
     }
 
-    // @AllowFailure(message="Value() expression not implemented")
-    // public void testSelectList1() {
-    // String jpql = "SELECT v.location.street, KEY(i).title, VALUE(i) FROM "
-    // + "VideoStore v JOIN v.videoInventory i WHERE v.location.zipCode = "
-    // + "'94301' AND VALUE(i) > 0";
-    // CriteriaQuery q = cb.create();
-    // Root<VideoStore> v = q.from(VideoStore.class);
-    // MapJoin<VideoStore, Movie, Integer> inv = v
-    // .join(VideoStore_.videoInventory);
-    // q.where(cb.equal(v.get(VideoStore_.location).get(Address_.zipCode),
-    // "94301"), cb.gt(inv.value(), 0));
-    // q.select(v.get(VideoStore_.location).get(Address_.street), inv.key()
-    // .get(Movie_.title), inv.value());
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message="new() in projection is broken")
-    // public void testSelectList2() {
-    // String jpql =
-    // "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM "
-    // + "Customer c JOIN c.orders o WHERE o.quantity > 100";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Join<Customer, Order> o = c.join(Customer_.orders);
-    // q.where(cb.gt(o.get(Order_.quantity), 100));
-    // q.select(cb.select(CustomerDetails.class, c.get(Customer_.id), c
-    // .get(Customer_.status), o.get(Order_.quantity)));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries1() {
-//        String jpql = "SELECT goodCustomer FROM Customer goodCustomer WHERE "
-//                + "goodCustomer.balanceOwed < (SELECT AVG(c.balanceOwed) " 
-//                + " FROM "
-//                + "Customer c)";
-//        CriteriaQuery q = cb.create();
-//        Root<Customer> goodCustomer = q.from(Customer.class);
-//        Subquery<Double> sq = q.subquery(Double.class);
-//        Root<Customer> c = sq.from(Customer.class);
-//        q.where(cb.lt(goodCustomer.get(Customer_.balanceOwed), sq.select(cb
-//                .avg(c.get(Customer_.balanceOwed)))));
-//        q.select(goodCustomer);
-//
-//        assertEquivalence(q, jpql);
-//    }
-//
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries2() {
-//        String jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
-//                + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp ="
-//                + " emp.spouse)";
-//        CriteriaQuery q = cb.create();
-//        Root<Employee> emp = q.from(Employee.class);
-//        Subquery<Employee> sq = q.subquery(Employee.class);
-//        Root<Employee> spouseEmp = sq.from(Employee.class);
-//        sq.select(spouseEmp);
-//        sq.where(cb.equal(spouseEmp, emp.get(Employee_.spouse)));
-//        q.where(cb.exists(sq));
-//        q.select(emp).distinct(true);
-//
-//        assertEquivalence(q, jpql);
-//    }
-//
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries3() {
-//        String jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
-//                + "SELECT m.salary FROM Manager m WHERE m.department = "
-//                + "emp.department)";
-//        CriteriaQuery q = cb.create();
-//        Root<Employee> emp = q.from(Employee.class);
-//        q.select(emp);
-//        Subquery<BigDecimal> sq = q.subquery(BigDecimal.class);
-//        Root<Manager> m = sq.from(Manager.class);
-//        sq.select(m.get(Manager_.salary));
-//        sq.where(cb.equal(m.get(Manager_.department), emp
-//                .get(Employee_.department)));
-//        q.where(cb.gt(emp.get(Employee_.salary), cb.all(sq)));
-//
-//        assertEquivalence(q, jpql);
-//    }
-//
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries4() {
-//        String jpql = "SELECT c FROM Customer c WHERE "
-//                + "(SELECT COUNT(o) FROM c.orders o) > 10";
-//        CriteriaQuery q = cb.create();
-//        Root<Customer> c1 = q.from(Customer.class);
-//        q.select(c1);
-//        Subquery<Long> sq3 = q.subquery(Long.class);
-//        Root<Customer> c2 = sq3.correlate(c1);
-//        Join<Customer, Order> o = c2.join(Customer_.orders);
-//        q.where(cb.gt(sq3.select(cb.count(o)), 10));
-//
-//        assertEquivalence(q, jpql);
-//    }
-//
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries5() {
-//        String jpql = "SELECT o FROM Order o WHERE 10000 < ALL ("
-//                + "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
-//        CriteriaQuery q = cb.create();
-//        Root<Order> o = q.from(Order.class);
-//        q.select(o);
-//        Subquery<Integer> sq = q.subquery(Integer.class);
-//        Root<Order> osq = sq.correlate(o);
-//        Join<Order, Customer> c = osq.join(Order_.customer);
-//        Join<Customer, Account> a = c.join(Customer_.accounts);
-//        sq.select(a.get(Account_.balance));
-//        q.where(cb.lt(cb.literal(10000), cb.all(sq)));
-//
-//        assertEquivalence(q, jpql);
-//    }
-//
-//    @AllowFailure(message="Subqueries not implemented")
-//    public void testSubqueries6() {
-//        String jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < "
-//                + "ALL (SELECT a.balance FROM c.accounts a)";
-//        CriteriaQuery q = cb.create();
-//        Root<Order> o = q.from(Order.class);
-//        q.select(o);
-//        Join<Order, Customer> c = o.join(Order_.customer);
-//        Subquery<Integer> sq = q.subquery(Integer.class);
-//        Join<Order, Customer> csq = sq.correlate(c);
-//        Join<Customer, Account> a = csq.join(Customer_.accounts);
-//        sq.select(a.get(Account_.balance));
-//        q.where(cb.lt(cb.literal(10000), cb.all(sq)));
-//
-//        assertEquivalence(q, jpql);
-//    }
+    @AllowFailure(message="Subqueries not implemented")
+    public void testSubqueries6() {
+        String jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < "
+            + "ALL (SELECT a.balance FROM c.accounts a)";
+        CriteriaQuery q = cb.create();
+        Root<Order> o = q.from(Order.class);
+        q.select(o);
+        Join<Order, Customer> c = o.join(Order_.customer);
+        Subquery<Integer> sq = q.subquery(Integer.class);
+        Join<Order, Customer> csq = sq.correlate(c);
+        Join<Customer, Account> a = csq.join(Customer_.accounts);
+        sq.select(a.get(Account_.balance));
+        q.where(cb.lt(cb.literal(10000), cb.all(sq)));
+
+        assertEquivalence(q, jpql);
+    }
 
     public void testGroupByAndHaving() {
         String jpql = "SELECT c.status, AVG(c.filledOrderCount), COUNT(c) FROM "
-                + "Customer c GROUP BY c.status HAVING c.status IN (1, 2)";
+            + "Customer c GROUP BY c.status HAVING c.status IN (1, 2)";
         CriteriaQuery q = cb.create();
         Root<Customer> c = q.from(Customer.class);
         q.groupBy(c.get(Customer_.status));
@@ -702,137 +710,84 @@
         assertEquivalence(q, jpql);
     }
 
-    // @AllowFailure(message="AbstractExpressionExecutor.assertNotContainer() 
-    // not happy")
-    // public void testOrdering() {
-    // String jpql = "SELECT c FROM Customer c JOIN c.orders o "
-    // + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity DESC, "
-    // + "o.totalCost";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Join<Customer, Order> o = c.join(Customer_.orders);
-    // Join<Customer, Address> a = c.join(Customer_.address);
-    // q.where(cb.equal(a.get(Address_.state), "CA"));
-    // q.orderBy(cb.desc(o.get(Order_.quantity)), cb.asc(o
-    // .get(Order_.totalCost)));
-    // q.select(o);
-    //
-    // assertEquivalence(q, jpql);
-    //
-    // jpql = "SELECT o.quantity, a.zipCode FROM Customer c JOIN c.orders "
-    // + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity, "
-    // + "a.zipCode";
-    // q = cb.create();
-    // Root<Customer> c1 = q.from(Customer.class);
-    // Join<Customer, Order> o1 = c1.join(Customer_.orders);
-    // Join<Customer, Address> a1 = c1.join(Customer_.address);
-    // q.where(cb.equal(a1.get(Address_.state), "CA"));
-    // q.orderBy(cb.asc(o1.get(Order_.quantity)), cb.asc(a1
-    // .get(Address_.zipCode)));
-    // q.select(o1.get(Order_.quantity), a1.get(Address_.zipCode));
-    //
-    // assertEquivalence(q, jpql);
-    //
-    // jpql = "SELECT o.quantity, o.cost * 1.08 AS taxedCost, a.zipCode "
-    // + "FROM Customer c JOIN c.orders o JOIN c.address a "
-    // + "WHERE a.state = 'CA' AND a.county = 'Santa Clara' "
-    // + "ORDER BY o.quantity, taxedCost, a.zipCode";
-    // q = cb.create();
-    // Root<Customer> c2 = q.from(Customer.class);
-    // Join<Customer, Order> o2 = c2.join(Customer_.orders);
-    // Join<Customer, Address> a2 = c2.join(Customer_.address);
-    // q.where(cb.equal(a.get(Address_.state), "CA"), cb.equal(a
-    // .get(Address_.county), "Santa Clara"));
-    // q.orderBy(cb.asc(o.get(Order_.quantity)), cb.asc(cb.prod(
-    // o.get(Order_.totalCost), 1.08)),
-    // cb.asc(a.get(Address_.zipCode)));
-    // q.select(o.get(Order_.quantity), cb.prod(
-    // o.get(Order_.totalCost), 1.08), a.get(Address_.zipCode));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message="AbstractExpressionExecutor.assertNotContainer()"+
-    // "not happy")
-    // public void testOrdering1() {
-    // String jpql = "SELECT o FROM Customer c JOIN c.orders o "
-    // + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity DESC, "
-    // + "o.totalCost";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Join<Customer, Order> o = c.join(Customer_.orders);
-    // Join<Customer, Address> a = c.join(Customer_.address);
-    // q.where(cb.equal(a.get(Address_.state), "CA"));
-    // q.orderBy(cb.desc(o.get(Order_.quantity)), cb.asc(o
-    // .get(Order_.totalCost)));
-    // q.select(o);
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message="The JPQL is broken!")
-    // public void testOrdering2() {
-    // String jpql = "SELECT o.quantity, a.zipCode FROM Customer c "
-    // + "JOIN c.orders JOIN c.address a WHERE a.state = 'CA' "
-    // + "ORDER BY o.quantity, a.zipCode";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Join<Customer, Order> o = c.join(Customer_.orders);
-    // Join<Customer, Address> a = c.join(Customer_.address);
-    // q.where(cb.equal(a.get(Address_.state), "CA"));
-    // q.orderBy(cb.asc(o.get(Order_.quantity)), cb.asc(a
-    // .get(Address_.zipCode)));
-    // q.select(o.get(Order_.quantity), a.get(Address_.zipCode));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message="QueryExpression.ordering not initialized")
-    // public void testOrdering3() {
-    // String jpql = "SELECT o.quantity, o.totalCost * 1.08 AS taxedCost, "
-    // + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a "
-    // + "WHERE a.state = 'CA' AND a.county = 'Santa Clara' "
-    // + "ORDER BY o.quantity, taxedCost, a.zipCode";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // Join<Customer, Order> o = c.join(Customer_.orders);
-    // Join<Customer, Address> a = c.join(Customer_.address);
-    // q.where(cb.equal(a.get(Address_.state), "CA"), cb.equal(a
-    // .get(Address_.county), "Santa Clara"));
-    // q.orderBy(cb.asc(o.get(Order_.quantity)), cb.asc(cb.prod(
-    // o.get(Order_.totalCost), 1.08)),
-    // cb.asc(a.get(Address_.zipCode)));
-    // q.select(o.get(Order_.quantity), cb.prod(
-    // o.get(Order_.totalCost), 1.08), a.get(Address_.zipCode));
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    //
-    // @AllowFailure(message="QueryExpression.ordering not initialized")
-    // public void testOrdering4() {
-    // String jpql = "SELECT c FROM Customer c "
-    // + "ORDER BY c.name DESC, c.status";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
-    // .get(Customer_.status)));
-    // q.select(c);
-    //
-    // assertEquivalence(q, jpql);
-    // }
-    //
-    // @AllowFailure(message="QueryExpression.ordering not initialized")
-    // public void testOrdering5() {
-    // String jpql = "SELECT c.firstName, c.lastName, c.balanceOwed "
-    // + "FROM Customer c ORDER BY c.name DESC, c.status";
-    // CriteriaQuery q = cb.create();
-    // Root<Customer> c = q.from(Customer.class);
-    // q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
-    // .get(Customer_.status)));
-    // q.select(c.get(Customer_.firstName), c.get(Customer_.lastName), c
-    // .get(Customer_.balanceOwed));
-    //
-    // assertEquivalence(q, jpql);
-    // }
+    @AllowFailure(message="AbstractExpressionExecutor.assertNotContainer()"+
+    "not happy")
+    public void testOrdering1() {
+        String jpql = "SELECT o FROM Customer c JOIN c.orders o "
+            + "JOIN c.address a WHERE a.state = 'CA' ORDER BY o.quantity DESC, "
+            + "o.totalCost";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        Join<Customer, Address> a = c.join(Customer_.address);
+        q.where(cb.equal(a.get(Address_.state), "CA"));
+        q.orderBy(cb.desc(o.get(Order_.quantity)), cb.asc(o
+                .get(Order_.totalCost)));
+        q.select(o);
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure
+    public void testOrdering2() {
+        String jpql = "SELECT o.quantity, a.zipCode FROM Customer c "
+            + "JOIN c.orders o JOIN c.address a WHERE a.state = 'CA' "
+            + "ORDER BY o.quantity, a.zipCode";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        Join<Customer, Address> a = c.join(Customer_.address);
+        q.where(cb.equal(a.get(Address_.state), "CA"));
+        q.orderBy(cb.asc(o.get(Order_.quantity)), cb.asc(a
+                .get(Address_.zipCode)));
+        q.select(o.get(Order_.quantity), a.get(Address_.zipCode));
+
+        assertEquivalence(q, jpql);
+    }
+
+    @AllowFailure
+    public void testOrdering3() {
+        String jpql = "SELECT o.quantity, o.totalCost * 1.08 AS taxedCost, "
+            + "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a "
+            + "WHERE a.state = 'CA' AND a.county = 'Santa Clara' "
+            + "ORDER BY o.quantity, taxedCost, a.zipCode";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        Join<Customer, Address> a = c.join(Customer_.address);
+        q.where(cb.equal(a.get(Address_.state), "CA"), cb.equal(a
+                .get(Address_.county), "Santa Clara"));
+        q.orderBy(cb.asc(o.get(Order_.quantity)), cb.asc(cb.prod(
+                o.get(Order_.totalCost), 1.08)),
+                cb.asc(a.get(Address_.zipCode)));
+        q.select(o.get(Order_.quantity), cb.prod(
+                o.get(Order_.totalCost), 1.08), a.get(Address_.zipCode));
+
+        assertEquivalence(q, jpql);
+    }
+    
+    public void testOrdering4() {
+        String jpql = "SELECT c FROM Customer c "
+            + "ORDER BY c.name DESC, c.status";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
+                .get(Customer_.status)));
+        q.select(c);
+
+        assertEquivalence(q, jpql);
+    }
+
+    public void testOrdering5() {
+        String jpql = "SELECT c.firstName, c.lastName, c.balanceOwed "
+            + "FROM Customer c ORDER BY c.name DESC, c.status";
+        CriteriaQuery q = cb.create();
+        Root<Customer> c = q.from(Customer.class);
+        q.orderBy(cb.desc(c.get(Customer_.name)), cb.asc(c
+                .get(Customer_.status)));
+        q.select(c.get(Customer_.firstName), c.get(Customer_.lastName), c
+                .get(Customer_.balanceOwed));
+
+        assertEquivalence(q, jpql);
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java?rev=781621&r1=781620&r2=781621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java Wed Jun  3 23:44:58 2009
@@ -96,7 +96,7 @@
     }
 
     public <Y> Expression<Y> all(Subquery<Y> subquery) {
-        throw new AbstractMethodError();
+        return new Expressions.All<Y>(subquery);
     }
 
     public Predicate and(Predicate... restrictions) {
@@ -108,7 +108,7 @@
     }
 
     public <Y> Expression<Y> any(Subquery<Y> subquery) {
-        throw new AbstractMethodError();
+        return new Expressions.Any<Y>(subquery);
     }
 
     public Order asc(Expression<?> x) {
@@ -208,15 +208,19 @@
     }
 
     public Predicate equal(Expression<?> x, Expression<?> y) {
+        if (y == null)
+            return new Expressions.IsNull((ExpressionImpl<?> )x);
         return new Expressions.Equal(x, y);
     }
 
     public Predicate equal(Expression<?> x, Object y) {
+        if (y == null)
+            return new Expressions.IsNull((ExpressionImpl<?> )x);
         return new Expressions.Equal(x, y);
     }
 
     public Predicate exists(Subquery<?> subquery) {
-        throw new AbstractMethodError();
+        return new Expressions.Exists(subquery);
     }
 
     public <T> Expression<T> function(String name, Class<T> type,
@@ -326,7 +330,7 @@
     }
 
     public Expression<Integer> length(Expression<String> x) {
-        throw new AbstractMethodError();
+        return new Expressions.Length(x);
 
     }
 
@@ -385,29 +389,29 @@
 
     public Expression<Integer> locate(Expression<String> x,
         Expression<String> pattern) {
-        throw new AbstractMethodError();
+        return new Expressions.Locate(x, pattern);
 
     }
 
     public Expression<Integer> locate(Expression<String> x, String pattern) {
-        throw new AbstractMethodError();
+        return new Expressions.Locate(x, pattern);
 
     }
 
     public Expression<Integer> locate(Expression<String> x,
         Expression<String> pattern, Expression<Integer> from) {
-        throw new AbstractMethodError();
+        return new Expressions.Locate(x, pattern, from);
 
     }
 
     public Expression<Integer> locate(Expression<String> x, String pattern,
         int from) {
-        throw new AbstractMethodError();
+        return new Expressions.Locate(x, pattern, from);
 
     }
 
     public Expression<String> lower(Expression<String> x) {
-        throw new AbstractMethodError();
+        return new Expressions.Lower(x);
 
     }
 
@@ -486,12 +490,12 @@
     }
 
     public <Y> Expression<Y> nullif(Expression<Y> x, Expression<?> y) {
-        throw new AbstractMethodError();
+        return new Expressions.Nullif(x, y);
 
     }
 
     public <Y> Expression<Y> nullif(Expression<Y> x, Y y) {
-        throw new AbstractMethodError();
+        return new Expressions.Nullif(x, y);
 
     }
 
@@ -563,7 +567,7 @@
     }
 
     public <Y> Expression<Y> some(Subquery<Y> subquery) {
-        throw new AbstractMethodError();
+        return new Expressions.Some<Y>(subquery);
     }
 
     public Expression<Double> sqrt(Expression<? extends Number> x) {
@@ -572,7 +576,7 @@
 
     public Expression<String> substring(Expression<String> x,
         Expression<Integer> from) {
-    	return new Expressions.Substring(x);
+    	return new Expressions.Substring(x, from);
     }
 
     public Expression<String> substring(Expression<String> x, int from) {
@@ -665,7 +669,7 @@
     }
 
     public Expression<String> upper(Expression<String> x) {
-        throw new AbstractMethodError();
+        return new Expressions.Upper(x);
 
     }
 



Mime
View raw message