openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r783166 [2/3] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-kernel/src/ma...
Date Wed, 10 Jun 2009 00:41:38 GMT
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java?rev=783166&r1=783165&r2=783166&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestCriteria.java Wed Jun 10 00:41:35 2009
@@ -56,28 +56,43 @@
     
     public void setUp() {
             super.setUp(CLEAR_TABLES,
-                Account.class,
-                Address.class, 
-                CompUser.class,
-                Contact.class,
-                Contractor.class, 
-                Course.class, 
-                CreditCard.class, 
-                Customer.class, 
-                Department.class, 
-                Employee.class, 
-                Exempt.class, 
-                FrequentFlierPlan.class,
-                Item.class,
-                LineItem.class,
-                Manager.class, 
-                Person.class, 
-                Order.class, 
-                Phone.class,
-                Photo.class,
-                Student.class, 
-                Transaction.class,
-                VideoStore.class);
+                    "openjpa.DynamicEnhancementAgent", "false",
+                    Account.class,
+                    Address.class,
+                    A.class,
+                    B.class,
+                    CompUser.class,
+                    Contact.class,
+                    Contractor.class,
+                    Course.class,
+                    CreditCard.class,
+                    Customer.class,
+                    C.class,
+                    Department.class,
+                    DependentId.class,
+                    Dependent.class,
+                    D.class,
+                    Employee.class,
+                    Exempt.class,
+                    FemaleUser.class,
+                    FrequentFlierPlan.class,
+                    Item.class,
+                    LineItem.class,
+                    Magazine.class,
+                    MaleUser.class,
+                    Manager.class,
+                    Movie.class,
+                    Order.class,
+                    Person.class,
+                    Phone.class,
+                    Photo.class,
+                    Product.class,
+                    Publisher.class,
+                    Semester.class,
+                    Student.class,
+                    TransactionHistory.class,
+                    Transaction.class,
+                    VideoStore.class);
         qb = (QueryBuilderImpl)emf.getDynamicQueryBuilder();
         emf.createEntityManager();
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJoinCondition.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJoinCondition.java?rev=783166&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJoinCondition.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJoinCondition.java Wed Jun 10 00:41:35 2009
@@ -0,0 +1,146 @@
+package org.apache.openjpa.persistence.criteria;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.criteria.CollectionJoin;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.ListJoin;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.SetJoin;
+
+import org.apache.openjpa.persistence.test.AllowFailure;
+
+/**
+ * Tests Criteria Queries that use Join.
+ *  
+ * @author Pinaki Poddar
+ *
+ */
+public class TestJoinCondition extends CriteriaTest {
+    
+    public void testSingleAttributeJoinModel() {
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Join<A,B> b = a.join(A_.b);
+        assertSame(B.class, b.getJavaType());
+        assertSame(B.class, b.getMember().getMemberJavaType());
+    }
+    
+    public void testCollectionJoinModel() {
+        CriteriaQuery cq = cb.create();
+        Root<C> c = cq.from(C.class);
+        CollectionJoin<C,D> d = c.join(C_.coll);
+        assertSame(Collection.class, d.getJavaType());
+        assertSame(D.class, d.getMember().getMemberJavaType());
+    }
+    
+    public void testSetJoinModel() {
+        CriteriaQuery cq = cb.create();
+        Root<C> c = cq.from(C.class);
+        SetJoin<C,D> d = c.join(C_.set);
+        assertSame(Set.class, d.getJavaType());
+        assertSame(D.class, d.getMember().getMemberJavaType());
+    }
+    
+    public void testListJoinModel() {
+        CriteriaQuery cq = cb.create();
+        Root<C> c = cq.from(C.class);
+        ListJoin<C,D> d = c.join(C_.list);
+        assertSame(List.class, d.getJavaType());
+        assertSame(D.class, d.getMember().getMemberJavaType());
+    }
+    
+    public void testInnerJoinSingleAttributeWithoutCondition() {
+        String jpql = "select a from A a INNER JOIN a.b b";
+        CriteriaQuery c = cb.create();
+        c.from(A.class).join(A_.b, JoinType.INNER);
+        
+        assertEquivalence(c, jpql);
+    }  
+    
+    public void testCrossJoinWithoutCondition() {
+        String jpql = "select a from A a, C c";
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Root<C> c = cq.from(C.class);
+        
+        assertEquivalence(cq, jpql);
+    }
+    
+    @AllowFailure(message="Missing where clause")
+    public void testCrossJoin() {
+        String jpql = "select a from A a, C c where a.name=c.name";
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Root<C> c = cq.from(C.class);
+        cq.where(cb.equal(a.get(A_.name), c.get(C_.name)));
+        
+        assertEquivalence(cq, jpql);
+    }
+
+    public void testInnerJoinSingleAttribute() {
+        String jpql = "select a from A a INNER JOIN a.b b WHERE a.id=b.age";
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Join<A,B> b = a.join(A_.b);
+        cq.where(cb.equal(a.get(A_.id), b.get(B_.age)));
+        
+        assertEquivalence(cq, jpql);
+    }
+    
+    public void testOuterJoinSingleAttributeWithoutCondition() {
+        String jpql = "select a from A a LEFT JOIN a.b b";
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Join<A,B> b = a.join(A_.b, JoinType.LEFT);
+        
+        assertEquivalence(cq, jpql);
+    }
+    
+    public void testOuterJoinSingleAttribute() {
+        String jpql = "select a from A a LEFT JOIN a.b b where a.id=b.age";
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        Join<A,B> b = a.join(A_.b, JoinType.LEFT);
+        cq.where(cb.equal(a.get(A_.id), b.get(B_.age)));
+        
+        assertEquivalence(cq, jpql);
+    }
+
+    public void testSetJoinWithoutCondition() {
+        String jpql = "select c from C c JOIN c.set d";
+        CriteriaQuery c = cb.create();
+        c.from(C.class).join(C_.set);
+        
+        assertEquivalence(c, jpql);
+    }
+    
+    public void testListJoinWithoutCondition() {
+        String jpql = "select c from C c JOIN c.list d";
+        CriteriaQuery c = cb.create();
+        c.from(C.class).join(C_.list);
+        
+        assertEquivalence(c, jpql);
+    }
+    
+    public void testCollectionJoinWithoutCondition() {
+        String jpql = "select c from C c JOIN c.coll d";
+        CriteriaQuery c = cb.create();
+        c.from(C.class).join(C_.coll);
+        
+        assertEquivalence(c, jpql);
+    }
+    
+    public void testMapJoinWithoutCondition() {
+        String jpql = "select c from C c JOIN c.map d";
+        CriteriaQuery c = cb.create();
+        c.from(C.class).join(C_.map);
+        
+        assertEquivalence(c, jpql);
+    }
+ 
+}

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

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java?rev=783166&r1=783165&r2=783166&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java Wed Jun 10 00:41:35 2009
@@ -17,10 +17,10 @@
  * under the License.    
  */
 package org.apache.openjpa.persistence.criteria;
+
 import java.math.BigDecimal;
 import java.util.List;
 
-import javax.persistence.EntityManager;
 import javax.persistence.Parameter;
 import javax.persistence.Query;
 import javax.persistence.criteria.CriteriaQuery;
@@ -34,390 +34,364 @@
 import javax.persistence.metamodel.Entity;
 import javax.persistence.metamodel.Metamodel;
 
