cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562280 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
Date Thu, 02 Aug 2007 22:26:51 GMT
Author: aadamchik
Date: Thu Aug  2 15:26:49 2007
New Revision: 562280

URL: http://svn.apache.org/viewvc?view=rev&rev=562280
Log:
CAY-838 EJBQL GROUP BY and HAVING support
initial HAVING support; still no support for aggregate functions in HAVING

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java?view=diff&rev=562280&r1=562279&r2=562280
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
Thu Aug  2 15:26:49 2007
@@ -55,6 +55,12 @@
         expression.visit(new EJBQLGroupByTranslator(context));
         return false;
     }
+    
+    public boolean visitHaving(EJBQLExpression expression) {
+        context.append(" HAVING");
+        expression.visit(new EJBQLConditionTranslator(context));
+        return false;
+    }
 
     public boolean visitOrderBy(EJBQLExpression expression) {
         context.append(" ORDER BY");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java?view=diff&rev=562280&r1=562279&r2=562280
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLGroupByHavingTest.java
Thu Aug  2 15:26:49 2007
@@ -98,4 +98,38 @@
         // assertEquals(new Long(1), row[0]);
         // }
     }
+
+    public void testGroupByHavingOnColumn() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p.estimatedPrice, count(p) FROM Painting p"
+                + " GROUP BY p.estimatedPrice"
+                + " HAVING p.estimatedPrice > 1";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(1, data.size());
+        assertTrue(data.get(0) instanceof Object[]);
+
+        Object[] row0 = (Object[]) data.get(0);
+        assertEquals(new BigDecimal(2), row0[0]);
+        assertEquals(new Long(2), row0[1]);
+    }
+
+    public void testGroupByHavingOnAggregate() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p.estimatedPrice, count(p) FROM Painting p"
+                + " GROUP BY p.estimatedPrice"
+                + " HAVING count(p) > 2";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+//        List data = createDataContext().performQuery(query);
+//        assertEquals(1, data.size());
+//        assertTrue(data.get(0) instanceof Object[]);
+//
+//        Object[] row0 = (Object[]) data.get(0);
+//        assertEquals(new BigDecimal(1), row0[0]);
+//        assertEquals(new Long(3), row0[1]);
+    }
 }



Mime
View raw message