openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r835961 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/
Date Fri, 13 Nov 2009 19:29:49 GMT
Author: ppoddar
Date: Fri Nov 13 19:29:48 2009
New Revision: 835961

URL: http://svn.apache.org/viewvc?rev=835961&view=rev
Log:
Use decorator pattern for Criteria Query tests

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestDateStringConversion.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.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

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestDateStringConversion.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestDateStringConversion.java?rev=835961&r1=835960&r2=835961&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestDateStringConversion.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestDateStringConversion.java
Fri Nov 13 19:29:48 2009
@@ -23,6 +23,7 @@
 import java.sql.Timestamp;
 import java.util.List;
 
+import javax.persistence.Query;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Root;
 
@@ -103,7 +104,7 @@
         
         Date earlier = new Date(now - 1000);
         
-        String dateString = createJDBCEscapeString(earlier);
+        final String dateString = createJDBCEscapeString(earlier);
         String jpql = "select d from Dependent d where d.endDate >= :dateString ORDER
BY d.endDate";
         CriteriaQuery<Dependent> c = cb.createQuery(Dependent.class);
         Root<Dependent> d = c.from(Dependent.class);
@@ -112,7 +113,12 @@
                 .as(Date.class)));
         c.orderBy(cb.asc(d.get(Dependent_.endDate)));
         
-        assertEquivalence(c, jpql, new String[]{"dateString"}, new Object[]{dateString});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("dateString", dateString);
+            }
+        }, c, jpql);
+
     }
     
     String createJDBCEscapeString(Object time) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java?rev=835961&r1=835960&r2=835961&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java
Fri Nov 13 19:29:48 2009
@@ -23,6 +23,7 @@
 import java.util.Set;
 
 import javax.persistence.Parameter;
+import javax.persistence.Query;
 import javax.persistence.Tuple;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
@@ -1158,7 +1159,11 @@
         q.multiselect(e, e.get(Embed_Embed_.intVal1), e.get(Embed_Embed_.embed).get(Embed_.intVal2));
         ParameterExpression<Embed_Embed> param1 = cb.parameter(Embed_Embed.class, "embed2");
         q.where(cb.isMember(param1, a.get(EntityA_Coll_Embed_Embed_.embeds)));
-        assertEquivalence(q, jpql, new String[]{"embed2"}, new Object[]{new Embed_Embed()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("embed2", new Embed_Embed());
+            }
+        }, q, jpql);
     }
     
     @AllowFailure(message="JPQL parse error")
@@ -1172,7 +1177,12 @@
         q.multiselect(e, e.get(Embed_Embed_.intVal1), e.get(Embed_Embed_.embed).get(Embed_.intVal2));
         ParameterExpression<Embed_Embed> param1 = cb.parameter(Embed_Embed.class, "embed2");
         q.where(cb.isMember(param1, a.get(EntityA_Coll_Embed_Embed_.embeds)));
-        assertEquivalence(q, jpql, new String[]{"embed2"}, new Object[]{new Embed_Embed()});
+        
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("embed2", new Embed_Embed());
+            }
+        }, q, jpql);
     }
     
     @AllowFailure(message="JPQL parse error")
@@ -1186,7 +1196,11 @@
         q.multiselect(e, e.get(Embed_Embed_.intVal1), e.get(Embed_Embed_.embed).get(Embed_.intVal2));
         Parameter<Embed_Embed> param1 = cb.parameter(Embed_Embed.class);
         //q.where(cb.equal(param1, e));