-import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
-import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.persistence.test.AllowFailure;
 
 public class TestMetaModelTypesafeCriteria extends CriteriaTest {
-    protected Entity<Account> account_ = null; 
-    protected Embeddable<Address> address_ = null; 
-    protected Embeddable<Contact> contact_ = null; 
-    protected Entity<Course> course_ = null; 
-    protected Entity<CreditCard> creditCard_ = null; 
-    protected Entity<Customer> customer_ = null; 
-    protected Entity<Department> department_ = null; 
-    protected Entity<Employee> employee_ = null; 
-    protected Entity<Exempt> exempt_ = null; 
-    protected Entity<Item> item_ = null; 
-    protected Entity<LineItem> lineItem_ = null; 
-    protected Entity<Manager> manager_ = null; 
-    protected Entity<Movie> movie_ = null; 
+    protected Entity<Account> account_ = null;
+    protected Embeddable<Address> address_ = null;
+    protected Embeddable<Contact> contact_ = null;
+    protected Entity<Course> course_ = null;
+    protected Entity<CreditCard> creditCard_ = null;
+    protected Entity<Customer> customer_ = null;
+    protected Entity<Department> department_ = null;
+    protected Entity<Employee> employee_ = null;
+    protected Entity<Exempt> exempt_ = null;
+    protected Entity<Item> item_ = null;
+    protected Entity<LineItem> lineItem_ = null;
+    protected Entity<Manager> manager_ = null;
+    protected Entity<Movie> movie_ = null;
     protected Entity<Order> order_ = null;
     protected Entity<Person> person_ = null;
     protected Entity<Phone> phone_ = null;
     protected Entity<Photo> photo_ = null;
-    protected Entity<Product> product_ = null; 
-    protected Entity<Semester> semester_ = null; 
-    protected Entity<Student> student_ = null; 
-    protected Entity<TransactionHistory> transactionHistory_ = null; 
-    protected Entity<VideoStore> videoStore_ = null; 
-    CriteriaBuilder cb;
-    EntityManager em;
-    
-         
+    protected Entity<Product> product_ = null;
+    protected Entity<Semester> semester_ = null;
+    protected Entity<Student> student_ = null;
+    protected Entity<TransactionHistory> transactionHistory_ = null;
+    protected Entity<VideoStore> videoStore_ = null;
+
     public void setUp() {
-             super.setUp((Object[])null); // super will initialize domain
-            
-            setDictionary();
-            
-            cb = (CriteriaBuilder)emf.getQueryBuilder();
-            em = emf.createEntityManager();
-            Metamodel mm = em.getMetamodel();
-            account_ = mm.entity(Account.class);
-            address_ = mm.embeddable(Address.class);
-            contact_ = mm.embeddable(Contact.class);
-            course_ = mm.entity(Course.class);
-            creditCard_ = mm.entity(CreditCard.class);
-            customer_ = mm.entity(Customer.class);
-            department_ = mm.entity(Department.class);
-            employee_ = mm.entity(Employee.class);
-            exempt_ = mm.entity(Exempt.class);
-            item_ = mm.entity(Item.class);
-            lineItem_ = mm.entity(LineItem.class);
-            manager_ = mm.entity(Manager.class);
-            movie_ = mm.entity(Movie.class);
-            order_ = mm.entity(Order.class);
-            person_ = mm.entity(Person.class);
-            phone_ = mm.entity(Phone.class);
-            photo_ = mm.entity(Photo.class);
-            product_ = mm.entity(Product.class); 
-            semester_ = mm.entity(Semester.class);
-            student_ = mm.entity(Student.class);
-            transactionHistory_ = mm.entity(TransactionHistory.class);
-            videoStore_ = mm.entity(VideoStore.class);
-            
-        }
-        
-        void setDictionary() {
-            JDBCConfiguration conf = (JDBCConfiguration)emf.getConfiguration();
-            DBDictionary dict = conf.getDBDictionaryInstance();
-            dict.requiresCastForComparisons = false;
-            dict.requiresCastForMathFunctions = false;
-        }
-        
-    public void createObj() {
+        super.setUp();
+
+        Metamodel mm = em.getMetamodel();
+        account_ = mm.entity(Account.class);
+        address_ = mm.embeddable(Address.class);
+        contact_ = mm.embeddable(Contact.class);
+        course_ = mm.entity(Course.class);
+        creditCard_ = mm.entity(CreditCard.class);
+        customer_ = mm.entity(Customer.class);
+        department_ = mm.entity(Department.class);
+        employee_ = mm.entity(Employee.class);
+        exempt_ = mm.entity(Exempt.class);
+        item_ = mm.entity(Item.class);
+        lineItem_ = mm.entity(LineItem.class);
+        manager_ = mm.entity(Manager.class);
+        movie_ = mm.entity(Movie.class);
+        order_ = mm.entity(Order.class);
+        person_ = mm.entity(Person.class);
+        phone_ = mm.entity(Phone.class);
+        photo_ = mm.entity(Photo.class);
+        product_ = mm.entity(Product.class);
+        semester_ = mm.entity(Semester.class);
+        student_ = mm.entity(Student.class);
+        transactionHistory_ = mm.entity(TransactionHistory.class);
+        videoStore_ = mm.entity(VideoStore.class);
     }
-    
-    @AllowFailure
+
     public void testCriteria() {
-        String jpql = "select c from Customer c where c.name='Autowest Toyota'";
+        String jpql = "select c from Customer c " 
+                    + "where c.name='Autowest Toyota'";
         CriteriaQuery q = cb.create();
         Root<Customer> customer = q.from(Customer.class);
-        q = cb.create();
-        q.select(customer).where(cb.equal(
-            customer.get(customer_.getAttribute("name", String.class)), 
-            "Autowest Toyota"));
-        
+        q.select(customer).where(
+                cb.equal(customer.get(customer_.getAttribute("name",
+                        String.class)), "Autowest Toyota"));
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     public void testJoins() {
-        String jpql = "SELECT c.name FROM Customer c JOIN c.orders o " + 
-            "JOIN o.lineItems i WHERE i.product.productType = 'printer'";
+        String jpql = "SELECT c.name FROM Customer c JOIN c.orders o "
+                + "JOIN o.lineItems i WHERE i.product.productType = 'printer'";
         CriteriaQuery q = cb.create();
         Root<Customer> cust = q.from(Customer.class);
-        Join<Customer, Order> order = cust.join(customer_.getSet("orders", 
-            Order.class));
-        Join<Order, LineItem> item = order.join(order_.getList("lineItems", 
-            LineItem.class));
-        q.select(cust.get(Customer_.name))
-            .where(cb.equal(
-                item.get(lineItem_.getAttribute("product", Product.class)).
-                get(product_.getAttribute("productType", String.class)), 
-                "printer"));
-        
+        Join<Customer, Order> order = cust.join(customer_.getSet("orders",
+                Order.class));
+        Join<Order, LineItem> item = order.join(order_.getList("lineItems",
+                LineItem.class));
+        q.select(cust.get(Customer_.name)).where(
+                cb.equal(item.get(
+                        lineItem_.getAttribute("product", Product.class)).get(
+                        product_.getAttribute("productType", String.class)),
+                        "printer"));
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT c FROM Customer c LEFT JOIN c.orders o WHERE " + 
-            "c.status = 1";
+
+        jpql = "SELECT c FROM Customer c LEFT JOIN c.orders o WHERE "
+                + "c.status = 1";
         q = cb.create();
         Root<Customer> cust1 = q.from(Customer.class);
-        Join<Customer, Order> order1 = cust1.join(customer_.getSet("orders", 
-            Order.class), JoinType.LEFT);
-        q.where(cb.equal(cust1.get(customer_.getAttribute("status", 
-            Integer.class)), 1)).select(cust1);
-        
+        Join<Customer, Order> order1 = cust1.join(customer_.getSet("orders",
+                Order.class), JoinType.LEFT);
+        q.where(
+                cb.equal(cust1.get(customer_.getAttribute("status",
+                        Integer.class)), 1)).select(cust1);
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     public void testFetchJoins() {
-        String jpql =
-            "SELECT d FROM Department LEFT JOIN FETCH d.employees "
+        String jpql = "SELECT d FROM Department LEFT JOIN FETCH d.employees "
                 + "WHERE d.deptNo = 1";
         CriteriaQuery q = cb.create();
         Root<Department> d = q.from(Department.class);
         d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT);
-        q.where(cb.equal(d.get(department_.getAttribute("deptNo", 
-            Integer.class)), 1)).select(d);
-        
+        q.where(
+                cb.equal(d.get(department_
+                        .getAttribute("deptNo", Integer.class)), 1)).select(d);
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     public void testPathNavigation() {
-        String jpql = "SELECT p.vendor FROM Employee e " + 
-            "JOIN e.contactInfo.phones p  WHERE e.contactInfo.address.zipCode ="
-            + " '95054'";
+        String jpql = "SELECT p.vendor FROM Employee e "
+                + "JOIN 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_.getAttribute("contactInfo", Contact.class)).
-            join(contact_.getList("phones", Phone.class));
+                employee_.getAttribute("contactInfo", Contact.class)).join(
+                contact_.getList("phones", Phone.class));
         q.where(cb.equal(emp.get(
-            employee_.getAttribute("contactInfo", Contact.class)).get(
-            contact_.getAttribute("address", Address.class)).get(
-            address_.getAttribute("zipCode", String.class)), "95054"));
+                employee_.getAttribute("contactInfo", Contact.class)).get(
+                contact_.getAttribute("address", Address.class)).get(
+                address_.getAttribute("zipCode", String.class)), "95054"));
         q.select(phone.get(phone_.getAttribute("vendor", String.class)));
-        
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) " + 
-            "LIKE '%egret%'";
-        
+
+        jpql = "SELECT i.name, p FROM Item i JOIN i.photos p WHERE KEY(p) "
+                + "LIKE '%egret%'";
+
         q = cb.create();
         Root<Item> item = q.from(Item.class);
-        MapJoin<Item, String, Photo> photo = item.join(item_.getMap("photos", 
-            String.class, Photo.class));
-        q.select(item.get(item_.getAttribute("name", String.class)), photo).
-            where(cb.like(photo.key(), "%egret%"));
-        
+        MapJoin<Item, String, Photo> photo = item.join(item_.getMap("photos",
+                String.class, Photo.class));
+        q.select(item.get(item_.getAttribute("name", String.class)), photo)
+                .where(cb.like(photo.key(), "%egret%"));
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     public void testRestrictQueryResult() {
-        String jpql = "SELECT t FROM CreditCard c JOIN c.transactionHistory t " 
-            + "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_.getList("transactionHistory", 
-            TransactionHistory.class));
-        q.select(t).where(cb.equal(
-            c.get(creditCard_.getAttribute("customer", Customer.class)).
-            get(customer_.getAttribute("accountNum", Long.class)), 321987),
-            cb.between(t.index(), 0, 9));
-        
-        assertEquivalence(q, jpql);
+        String jpql = "SELECT t FROM CreditCard c JOIN c.transactionHistory t "
+                + "WHERE c.customer.accountNum = 321987 AND INDEX(t) BETWEEN 0 "
+                + "AND 9";
+        
+        CriteriaQuery cq = cb.create();
+        Root<CreditCard> c = cq.from(CreditCard.class);
+        ListJoin<CreditCard, TransactionHistory> t = c.join(creditCard_
+                .getList("transactionHistory", TransactionHistory.class));
+        cq.select(t).where(
+                cb.equal(c.get(
+                        creditCard_.getAttribute("customer", Customer.class))
+                        .get(customer_.getAttribute("accountNum", Long.class)),
+                        321987), cb.between(t.index(), 0, 9));
 
