cayenne-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=562275
Log:
CAY-838 EJBQL GROUP BY and HAVING support
support for id vars in result

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.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/EJBQLGroupByTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java?view=diff&rev=562275&r1=562274&r2=562275
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLGroupByTranslator.java
Thu Aug  2 15:12:38 2007
@@ -36,6 +36,11 @@
         this.context = context;
     }
 
+    public boolean visitIdentifier(EJBQLExpression expression) {
+        expression.visit(new EJBQLIdentifierColumnsTranslator(context, false));
+        return false;
+    }
+
     public boolean visitPath(EJBQLExpression expression, int finishedChildIndex) {
 
         if (itemCount++ > 0) {
@@ -45,7 +50,8 @@
         EJBQLExpressionVisitor childVisitor = new EJBQLPathTranslator(context) {
 
             protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) {
-                throw new EJBQLException("Can't GROUP BY on multi-column paths or objects");
+                throw new EJBQLException(
+                        "Can't GROUP BY on multi-column paths or objects");
             }
         };
         expression.visit(childVisitor);

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=562275&r1=562274&r2=562275
==============================================================================
--- 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:12:38 2007
@@ -25,7 +25,7 @@
 import org.apache.cayenne.unit.CayenneCase;
 
 public class DataContextEJBQLGroupByHavingTest extends CayenneCase {
-    
+
     protected void setUp() throws Exception {
         deleteTestData();
     }
@@ -45,12 +45,12 @@
         Object[] row0 = (Object[]) data.get(0);
         assertEquals(new BigDecimal(1), row0[0]);
         assertEquals(new Long(3), row0[1]);
-        
+
         Object[] row1 = (Object[]) data.get(1);
         assertEquals(new BigDecimal(2), row1[0]);
         assertEquals(new Long(2), row1[1]);
     }
-    
+
     public void testGroupByMultipleItems() throws Exception {
         createTestData("prepare");
 
@@ -67,15 +67,35 @@
         assertEquals(new BigDecimal(1), row0[0]);
         assertEquals("PX", row0[1]);
         assertEquals(new Long(1), row0[2]);
-        
+
         Object[] row1 = (Object[]) data.get(1);
         assertEquals(new BigDecimal(1), row1[0]);
         assertEquals("PZ", row1[1]);
         assertEquals(new Long(2), row1[2]);
-        
+
         Object[] row2 = (Object[]) data.get(2);
         assertEquals(new BigDecimal(2), row2[0]);
         assertEquals("PY", row2[1]);
         assertEquals(new Long(2), row2[2]);
+    }
+
+    public void testGroupByIdVariable() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT count(p), p FROM Painting p GROUP BY p";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(5, data.size());
+
+        // TODO: andrus, 8/3/2007 the rest of the unit test fails as currently Cayenne
+        // does not allow mixed object and scalar results (see CAY-839)
+
+        // assertTrue(data.get(0) instanceof Object[]);
+        //
+        // for(int i = 0; i < data.size(); i++) {
+        // Object[] row = (Object[]) data.get(i);
+        // assertEquals(new Long(1), row[0]);
+        // }
     }
 }



Mime
View raw message