-        assertEquivalence(q, jpql, new String[]{"embed2"}, new Object[]{new Embed_Embed()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("embed2", new Embed_Embed());
+            }
+        }, q, jpql);
     }
 
     public void testEmbeddableQuery87() {
@@ -1489,7 +1503,11 @@
         ParameterExpression<String> param1 = cb.parameter(String.class, "image");
         q.where(cb.equal(param1, cb.any(sq)));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery112() {
@@ -1505,7 +1523,11 @@
         ParameterExpression<String> param1 = cb.parameter(String.class, "image");
         q.where(cb.equal(param1, cb.any(sq)));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery113() {
@@ -1522,7 +1544,11 @@
         sq.where(cb.equal(param1, e.key()));
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
      
     public void testEmbeddableQuery114() {
@@ -1538,7 +1564,11 @@
         ParameterExpression<String> param1 = cb.parameter(String.class, "image");
         q.where(cb.equal(param1, cb.any(sq)));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery115() {
@@ -1555,7 +1585,11 @@
         sq.where(cb.equal(param1, e.key()));
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery116() {
@@ -1571,7 +1605,11 @@
         ParameterExpression<String> param1 = cb.parameter(String.class, "image");
         q.where(cb.equal(param1, cb.any(sq)));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery117() {
@@ -1588,7 +1626,11 @@
         sq.where(cb.equal(param1, e.key()));
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(i));
-        assertEquivalence(q, jpql, new String[]{"image"}, new String[]{"my photo"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("image", "my photo");
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery118() {
@@ -1621,7 +1663,11 @@
         sq.where(cb.equal(d.value().get(VicePresident_.id), 1));
         q.where(cb.equal(param1, sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"division"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("division", new Division());
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery122() {
@@ -1638,7 +1684,11 @@
         sq.select(d.key());
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"division"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("division", new Division());
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery123() {
@@ -1655,7 +1705,11 @@
         sq.where(cb.equal(d.key(), param1));
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"division"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("division", new Division());
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery124() {
@@ -1672,7 +1726,11 @@
         sq.where(cb.equal(d.value().get(VicePresident_.id), 3));
         q.where(cb.equal(param1, sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"division"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("division", new Division());
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery125() {
@@ -1689,7 +1747,11 @@
         sq.select(d.key());
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"k"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("k", new Division());
+            }
+        }, q, jpql);
     }
     
     public void testEmbeddableQuery126() {
@@ -1706,7 +1768,11 @@
         sq.select(d.value());
         q.where(cb.exists(sq));
         q.orderBy(cb.asc(c));
-        assertEquivalence(q, jpql, new String[]{"k"}, new Object[]{new Division()});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("k", new Division());
+            }
+        }, q, jpql);
     }
 
     public void testEmbeddableQuery127() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java?rev=835961&r1=835960&r2=835961&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestJPQLSubquery.java
Fri Nov 13 19:29:48 2009
@@ -34,6 +34,9 @@
 import javax.persistence.criteria.SetJoin;
 import javax.persistence.criteria.Subquery;
 
+import org.apache.openjpa.persistence.criteria.AbstractCriteriaTestCase.QueryDecorator;
+import org.apache.openjpa.persistence.embed.Division;
+
 /**
  * Tests type-strict version of Criteria API.
  * 
@@ -1499,10 +1502,13 @@
         Predicate p4 = cb.lessThan(d.get(Dependent_.id).get(DependentId_.effDate), maxDate);
         
         q.where(cb.and(cb.and(cb.and(p1, p2), p3), p4));
-        
-        assertEquivalence(q, jpql, 
-            new String[]{"empid", "minDate", "maxDate"}, 
-            new Object[]{101L, new Date(100), new Date(100000)});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("empid",   101L);
+                q.setParameter("minDate", new Date(100));
+                q.setParameter("maxDate", new Date(100000));
+            }
+        }, q, jpql);
     }
     
     public void testCorrelatedNestedSubquery1() {

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=835961&r1=835960&r2=835961&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
Fri Nov 13 19:29:48 2009
@@ -22,6 +22,7 @@
 import java.util.List;
 
 import javax.persistence.Parameter;
+import javax.persistence.Query;
 import javax.persistence.Tuple;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
@@ -334,7 +335,11 @@
         q.multiselect(c).where(cb.equal(
             c.get(customer_.getSingularAttribute("status", Integer.class)), param));
 
-        assertEquivalence(q, jpql, new String[] { "stat" }, new Object[] { 1 });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+            }
+        }, q, jpql);
     }
 
     public void testKeyExpressionInSelectList() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java?rev=835961&r1=835960&r2=835961&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
Fri Nov 13 19:29:48 2009
@@ -21,6 +21,7 @@
 import java.math.BigDecimal;
 import java.util.Collection;
 
+import javax.persistence.Query;
 import javax.persistence.Tuple;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
@@ -34,6 +35,7 @@
 import javax.persistence.criteria.SetJoin;
 import javax.persistence.criteria.Subquery;
 
+import org.apache.openjpa.persistence.criteria.AbstractCriteriaTestCase.QueryDecorator;
 import org.apache.openjpa.persistence.test.AllowFailure;
 
 public class TestStringCriteria extends CriteriaTest {
@@ -215,7 +217,11 @@
         param.alias("stat");
         q.select(c).where(cb.equal(c.get("status"), param));
 
-        assertEquivalence(q, jpql, new String[] { "stat" }, new Object[] { 1 });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+            }
+        }, q, jpql);
     }
 
     public void testSelectList() {

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=835961&r1=835960&r2=835961&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
Fri Nov 13 19:29:48 2009
@@ -37,6 +37,7 @@
 package org.apache.openjpa.persistence.criteria;
 
 import javax.persistence.Parameter;
+import javax.persistence.Query;
 import javax.persistence.Tuple;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
@@ -44,6 +45,7 @@
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Subquery;
 
+import org.apache.openjpa.persistence.criteria.AbstractCriteriaTestCase.QueryDecorator;
 import org.apache.openjpa.persistence.test.DatabasePlatform;
 
 /**
@@ -163,7 +165,11 @@
         cq.where(cb.like(c.get(CompUser_.name), param, '|'));
         cq.select(c.get(CompUser_.name));
         
-        assertEquivalence(cq, query, new String[]{"name"}, new Object[] {"%|_%"});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("name", "%|_%");
+            }
+        }, cq, query);
     }
 
     public void testNullExpression() {
@@ -501,8 +507,12 @@
         cq.where(e.type().in(param1, param2));
         cq.orderBy(cb.asc(e.get(CompUser_.name)));
         
-        assertEquivalence(cq, jpql, new String[]{"a","b"}, 
-             new Class[]{MaleUser.class,FemaleUser.class});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("a", MaleUser.class);
+                q.setParameter("b", FemaleUser.class);
+            }
+        }, cq, jpql);
     }
 
     public void testTypeExpression2() {
@@ -516,7 +526,11 @@
         q.multiselect(e.type());
         q.where(cb.equal(e.type(), param1).not());
         
-        assertEquivalence(q, query, new String[]{"t"}, new Class[]{MaleUser.class});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("t", MaleUser.class);
+            }
+        }, q, query);
     }
 
     public void testTypeExpression3() {

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=835961&r1=835960&r2=835961&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
Fri Nov 13 19:29:48 2009
@@ -25,6 +25,7 @@
 import java.util.Map;
 
 import javax.persistence.Parameter;
+import javax.persistence.Query;
 import javax.persistence.Tuple;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Expression;
@@ -33,6 +34,7 @@
 import javax.persistence.criteria.ListJoin;
 import javax.persistence.criteria.MapJoin;
 import javax.persistence.criteria.ParameterExpression;
+import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Selection;
 import javax.persistence.criteria.SetJoin;
@@ -539,7 +541,11 @@
         Parameter<Integer> param = cb.parameter(Integer.class, "stat");
         q.select(c).where(cb.equal(c.get(Customer_.status), param));
 
-        assertEquivalence(q, jpql, new String[] { "stat" }, new Object[] { 1 });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+            }
+        }, q, jpql);
     }
     
     public void testParameters2() {
@@ -552,8 +558,12 @@
         q.select(c).where(cb.and(cb.equal(c.get(Customer_.status), param1), 
                 cb.equal(c.get(Customer_.name), param2)));
 
-        assertEquivalence(q, jpql, new String[] { "stat", "name" },
-                new Object[] { 1, "test" });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+                q.setParameter("name", "test");
+            }
+        }, q, jpql);
     }
     
     public void testParameters3() {
@@ -564,7 +574,11 @@
         Parameter<Integer> param = cb.parameter(Integer.class, "stat");
         q.select(c).where(cb.equal(c.get(Customer_.status), param));
         
-        assertEquivalence(q, jpql, new String[]{"stat"}, new Object[] { 1 });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+            }
+        }, q, jpql);
     }
     
     public void testParameters4() {
@@ -576,8 +590,12 @@
         Parameter<String> param2 = cb.parameter(String.class, "name");
         q.select(c).where(cb.and(cb.equal(c.get(Customer_.status), param1), 
                 cb.equal(c.get(Customer_.name), param2)));
-        assertEquivalence(q, jpql, new String[]{"stat", "name"},
-                new Object[] { 1, "test" });
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("stat", 1);
+                q.setParameter("name", "test");
+            }
+        }, q, jpql);
     }
     
     public void testParameters5() {
@@ -588,10 +606,14 @@
         ParameterExpression<List> param1 = cb.parameter(List.class, "coll");
         q.where(c.get(Customer_.status).in(param1));
         q.select(c);
-        List vals = new ArrayList();
+        final List vals = new ArrayList();
         vals.add(1);
         vals.add(2);
-        assertEquivalence(q, jpql, new String[] {"coll"}, new Object[] {vals});
+        assertEquivalence(new QueryDecorator() {
+            public void decorate(Query q) {
+                q.setParameter("coll", vals);
+            }
+        }, q, jpql);
     }
     
     public void testSelectList1() {
@@ -1333,5 +1355,23 @@
         } catch (IllegalArgumentException e) {
         }
     }
+    
+    public void testGroupByOnMaxResult() {
+        String jpql = "SELECT c.address.country, count(c) from Customer c GROUP BY c.address.country
" +
+                      "HAVING COUNT(c.address.country)>3";
+        
+        CriteriaQuery<Object[]> c = cb.createQuery(Object[].class);
+        Root<Customer> customer = c.from(Customer.class);
+        Path<String> country = customer.get(Customer_.address).get(Address_.country);
+        c.multiselect(country, cb.count(customer))
+         .groupBy(country)
+         .having(cb.gt(cb.count(country), 3));
+        
+        assertEquivalence(new QueryDecorator(){
+            public void decorate(Query q) {
+                q.setMaxResults(20);
+            }
+        }, c, jpql);
+    }
 
 }



Mime
View raw message