-/*
-         
-        jpql = "SELECT o FROM Order o WHERE o.lineItems IS EMPTY";
-        q = cb.create();
-        Root<Order> order = q.from(Order.class);
-        Join<Order,LineItem> lineItems = order.join(order_.getList("lineItems",
-            LineItem.class));
-        q.where(cb.isEmpty(lineItems));
-        q.select(order);
-        
-        assertEquivalence(q, jpql);
-*/        
+        assertEquivalence(cq, jpql);
+
+        /*
+         * 
+         * jpql = "SELECT o FROM Order o WHERE o.lineItems IS EMPTY"; q =
+         * cb.create(); Root<Order> order = q.from(Order.class);
+         * Join<Order,LineItem> lineItems =
+         * order.join(order_.getList("lineItems", LineItem.class));
+         * q.where(cb.isEmpty(lineItems)); q.select(order);
+         * 
+         * assertEquivalence(q, jpql);
+         */
     }
 
     @AllowFailure
     public void testExpressions() {
-        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";
+        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_.getSet("orders", 
-            Order.class));
+        Join<Customer, Order> order = cust.join(customer_.getSet("orders",
+                Order.class));
         Join<Customer, Address> address = cust.join(customer_.getAttribute(
-            "address", Address.class));
-        q.where(cb.equal(address.get(address_.getAttribute("state", 
-            String.class)), "CA"),
-            cb.equal(address.get(address_.getAttribute("county", 
-            String.class)), "Santa Clara"));
-        q.select(order.get(order_.getAttribute("quantity", Integer.class)), 
-            cb.prod(order.get(order_.getAttribute("totalCost", Double.class)),
-            1.08),
-            address.get(address_.getAttribute("zipCode", String.class)));
-        
+                "address", Address.class));
+        q.where(cb.equal(address.get(address_.getAttribute("state",
+                String.class)), "CA"), cb.equal(address.get(address_
+                .getAttribute("county", String.class)), "Santa Clara"));
+        q.select(order.get(order_.getAttribute("quantity", Integer.class)),
+                cb.prod(order.get(order_
+                        .getAttribute("totalCost", Double.class)), 1.08),
+                address.get(address_.getAttribute("zipCode", String.class)));
+
         assertEquivalence(q, jpql);
-        
+
         jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
         q = cb.create();
         Root<Employee> emp = q.from(Employee.class);
         q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));
-        
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w " + 
-            "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
+
+        jpql = "SELECT w.name FROM Course c JOIN c.studentWaitList w "
+                + "WHERE c.name = 'Calculus' AND INDEX(w) = 0";
         q = cb.create();
         Root<Course> course = q.from(Course.class);
         ListJoin<Course, Student> w = course.join(course_.getList(
-            "studentWaitList", Student.class));
-        q.where(cb.equal(course.get(course_.getAttribute("name", 
-            String.class)), "Calculus"), 
-            cb.equal(w.index(), 0)).select(w.get(student_.getAttribute("name", 
-            String.class)));
-        
+                "studentWaitList", Student.class));
+        q.where(
+                cb.equal(
+                        course.get(course_.getAttribute("name", String.class)),
+                        "Calculus"), cb.equal(w.index(), 0)).select(
+                w.get(student_.getAttribute("name", String.class)));
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT SUM(i.price) FROM Order o JOIN o.lineItems i JOIN " +
-            "o.customer c WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
+
+        jpql = "SELECT SUM(i.price) " 
+             + "FROM Order o JOIN o.lineItems i JOIN o.customer c "
+             + "WHERE c.lastName = 'Smith' AND c.firstName = 'John'";
         q = cb.create();
         Root<Order> o = q.from(Order.class);
-        Join<Order, LineItem> i = o.join(order_.getList("lineItems", 
-            LineItem.class));
-        Join<Order, Customer> c = o.join(order_.getAttribute("customer", 
-            Customer.class));
-        q.where(cb.equal(c.get(customer_.getAttribute("lastName", 
-            String.class)), "Smith"),
-            cb.equal(c.get(customer_.getAttribute("firstName", 
-            String.class)), "John"));
-        q.select(cb.sum(i.get(lineItem_.getAttribute("price", 
-            Double.class))));
-        
-        assertEquivalence(q, jpql);
-/*        
-        jpql = "SELECT SIZE(d.employees) FROM Department d " + 
-            "WHERE d.name = 'Sales'";
-        q = cb.create();
-        Root<Department> d = q.from(Department.class);
-        q.where(cb.equal(d.get(department_.getAttribute("name", 
-            String.class)), "Sales"));
-        q.select(cb.size(d.get(department_.getSet("employees", 
-            Employee.class))));
-        
+        Join<Order, LineItem> i = o.join(order_.getList("lineItems",
+                LineItem.class));
+        Join<Order, Customer> c = o.join(order_.getAttribute("customer",
+                Customer.class));
+        q.where(cb
+                .equal(c.get(customer_.getAttribute("lastName", String.class)),
+                        "Smith"), cb.equal(c.get(customer_.getAttribute(
+                "firstName", String.class)), "John"));
+        q.select(cb.sum(i.get(lineItem_.getAttribute("price", Double.class))));
+
         assertEquivalence(q, jpql);
-*/        
-        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'";
+        /*
+         * jpql = "SELECT SIZE(d.employees) FROM Department d " +
+         * "WHERE d.name = 'Sales'"; q = cb.create(); Root<Department> d =
+         * q.from(Department.class);
+         * q.where(cb.equal(d.get(department_.getAttribute("name",
+         * String.class)), "Sales"));
+         * q.select(cb.size(d.get(department_.getSet("employees",
+         * Employee.class))));
+         * 
+         * assertEquivalence(q, jpql);
+         */
+        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'";
         q = cb.create();
         Root<Employee> e = q.from(Employee.class);
-        q.where(cb.equal(e.get(employee_.getAttribute("department", 
-            Department.class)).
-            get(department_.getAttribute("name", String.class)), 
-            "Engineering"));
-        q.select(e.get(employee_.getAttribute("name", String.class)), 
-            cb.selectCase()
-                .when(cb.equal(e.get(employee_.getAttribute("rating", 
-                    Integer.class)), 1),
-                    cb.prod(e.get(employee_.getAttribute("salary", 
-                    Long.class)), 1.1))
-                .when(cb.equal(e.get(employee_.getAttribute("rating", 
-                    Integer.class)), 2), 
-                    cb.prod(e.get(employee_.getAttribute("salary", 
-                    Long.class)), 1.2))
-                .otherwise(cb.prod(e.get(employee_.getAttribute("salary", 
-                    Long.class)), 1.01)));    
- 
-        assertEquivalence(q, jpql);
-    }    
-/*    
-    @AllowFailure
-    public void testLiterals() {
-        String jpql = "SELECT p FROM Person p where 'Joe' MEMBER OF " + 
-            "p.nickNames";
-        CriteriaQuery q = cb.create();
-        Root<Person> p = q.from(Person.class);
-        q.select(p).where(cb.isMember(cb.literal("Joe"), p.get(person_.
-            getSet("nickNames", String.class))));
-        
+        q
+                .where(cb.equal(e.get(
+                        employee_.getAttribute("department", Department.class))
+                        .get(department_.getAttribute("name", String.class)),
+                        "Engineering"));
+        q.select(e.get(employee_.getAttribute("name", String.class)), cb
+                .selectCase().when(
+                        cb.equal(e.get(employee_.getAttribute("rating",
+                                Integer.class)), 1),
+                        cb.prod(e.get(employee_.getAttribute("salary",
+                                Long.class)), 1.1)).when(
+                        cb.equal(e.get(employee_.getAttribute("rating",
+                                Integer.class)), 2),
+                        cb.prod(e.get(employee_.getAttribute("salary",
+                                Long.class)), 1.2)).otherwise(
+                        cb.prod(e.get(employee_.getAttribute("salary",
+                                Long.class)), 1.01)));
+
         assertEquivalence(q, jpql);
     }
-*/
-    
+
+    /*
+     * @AllowFailure public void testLiterals() { String jpql =
+     * "SELECT p FROM Person p where 'Joe' MEMBER OF " + "p.nickNames";
+     * CriteriaQuery q = cb.create(); Root<Person> p = q.from(Person.class);
+     * q.select(p).where(cb.isMember(cb.literal("Joe"), p.get(person_.
+     * getSet("nickNames", String.class))));
+     * 
+     * assertEquivalence(q, jpql); }
+     */
+
     @AllowFailure
     public void testParameters() {
         String jpql = "SELECT c FROM Customer c Where c.status = :stat";
         CriteriaQuery q = cb.create();
         Root<Customer> c = q.from(Customer.class);
         Parameter<Integer> param = cb.parameter(Integer.class);
-        q.select(c).where(cb.equal(c.get(customer_.getAttribute("status", 
-            Integer.class)), param));
-        
-        assertEquivalence(q, jpql, new String[]{"stat"}, new Object[] {1});
+        q.select(c).where(
+                cb.equal(
+                        c.get(customer_.getAttribute("status", Integer.class)),
+                        param));
+
+        assertEquivalence(q, jpql, new String[] { "stat" }, new Object[] { 1 });
     }
-    
+
     @AllowFailure
     public void testSelectList() {
-        String jpql =
-            "SELECT v.location.street, KEY(i).title, VALUE(i) FROM "
+        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_.getMap(
-            "videoInventory", Movie.class, Integer.class));
-        q.where(cb.equal(v.get(videoStore_.getAttribute("location", 
-            Address.class)).
-            get(address_.getAttribute("zipCode", String.class)), "94301"),
-            cb.gt(inv.value(), 0));
-        q.select(v.get(videoStore_.getAttribute("location", Address.class)).
-            get(address_.getAttribute("street", String.class)), 
-            inv.key().get(movie_.getAttribute("title", String.class)), 
-                inv.value());
-        
+                "videoInventory", Movie.class, Integer.class));
+        q.where(cb.equal(v.get(
+                videoStore_.getAttribute("location", Address.class)).get(
+                address_.getAttribute("zipCode", String.class)), "94301"), cb
+                .gt(inv.value(), 0));
+        q.select(v.get(videoStore_.getAttribute("location", Address.class))
+                .get(address_.getAttribute("street", String.class)), inv.key()
+                .get(movie_.getAttribute("title", String.class)), inv.value());
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM " + 
-            "Customer c JOIN c.orders o WHERE o.quantity > 100";
+
+        jpql = "SELECT NEW CustomerDetails(c.id, c.status, o.quantity) FROM "
+                + "Customer c JOIN c.orders o WHERE o.quantity > 100";
         q = cb.create();
         Root<Customer> c = q.from(Customer.class);
-        Join<Customer, Order> o =
-            c.join(customer_.getSet("orders", Order.class));
+        Join<Customer, Order> o = c.join(customer_
+                .getSet("orders", Order.class));
         q.where(cb.gt(o.get(order_.getAttribute("quantity", Integer.class)),
-            100));
-        q.select(cb.select(CustomerDetails.class, 
-            c.get(customer_.getAttribute("id", Integer.class)),
-            c.get(customer_.getAttribute("status", Integer.class)),
-            o.get(order_.getAttribute("quantity", Integer.class))));
-        
+                100));
+        q.select(cb.select(CustomerDetails.class, c.get(customer_.getAttribute(
+                "id", Integer.class)), c.get(customer_.getAttribute("status",
+                Integer.class)), o.get(order_.getAttribute("quantity",
+                Integer.class))));
+
         assertEquivalence(q, jpql);
     }
 
     @AllowFailure
     public void testSubqueries() {
-        String jpql = "SELECT goodCustomer FROM Customer goodCustomer WHERE " + 
-            "goodCustomer.balanceOwed < (SELECT AVG(c.balanceOwed) FROM " + 
-            "Customer c)";
+        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_.getAttribute("balanceOwed", 
-            Integer.class)), 
-            sq.select(cb.avg(c.get(customer_.getAttribute("balanceOwed", 
-            Integer.class))))));
+        q.where(cb.lt(goodCustomer.get(customer_.getAttribute("balanceOwed",
+                Integer.class)), sq.select(cb.avg(c.get(customer_.getAttribute(
+                "balanceOwed", Integer.class))))));
         q.select(goodCustomer);
-        
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS (" + 
-            "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = " + 
-            "emp.spouse)";
+
+        jpql = "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
+                + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = "
+                + "emp.spouse)";
         q = cb.create();
         Root<Employee> emp = q.from(Employee.class);
         Subquery<Employee> sq1 = q.subquery(Employee.class);
         Root<Employee> spouseEmp = sq1.from(Employee.class);
         sq1.select(spouseEmp);
-        sq1.where(cb.equal(spouseEmp, emp.get(employee_.getAttribute("spouse", 
-            Employee.class))));
+        sq1.where(cb.equal(spouseEmp, emp.get(employee_.getAttribute("spouse",
+                Employee.class))));
         q.where(cb.exists(sq));
         q.select(emp).distinct(true);
-        
+
         assertEquivalence(q, jpql);
-        
-        jpql =
-            "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
+
+        jpql = "SELECT emp FROM Employee emp WHERE emp.salary > ALL ("
                 + "SELECT m.salary FROM Manager m WHERE m.department ="
                 + " emp.department)";
         q = cb.create();
@@ -426,180 +400,137 @@
         Subquery<BigDecimal> sq2 = q.subquery(BigDecimal.class);
         Root<Manager> m = sq2.from(Manager.class);
         sq2.select(m.get(manager_.getAttribute("salary", BigDecimal.class)));
-        sq2.where(cb.equal(m.get(manager_.getAttribute("department", 
-            Department.class)), 
-            emp1.get(employee_.getAttribute("department", 
-            Department.class))));
-        q.where(cb.gt(emp.get(employee_.getAttribute("salary", Long.class)), 
-            cb.all(sq)));
-        
+        sq2.where(cb.equal(m.get(manager_.getAttribute("department",
+                Department.class)), emp1.get(employee_.getAttribute(
+                "department", Department.class))));
+        q.where(cb.gt(emp.get(employee_.getAttribute("salary", Long.class)), cb
+                .all(sq)));
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT c FROM Customer c WHERE " + 
-            "(SELECT COUNT(o) FROM c.orders o) > 10";
+
+        jpql = "SELECT c FROM Customer c WHERE "
+                + "(SELECT COUNT(o) FROM c.orders o) > 10";
         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_.getSet("orders", 
-            Order.class));
+        Root<Customer> c2 = sq3.correlate(c1);
+        Join<Customer, Order> o = c2.join(customer_.getSet("orders",
+                Order.class));
         q.where(cb.gt(sq3.select(cb.count(o)), 10));
-        
+
         assertEquivalence(q, jpql);
-        
-        jpql = "SELECT o FROM Order o WHERE 10000 < ALL (" + 
-            "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
+
+        jpql = "SELECT o FROM Order o WHERE 10000 < ALL ("
+                + "SELECT a.balance FROM o.customer c JOIN c.accounts a)";
         q = cb.create();
         Root<Order> o1 = q.from(Order.class);
         q.select(o1);
         Subquery<Integer> sq4 = q.subquery(Integer.class);
         Root<Order> o2 = sq4.correlate(o1);
-        Join<Order,Customer> c3 = o2.join(order_.getAttribute("customer", 
-            Customer.class));
-        Join<Customer,Account> a = c3.join(customer_.getList("accounts", 
-            Account.class));
+        Join<Order, Customer> c3 = o2.join(order_.getAttribute("customer",
+                Customer.class));
+        Join<Customer, Account> a = c3.join(customer_.getList("accounts",
+                Account.class));
         sq4.select(a.get(account_.getAttribute("balance", Integer.class)));
         q.where(cb.lt(cb.literal(10000), cb.all(sq4)));
-        
+
         assertEquivalence(q, jpql);
 
-        jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < " +
-            "ALL (SELECT a.balance FROM c.accounts a)";
+        jpql = "SELECT o FROM Order o JOIN o.customer c WHERE 10000 < "
+                + "ALL (SELECT a.balance FROM c.accounts a)";
         q = cb.create();
         Root<Order> o3 = q.from(Order.class);
         q.select(o3);
-        Join<Order,Customer> c4 = o3.join(Order_.customer);
+        Join<Order, Customer> c4 = o3.join(Order_.customer);
         Subquery<Integer> sq5 = q.subquery(Integer.class);
-        Join<Order,Customer> c5 = sq5.correlate(c4);
-        Join<Customer,Account> a2 = c5.join(customer_.getList("accounts", 
-            Account.class));
+        Join<Order, Customer> c5 = sq5.correlate(c4);
+        Join<Customer, Account> a2 = c5.join(customer_.getList("accounts",
+                Account.class));
         sq5.select(a.get(account_.getAttribute("balance", Integer.class)));
         q.where(cb.lt(cb.literal(10000), cb.all(sq5)));
-        
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     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_.getAttribute("status", Integer.class)));
-        q.having(cb.in(c.get(customer_.getAttribute("status", Integer.class))).
-            value(1).value(2));
-        q.select(c.get(customer_.getAttribute("status", Integer.class)), 
-            cb.avg(c.get(customer_.getAttribute("filledOrderCount", 
-                Integer.class))),
-            cb.count(c));
-        
+        q.having(cb.in(c.get(customer_.getAttribute("status", Integer.class)))
+                .value(1).value(2));
+        q.select(c.get(customer_.getAttribute("status", Integer.class)), cb
+                .avg(c.get(customer_.getAttribute("filledOrderCount",
+                        Integer.class))), cb.count(c));
+
         assertEquivalence(q, jpql);
     }
-    
+
     @AllowFailure
     public void testOrdering() {
-        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";
+        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_.getSet("orders", 
-            Order.class));
-        Join<Customer,Address> a = c.join(customer_.getAttribute("address", 
-            Address.class));
-        q.where(cb.equal(a.get(address_.getAttribute("state", String.class)), 
-            "CA")); 
-        q.orderBy(cb.desc(o.get(order_.getAttribute("quantity", 
-            Integer.class))), 
-            cb.asc(o.get(order_.getAttribute("totalCost", Double.class))));
+        Join<Customer, Order> o = c.join(customer_
+                .getSet("orders", Order.class));
+        Join<Customer, Address> a = c.join(customer_.getAttribute("address",
+                Address.class));
+        q.where(cb.equal(a.get(address_.getAttribute("state", String.class)),
+                "CA"));
+        q.orderBy(cb
+                .desc(o.get(order_.getAttribute("quantity", Integer.class))),
+                cb.asc(o.get(order_.getAttribute("totalCost", Double.class))));
         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_.getSet("orders", 
-            Order.class));
-        Join<Customer,Address> a1 = c1.join(customer_.getAttribute("address", 
-            Address.class));
-        q.where(cb.equal(a1.get(address_.getAttribute("state", String.class)), 
-            "CA"));
-        q.orderBy(cb.asc(o1.get(order_.getAttribute("quantity", 
-            Integer.class))), 
-            cb.asc(a1.get(address_.getAttribute("zipCode", 
-            String.class))));
-        q.select(o1.get(order_.getAttribute("quantity", 
-            Integer.class)), 
-            a1.get(address_.getAttribute("zipCode", String.class)));
-        
+
+        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_.getSet("orders",
+                Order.class));
+        Join<Customer, Address> a1 = c1.join(customer_.getAttribute("address",
+                Address.class));
+        q.where(cb.equal(a1.get(address_.getAttribute("state", String.class)),
+                "CA"));
+        q.orderBy(cb
+                .asc(o1.get(order_.getAttribute("quantity", Integer.class))),
+                cb.asc(a1.get(address_.getAttribute("zipCode", String.class))));
+        q.select(o1.get(order_.getAttribute("quantity", Integer.class)), a1
+                .get(address_.getAttribute("zipCode", String.class)));
+
         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";
+
+        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_.getSet("orders", 
-            Order.class));
-        Join<Customer,Address> a2 = c2.join(customer_.getAttribute("address", 
-            Address.class));
-        q.where(cb.equal(a.get(address_.getAttribute("state", String.class)), 
-             "CA"),
-            cb.equal(a.get(address_.getAttribute("county", String.class)), 
-             "Santa Clara"));
-        q.orderBy(cb.asc(o.get(order_.getAttribute("quantity", 
-            Integer.class))),
-            cb.asc(cb.prod(o.get(order_.getAttribute("totalCost", 
-            Double.class)), 1.08)),
-            cb.asc(a.get(address_.getAttribute("zipCode", String.class))));
-        q.select(o.get(order_.getAttribute("quantity", Integer.class)), 
-            cb.prod(o.get(order_.getAttribute("totalCost", Double.class)), 
-             1.08),
-            a.get(address_.getAttribute("zipCode", String.class)));
-        
-        assertEquivalence(q, jpql);
-    }
+        Join<Customer, Order> o2 = c2.join(customer_.getSet("orders",
+                Order.class));
+        Join<Customer, Address> a2 = c2.join(customer_.getAttribute("address",
+                Address.class));
+        q.where(cb.equal(a.get(address_.getAttribute("state", String.class)),
+                "CA"), cb.equal(a.get(address_.getAttribute("county",
+                String.class)), "Santa Clara"));
+        q.orderBy(
+                cb.asc(o.get(order_.getAttribute("quantity", Integer.class))),
+                cb.asc(cb.prod(o.get(order_.getAttribute("totalCost",
+                        Double.class)), 1.08)), cb.asc(a.get(address_
+                        .getAttribute("zipCode", String.class))));
+        q.select(o.get(order_.getAttribute("quantity", Integer.class)), cb
+                .prod(o.get(order_.getAttribute("totalCost", Double.class)),
+                        1.08), a.get(address_.getAttribute("zipCode",
+                String.class)));
 
-    void assertEquivalence(CriteriaQuery c, String jpql) {
-        sql.clear();
-        List cList = em.createQuery(c).getResultList();
-        assertEquals(1, sql.size());
-        String cSQL = sql.get(0);
-        
-        sql.clear();
-        List jList = em.createQuery(jpql).getResultList();
-        assertEquals(1, sql.size());
-        String jSQL = sql.get(0);
-        
-        assertEquals(jSQL, cSQL);
-    }
-    
-    void assertEquivalence(CriteriaQuery c, String jpql, String[] paramNames, 
-        Object[] params) {
-        sql.clear();
-        Query q = em.createQuery(c);
-        for (int i = 0; i < paramNames.length; i++) {
-            q.setParameter(paramNames[i], params[i]);
-        }
-        List cList = q.getResultList();
-        assertEquals(1, sql.size());
-        String cSQL = sql.get(0);
-        
-        sql.clear();
-        q = em.createQuery(jpql);
-        for (int i = 0; i < paramNames.length; i++) {
-            q.setParameter(paramNames[i], params[i]);
-        }
-        List jList = q.getResultList();
-        assertEquals(1, sql.size());
-        String jSQL = sql.get(0);
-        
-        assertEquals(jSQL, cSQL);
+        assertEquivalence(q, jpql);
     }
-
 }

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=783166&r1=783165&r2=783166&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 10 00:41:35 2009
@@ -61,75 +61,27 @@
  */
 
 public class TestTypeSafeCondExpression extends CriteriaTest {
-
-    private int userid1, userid2, userid3, userid4, userid5;
-    public void setUp() {
-        // super setUp() initializes a fixed domain model
-        super.setUp((Object[])null); 
-        createData();
-    }
     
-    void createData() {
-        Address[] add =
-            new Address[]{ new Address("43 Sansome", "SF", "USA", "94104"),
-                new Address("24 Mink", "ANTIOCH", "USA", "94513"),
-                new Address("23 Ogbete", "CoalCamp", "NIGERIA", "00000"),
-                new Address("10 Wilshire", "Worcester", "CANADA", "80080"),
-                new Address("23 Bellflower", "Ogui", "NIGERIA", "02000") };
-
-        CompUser user1 = createUser("Seetha", "MAC", add[0], 40, true);
-        CompUser user2 = createUser("Shannon", "PC", add[1], 36, false);
-        CompUser user3 = createUser("Ugo", "PC", add[2], 19, true);
-        CompUser user4 = createUser("Jacob", "LINUX", add[3], 10, true);
-        CompUser user5 = createUser("Famzy", "UNIX", add[4], 29, false);
-
-        startTx(em);
-        em.persist(user1);
-        userid1 = user1.getUserid();
-        em.persist(user2);
-        userid2 = user2.getUserid();
-        em.persist(user3);
-        userid3 = user3.getUserid();
-        em.persist(user4);
-        userid4 = user4.getUserid();
-        em.persist(user5);
-        userid5 = user5.getUserid();
-
-        endTx(em);
-        em.clear();
-    }
-
     public void testNothingUsingCriteria() {
         String query = "SELECT o FROM CompUser o";
+        
         CriteriaQuery c = cb.create();
         c.from(CompUser.class);
         assertEquivalence(c, query);
-        List result = em.createQuery(c).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("the size of the list is not 5", 5, result.size());
-
-        em.clear();
     }
 
     public void testBetweenExprUsingCriteria() {
         String query =
             "SELECT o.name FROM CompUser o WHERE o.age BETWEEN 19 AND 40 AND " +
             "o.computerName = 'PC'";
-        CriteriaQuery q = cb.create();
-        Root<CompUser> c = q.from(CompUser.class);
-        q.where(cb.and(cb.between(c.get(CompUser_.age), 19, 40), 
-                cb.equal(c.get(CompUser_.computerName), "PC")));
-        q.select(c.get(CompUser_.name));
-        assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("they are not equal", 2, result.size());
-        assertTrue("result dont contain shannon", result.contains("Shannon"));
-        assertTrue("result dont contain ugo", result.contains("Ugo"));
-
-        em.clear();
+        
+        CriteriaQuery cq = cb.create();
+        Root<CompUser> o = cq.from(CompUser.class);
+        cq.where(cb.and(cb.between(o.get(CompUser_.age), 19, 40), 
+                cb.equal(o.get(CompUser_.computerName), "PC")));
+        cq.select(o.get(CompUser_.name));
+        
+        assertEquivalence(cq, query);
     }
 
     public void testNotBetweenExprUsingCriteria() {
@@ -142,13 +94,8 @@
         q.where(cb.and(cb.between(c.get(CompUser_.age), 19, 40).negate(), 
                 cb.equal(c.get(CompUser_.computerName), "PC")));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("they are not equal", 0, result.size());
-
-        em.clear();
     }
 
     public void testInExprUsingCriteria() {
@@ -158,16 +105,8 @@
         Root<CompUser> c = q.from(CompUser.class);
         q.where(cb.in(c.get(CompUser_.age)).value(29).value(40).value(10));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals(3, result.size());
-        assertTrue("seetha is not in the list", result.contains("Seetha"));
-        assertTrue("jacob is not in the list", result.contains("Jacob"));
-        assertTrue("famzy is not in the list", result.contains("Famzy"));
-
-        em.clear();
     }
 
     public void testNotInUsingCriteria() {
@@ -179,22 +118,14 @@
         q.where(cb.in(c.get(CompUser_.age)).value(29).value(40).value(10)
             .negate());
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(2, result.size());
-        assertTrue(result.contains("Ugo"));
-        assertTrue(result.contains("Shannon"));
-
-        em.clear();
     }
 
     public void testLikeExprUsingCriteria1() {
         String query =
             "SELECT o.computerName FROM CompUser o WHERE o.name LIKE 'Sha%'" +
-            " AND " + 
-            "o.computerName NOT IN ('PC')";
+            " AND o.computerName NOT IN ('PC')";
 
         CriteriaQuery q = cb.create();
         Root<CompUser> c = q.from(CompUser.class);
@@ -204,12 +135,8 @@
                 ));
         
         q.select(c.get(CompUser_.computerName));
-        assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
 
-        assertNotNull(result);
-        assertEquals(0, result.size());
-        em.clear();
+        assertEquivalence(q, query);
     }
     
     public void testLikeExprUsingCriteria2() {
@@ -225,12 +152,8 @@
                     cb.in(c.get(CompUser_.computerName)).value("UNIX").negate()
                 ));
         q.select(c.get(CompUser_.computerName));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        em.clear();
     }
     
     public void testLikeExprUsingCriteria3() {
@@ -240,12 +163,8 @@
         Root<CompUser> c = q.from(CompUser.class);
         q.where(cb.like(c.get(CompUser_.name),"_J%"));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull(result);
-        assertEquals(0, result.size());
-        em.clear();
     }
     
     @AllowFailure(message="Parameter processing is broken")
@@ -257,13 +176,8 @@
         Parameter<String> param = cb.parameter(String.class);
         q.where(cb.like(c.get(CompUser_.name), param, '|'));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query, new Object[] {"%|_%"});
-        List result = em.createQuery(q).setParameter(1, "%|_%").getResultList();
-
-        assertNotNull(result);
-        assertEquals(0, result.size());
-
-        em.clear();
     }
 
     public void testNullExprUsingCriteria() {
@@ -276,16 +190,8 @@
         q.where(cb.and(cb.notEqual(c.get(CompUser_.age), null), 
                 cb.equal(c.get(CompUser_.computerName), "PC")));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("the list size is not 2", 2, result.size());
-        assertTrue("the result doesnt contain ugo", result.contains("Ugo"));
-        assertTrue("the result doesnt contain shannon",
-            result.contains("Shannon"));
-
-        em.clear();
     }
     
     public void testNullExpr2UsingCriteria() {
@@ -298,13 +204,8 @@
         q.where(cb.equal(c.get(CompUser_.address).get(Address_.country),
             null));
         q.select(c.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("they are not equal", 0, result.size());
-
-        em.clear();
     }
     
     // do not support isEmpty for array fields
@@ -313,20 +214,15 @@
         String query =
             "SELECT o.name FROM CompUser o WHERE o.nicknames IS NOT EMPTY";
 
-        CriteriaQuery q = cb.create();
-        Root<CompUser> c = q.from(CompUser.class);
-        //q.where(cb.isNotEmpty(c.get(CompUser_.nicknames)));
-        q.select(c);
-        assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("the list is null", result);
-        assertEquals("they are not equal", 0, result.size());
-
-        em.clear();
+        CriteriaQuery cq = cb.create();
+        Root<CompUser> o = cq.from(CompUser.class);
+        cq.select(o.get(CompUser_.name));
+        cq.where(cb.isNotEmpty(o.get(CompUser_.nicknames)));
+        assertEquivalence(cq, query);
     }
 
-    @AllowFailure
+    @AllowFailure(message="Address is embeddable. Can it be in " +
+    		"subquery/From Clause?")
     public void testExistExprUsingCriteria() {
         String query = "SELECT DISTINCT o.name FROM CompUser o WHERE EXISTS" +
             " (SELECT c FROM Address c WHERE c = o.address )";
@@ -370,19 +266,14 @@
                 o.get(CompUser_.address).get(Address_.country)));
         q.where(cb.exists(sq).negate());
         q.select(o.get(CompUser_.name)).distinct(true);
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("list is null", result);
-        assertEquals("they are not equal", 0, result.size());
-
-        em.clear();
     }
 
     @AllowFailure
     public void testAnyExprUsingCriteria() {
         String query =
-            "SELECT o.name FROM CompUser o WHERE o.address.zipcode = ANY (" +
+            "SELECT o.name FROM CompUser o WHERE o.address.zipCode = ANY (" +
                 " SELECT s.computerName FROM CompUser s WHERE " +
                 "s.address.country IS NOT NULL )";
 
@@ -396,38 +287,26 @@
             null));
         q.where(cb.equal(o.get(CompUser_.address).get(Address_.zipCode), 
             cb.any(sq)));
+        
         assertEquivalence(q, query);
-        List result = em.createQuery(q).getResultList();
-
-        assertNotNull("list is null", result);
-        assertEquals("they are not equal", 0, result.size());
-
-        em.clear();
     }
     
+    @AllowFailure(message="ResultPacker is all confused")
     public void testConstructorExprUsingCriteria() {
         String query =
             "SELECT NEW org.apache.openjpa.persistence.common.apps.MaleUser(" +
             "c.name, c.computerName, c.address, c.age, c.userid)" +
             " FROM CompUser c WHERE c.name = 'Seetha'";
+        
         CriteriaQuery q = cb.create();
-        q = cb.create();
         Root<CompUser> c = q.from(CompUser.class);
         q.where(cb.equal(c.get(CompUser_.name), "Seetha"));
         q.select(cb.select(MaleUser.class, c.get(CompUser_.name), 
             c.get(CompUser_.computerName), c.get(CompUser_.address),
             c.get(CompUser_.age), c.get(CompUser_.userid)));
         
-        MaleUser male = (MaleUser) em.createQuery(q).getSingleResult();
-
-        assertNotNull("the list is null", male);
-        assertEquals("the names dont match", "Seetha", male.getName());
-        assertEquals("computer names dont match", "MAC",
-            male.getComputerName());
-        assertEquals("the ages dont match", 40, male.getAge());
-
-        em.clear();
-    }
+        assertEquivalence(q, query);
+   }
 
     public void testConcatSubStringFunc1() {
         String query = "select " +
@@ -446,8 +325,8 @@
              )
         );
         q.where(cb.equal(e.get(CompUser_.name), "Seetha"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
     
     public void testConcatSubStringFunc2() {
@@ -459,18 +338,12 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(e.get(CompUser_.address));
         q.where(cb.and(cb.equal(e.get(CompUser_.name), "Seetha"),
-                cb.equal(
-                e.get(CompUser_.computerName),
+                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)
-                     )
-                )))
-             );
+                    cb.substring(e.get(CompUser_.name), 
+                    cb.locate(e.get(CompUser_.name), "e"), cb.literal(4))))));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testConcatSubStringFunc3() {
@@ -480,17 +353,11 @@
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
-        q.select(
-            cb.concat("XYZ", 
-                cb.substring(
-                    e.get(CompUser_.name), 
-                    cb.locate(e.get(CompUser_.name), "e") 
-                )
-            )
-        );
+        q.select(cb.concat("XYZ", cb.substring(e.get(CompUser_.name), 
+                 cb.locate(e.get(CompUser_.name), "e"))));
         q.where(cb.equal(e.get(CompUser_.name), "Ablahumeeth"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testConcatSubStringFunc4() {
@@ -502,17 +369,11 @@
         Root<CompUser> e = q.from(CompUser.class);
         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") 
-                    )
-                )))
-            );
+                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();
     }
 
     public void testConcatFunc() {
@@ -523,8 +384,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.concat("", cb.literal("")));
         q.where(cb.equal(e.get(CompUser_.name), "Seetha"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testTrimFunc1() {
@@ -535,8 +396,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.trim(e.get(CompUser_.computerName)));
         q.where(cb.equal(e.get(CompUser_.name), "Shannon "));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testTrimFunc2() {
@@ -547,8 +408,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.where(cb.equal(cb.trim(e.get(CompUser_.name)), "Shannon"));
         q.select(e.get(CompUser_.computerName));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testLowerFunc1() {
@@ -559,8 +420,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.lower(e.get(CompUser_.name)));
         q.where(cb.equal(e.get(CompUser_.computerName), "UNIX"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testLowerFunc2() {
@@ -571,8 +432,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.where(cb.equal(cb.lower(e.get(CompUser_.name)), "ugo"));
         q.select(e.get(CompUser_.age));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testUpperFunc1() {
@@ -583,8 +444,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.upper(e.get(CompUser_.name)));
         q.where(cb.equal(e.get(CompUser_.computerName), "PC"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testUpperFunc2() {
@@ -595,8 +456,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.where(cb.equal(cb.upper(e.get(CompUser_.name)), "UGO"));
         q.select(e.get(CompUser_.age));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testLengthFunc() {
@@ -608,8 +469,8 @@
         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();
     }
 
     public void testArithmFunc1() {
@@ -620,8 +481,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.abs(e.get(CompUser_.age)));
         q.where(cb.equal(e.get(CompUser_.name), "Seetha"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
     
     public void testArithmFunc2() {
@@ -632,8 +493,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.sqrt(e.get(CompUser_.age)));
         q.where(cb.equal(e.get(CompUser_.name), "Seetha"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
     
     @AllowFailure
@@ -645,12 +506,12 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.mod(e.get(CompUser_.age), 4));
         q.where(cb.equal(e.get(CompUser_.name), "Seetha"));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
     
     // size method can not be applied to an array field
-    @AllowFailure
+    @AllowFailure(message="size method can not be applied to an array field?")
     public void testArithmFunc4() {
         String query = "SELECT e.name FROM CompUser e WHERE " +
         		"SIZE(e.nicknames) = 6";
@@ -659,8 +520,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         //q.where(cb.equal(cb.size(e.get(CompUser_.nicknames)), 6));
         q.select(e.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testGroupByHavingClause() {
@@ -674,8 +535,8 @@
         q.groupBy(e.get(CompUser_.name));
         q.having(cb.like(e.get(CompUser_.name), "S%"));
         q.select(e.get(CompUser_.name));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testOrderByClause() {
@@ -689,19 +550,20 @@
         q.where(cb.like(e.get(CompUser_.name), "S%"));
         q.select(e.get(CompUser_.name));
         q.orderBy(cb.asc(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testAVGAggregFunc() {
         //To be Tested: AVG, COUNT, MAX, MIN, SUM
         String query = "SELECT AVG(e.age) FROM CompUser e";
+        
         CriteriaQuery q = cb.create();
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.avg(e.get(CompUser_.age)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testCOUNTAggregFunc() {
@@ -711,8 +573,8 @@
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.count(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testMAXAggregFunc() {
@@ -722,8 +584,8 @@
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.max(e.get(CompUser_.age))).distinct(true);
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     @AllowFailure(message="criteria does not generate Optimize for 1 row")
@@ -734,8 +596,8 @@
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.min(e.get(CompUser_.age))).distinct(true);
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testSUMAggregFunc() {
@@ -745,8 +607,8 @@
         q = cb.create();
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.sum(e.get(CompUser_.age)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     // can not do TYPE with parameter in the IN clause
@@ -762,8 +624,8 @@
         Parameter<Class> param2 = cb.parameter(Class.class);
         // q.where(cb.in(e.type()).value(param1).value(param2));
         q.orderBy(cb.asc(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     @AllowFailure
@@ -775,8 +637,8 @@
         Parameter<Class> param1 = cb.parameter(Class.class);
         q.select(e.type());
         q.where(cb.equal(e.type(), param1).negate());
-        assertEquivalence(q, query, new Object[] { MaleUser.class });
-        em.clear();
+        
+        assertEquivalence(q, query);
     }
 
     // Type literal
@@ -791,64 +653,63 @@
         // Join<Address,FemaleUser> e = a.join(Address_.user);
         // q.select(cb.literal(FemaleUser.class), e.get(CompUser_.address));
         // q.where(cb.equal(e.type(), null).negate());
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testTypeExpression4() {
         String query = "SELECT e FROM CompUser e where TYPE(e) = MaleUser";
-        CriteriaQuery q = cb.create();
-        q = cb.create();
-        Root<CompUser> e = q.from(CompUser.class);
-        q.select(e);
-        q.where(cb.equal(e.type(), cb.literal(MaleUser.class)));
-        assertEquivalence(q, query);
-        em.clear();
+        
+        CriteriaQuery cq = cb.create();
+        Root<CompUser> e = cq.from(CompUser.class);
+        cq.select(e);
+        cq.where(cb.equal(e.type(), cb.literal(MaleUser.class)));
+        
+        assertEquivalence(cq, query);
     }
 
     public void testTypeExpression5() {
         String query = "SELECT e FROM CompUser e where TYPE(e) in (MaleUser)";
-        CriteriaQuery q = cb.create();
-        q = cb.create();
-        Root<CompUser> e = q.from(CompUser.class);
-        q.select(e);
-        q.where(cb.in(e.type()).value(MaleUser.class));
-        assertEquivalence(q, query);
-        em.clear();
+        
+        CriteriaQuery cq = cb.create();
+        Root<CompUser> e = cq.from(CompUser.class);
+        cq.select(e);
+        cq.where(cb.in(e.type()).value(MaleUser.class));
+        
+        assertEquivalence(cq, query);
     }
 
     public void testTypeExpression6() {
         String query = "SELECT e FROM CompUser e where TYPE(e) not in " +
             "(MaleUser, FemaleUser)";
-        CriteriaQuery q = cb.create();
-        q = cb.create();
-        Root<CompUser> e = q.from(CompUser.class);
-        q.select(e);
-        q.where(cb.in(e.type()).value(MaleUser.class).value(FemaleUser.class)
+        
+        CriteriaQuery cq = cb.create();
+        Root<CompUser> e = cq.from(CompUser.class);
+        cq.select(e);
+        cq.where(cb.in(e.type()).value(MaleUser.class).value(FemaleUser.class)
                 .negate());
-        assertEquivalence(q, query);
-        em.clear();
+        
+        assertEquivalence(cq, query);
     }
 
     @AllowFailure
     public void testTypeExpression7() {
-        String query = "SELECT TYPE(a.user) FROM Address a";
+        String query = "SELECT TYPE(a.b) FROM A a";
         CriteriaQuery q = cb.create();
-        q = cb.create();
-        Root<Address> a = q.from(Address.class);
-        q.select(a.get(Address_.user).type());
+        Root<A> a = q.from(A.class);
+        q.select(a.get(A_.b).type());
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testTypeExpression8() {
-        String query = "SELECT MaleUser FROM Address a";
+        String query = "SELECT MaleUser FROM A a";
+        
         CriteriaQuery q = cb.create();
-        q = cb.create();
-        Root<Address> a = q.from(Address.class);
+        Root<A> a = q.from(A.class);
         q.select(cb.literal(MaleUser.class));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testTypeExpression9() {
@@ -859,9 +720,8 @@
         Root<CompUser> e = q.from(CompUser.class);
         q.select(cb.selectCase(e.type()).when(FemaleUser.class, "Female")
                 .otherwise("Male"));
+        
         assertEquivalence(q, query);
-
-        em.clear();
     }
 
     public void testCoalesceExpressions() {
@@ -875,8 +735,8 @@
                 e.get(CompUser_.address).get(Address_.country))
                 .value("Unknown"));
         q.orderBy(cb.desc(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testNullIfExpressions() {
@@ -887,8 +747,8 @@
         q.select(e.get(CompUser_.name), cb.nullif(e.get(CompUser_.address).get(
                 Address_.country), "USA"));
         q.orderBy(cb.desc(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
-        em.clear();
     }
 
     public void testSimpleCaseExpression1() {
@@ -904,6 +764,7 @@
                 "us").otherwise("non-us");
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
+        
         assertEquivalence(q, query);
     }
 
@@ -922,6 +783,7 @@
                 e.get(CompUser_.address).get(Address_.country));
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
+        
         assertEquivalence(q, query);
     }
 
@@ -938,6 +800,7 @@
             .otherwise("Male"));
         q.where(cb.like(e.get(CompUser_.name), "S%"));
         q.orderBy(cb.desc(e.get(CompUser_.name)));
+        
         assertEquivalence(q, query);
     }
 
@@ -952,6 +815,7 @@
                 true).otherwise(false);
         q.select(e.get(CompUser_.name), b, e.get(CompUser_.address).get(
                 Address_.country));
+        
         assertEquivalence(q, query);
     }
 
@@ -968,6 +832,7 @@
                 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);
+
         assertEquivalence(q, query);
     }
 
@@ -989,6 +854,7 @@
         Expression cage = cb.sum(e.get(CompUser_.age), 1);
         q.select(e.get(CompUser_.name), cage, d2, e.get(CompUser_.address).get(
                 Address_.country));
+
         assertEquivalence(q, query);
     }
 
@@ -1013,6 +879,7 @@
                         CompUser.CreditRating.EXCELLENT));
 
         q.orderBy(cb.asc(e.get(CompUser_.age)));
+
         assertEquivalence(q, query);
     }
 
@@ -1051,19 +918,16 @@
                         CompUser.CreditRating.EXCELLENT)));
 
         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 Ugo", "Ugo", result[0]);
-        assertEquals("the credit rating is not 'EXCELLENT'", "EXCELLENT",
-                ((CompUser.CreditRating) result[1]).name());
     }
 
     @AllowFailure
     public void testSubquery1() {
         String query = "select o1.id from Order o1 where o1.id in "
                 + " (select distinct o.id from LineItem i, Order o"
-                + " where i.quantity > 10 and o.count > 1000 and i.lid = o.id)";
+                + " where i.quantity > 10 and o.count > 1000 and i.id = o.id)";
+        
         CriteriaQuery q = cb.create();
         Root<Order> o1 = q.from(Order.class);
         q.select(o1.get(Order_.id));
@@ -1077,6 +941,7 @@
         sq.select(o.get(Order_.id)).distinct(true);
         q.where(cb.in(o1.get(Order_.id)).value(
                 sq.select(o.get(Order_.id)).distinct(true)));
+        
         assertEquivalence(q, query);
     }
 
@@ -1095,6 +960,7 @@
         q.where(cb.equal(o.get(Order_.customer).get(Customer_.balanceOwed), sq
                 .select(cb.max(o2.get(Order_.customer).get(
                         Customer_.balanceOwed)))));
+        
         assertEquivalence(q, query);
     }
 
@@ -1113,13 +979,14 @@
         q.where(cb.equal(o.get(Order_.customer).get(Customer_.balanceOwed), sq
                 .select(cb.max(o2.get(Order_.customer).get(
                         Customer_.balanceOwed)))));
+        
         assertEquivalence(q, query);
     }
 
     @AllowFailure
     public void testSubquery4() {
         String query = "select o.id from Order o where o.quantity >"
-                + " (select count(i) from o.lineitems i)";
+                + " (select count(i) from o.lineItems i)";
         CriteriaQuery q = cb.create();
         Root<Order> o = q.from(Order.class);
         q.select(o.get(Order_.id));
@@ -1141,6 +1008,7 @@
         Root<Order> o2 = sq.from(Order.class);
         q.where(cb.gt(o.get(Order_.quantity), sq.select(cb.count(o2
                 .get(Order_.quantity)))));
+        
         assertEquivalence(q, query);
     }
 
@@ -1155,6 +1023,7 @@
         Root<Order> o2 = sq.from(Order.class);
         q.where(cb.gt(o.get(Order_.quantity), sq.select(cb.count(o2
                 .get(Order_.id)))));
+        
         assertEquivalence(q, query);
     }
 
@@ -1169,6 +1038,7 @@
         Root<Order> o2 = sq.from(Order.class);
         q.where(cb.gt(o.get(Order_.quantity), sq.select(cb.avg(o2
                 .get(Order_.quantity)))));
+        
         assertEquivalence(q, query);
     }
 
@@ -1191,6 +1061,7 @@
         sq2.where(cb.equal(o2.get(Order_.id), 2)).select(o2);
 
         q.where(cb.or(cb.exists(sq1), cb.exists(sq2)));
+        
         assertEquivalence(q, query);
     }
 
@@ -1216,6 +1087,7 @@
         // not sure how to do call between of integer(quantity)
         // between integer (max quantity) and double (avg quantity)
         // q.where(cb.between(o.get(Order_.quantity), sq1, sq2));
+        
         assertEquivalence(q, query);
     }
 
@@ -1234,6 +1106,7 @@
         sq.select(cb.sum(o2.get(Order_.quantity)));
 
         q.where(cb.gt(o2.get(Order_.quantity), sq));
+        
         assertEquivalence(q, query);
     }
 
@@ -1278,6 +1151,7 @@
         SetJoin<Customer, Order> o2 = sqc.join(Customer_.orders);
         sq.select(cb.sum(o2.get(Order_.quantity)));
         q.where(cb.gt(o.get(Order_.quantity), sq));
+        
         assertEquivalence(q, query);
     }
 
@@ -1297,6 +1171,7 @@
         sq.select(o2.get(Order_.quantity));
 
         q.where(cb.equal(o1.get(Order_.quantity), cb.any(sq)));
+        
         assertEquivalence(q, query);
     }
 
@@ -1330,6 +1205,7 @@
             Publisher_.id), p.get(Publisher_.id)), cb.equal(m2
             .get(Magazine_.datePublished), sq2.select(cb.max(m3
             .get(Magazine_.id))))));
+        
         assertEquivalence(q, query);
     }
 
@@ -1365,12 +1241,13 @@
                         .otherwise(false)
         // )
                 ));
+        
         assertEquivalence(q, query);
     }
 
     @AllowFailure
     public void testSubquery16() {
-        String query = "select o1.oid from Order o1 where o1.quantity > "
+        String query = "select o1.id from Order o1 where o1.quantity > "
                 + " (select o.quantity*2 from LineItem i, Order o"
                 + " where i.quantity > 10 and o.quantity > 1000 and i.id = " +
                 		"o.id)";
@@ -1415,7 +1292,7 @@
     @AllowFailure
     public void testSubquery18() {
         String query = "select o.id from Order o where o.orderTs >"
-                + " (select CURRENT_TIMESTAMP from o.lineitems i)";
+                + " (select CURRENT_TIMESTAMP from o.lineItems i)";
         CriteriaQuery q = cb.create();
         Root<Order> o = q.from(Order.class);
         q.select(o.get(Order_.id));
@@ -1427,6 +1304,7 @@
         // q.where(cb.gt(
         // o.get(Order_.orderTs),
         // sq.select(cb.currentTimestamp())));
+        
         assertEquivalence(q, query);
     }
 
@@ -1569,30 +1447,4 @@
             + "AND d.id.effDate < :maxDate ";
     }
 
-    void startTx(EntityManager em) {
-        em.getTransaction().begin();
-    }
-    
-    void endTx(EntityManager em) {
-        em.getTransaction().commit();
-    }
-    
-    public CompUser createUser(String name, String cName, Address add, int age,
-        boolean isMale) {
-        CompUser user = null;
-        if (isMale) {
-            user = new MaleUser();
-            user.setName(name);
-            user.setComputerName(cName);
-            user.setAddress(add);
-            user.setAge(age);
-        } else {
-            user = new FemaleUser();
-            user.setName(name);
-            user.setComputerName(cName);
-            user.setAddress(add);
-            user.setAge(age);
-        }
-        return user;
-	}
 }

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=783166&r1=783165&r2=783166&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 10 00:41:35 2009
@@ -44,7 +44,7 @@
  * 
  */
 public class TestTypesafeCriteria extends CriteriaTest {
-
+    
     public void testExplictRoot() {
         String jpql = "select a from Account a";
         CriteriaQuery c = cb.create();
@@ -183,20 +183,30 @@
         assertEquivalence(c, jpql);
     }
 
+    public void testMultipartNavigation() {
+        String jpql = "select a from A a where a.b.age=22";
+        
+        CriteriaQuery cq = cb.create();
+        Root<A> a = cq.from(A.class);
+        cq.where(cb.equal(a.get(A_.b).get(B_.age), 22));
+        
+        assertEquivalence(cq, jpql);
+    }
+    
     @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'";
 
-        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)
+        CriteriaQuery cq = cb.create();
+        Root<Customer> c = cq.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        Join<Order, LineItem> i = o.join(Order_.lineItems);
+        cq.select(c)
+            .where(cb.equal(i.get(LineItem_.product)
             .get(Product_.productType), "printer"));
 
-        assertEquivalence(c, jpql);
+        assertEquivalence(cq, jpql);
     }
 
     public void testJoinsNotPresentInWhereClause() {
@@ -228,15 +238,16 @@
         String jpql = "SELECT p.vendor FROM Employee e JOIN "
             + "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(
+        
+        CriteriaQuery cq = cb.create();
+        Root<Employee> e = cq.from(Employee.class);
+        Join<Contact, Phone> p = e.join(Employee_.contactInfo).join(
                 Contact_.phones);
-        q.where(cb.equal(emp.get(Employee_.contactInfo).get(Contact_.address)
+        cq.where(cb.equal(e.get(Employee_.contactInfo).get(Contact_.address)
                 .get(Address_.zipCode), "95054"));
-        q.select(phone.get(Phone_.vendor));
+        cq.select(p.get(Phone_.vendor));
 
-        assertEquivalence(q, jpql);
+        assertEquivalence(cq, jpql);
     }
 
     @AllowFailure(message = "Key expression not implemented")
@@ -281,18 +292,19 @@
     @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"
+            + "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));
+        
+        CriteriaQuery cq = cb.create();
+        Root<Customer> c = cq.from(Customer.class);
+        Join<Customer, Order> o = c.join(Customer_.orders);
+        Join<Customer, Address> a = c.join(Customer_.address);
+        cq.where(cb.equal(a.get(Address_.state), "CA"), 
+                 cb.equal(a.get(Address_.county), "Santa Clara"));
+        cq.select(o.get(Order_.quantity), cb.prod(o
+                .get(Order_.totalCost), 1.08), a.get(Address_.zipCode));
 
-        assertEquivalence(q, jpql);
+        assertEquivalence(cq, jpql);
     }
 
     public void testTypeExpression() {



Mime
View raw message