cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562743 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/
Date Sat, 04 Aug 2007 17:46:33 GMT
Author: aadamchik
Date: Sat Aug  4 10:46:32 2007
New Revision: 562743

URL: http://svn.apache.org/viewvc?view=rev&rev=562743
Log:
CAY-838 EJBQL GROUP BY and HAVING support

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.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/EJBQLAggregateColumnTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java?view=diff&rev=562743&r1=562742&r2=562743
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAggregateColumnTranslator.java
Sat Aug  4 10:46:32 2007
@@ -34,9 +34,11 @@
 
     private EJBQLTranslationContext context;
     private String attributeType;
+    private boolean resultColumns;
 
-    EJBQLAggregateColumnTranslator(EJBQLTranslationContext context) {
+    EJBQLAggregateColumnTranslator(EJBQLTranslationContext context, boolean resultColumns)
{
         this.context = context;
+        this.resultColumns = resultColumns;
     }
 
     public boolean visitCount(EJBQLAggregateColumn expression) {
@@ -68,17 +70,27 @@
             EJBQLAggregateColumn column,
             EJBQLExpressionVisitor pathVisitor) {
 
-        context.append(" #result('").append(column.getFunction()).append('(');
+        if (resultColumns) {
+            context.append(" #result('");
+        }
+        else {
+            context.append(' ');
+        }
+
+        context.append(column.getFunction()).append('(');
 
         // path visitor must set attributeType ivar
         column.visit(pathVisitor);
+        context.append(')');
 
-        context
-                .append(")' '")
-                .append(column.getJavaType(attributeType))
-                .append("' '")
-                .append(context.nextColumnAlias())
-                .append("')");
+        if (resultColumns) {
+            context
+                    .append("' '")
+                    .append(column.getJavaType(attributeType))
+                    .append("' '")
+                    .append(context.nextColumnAlias())
+                    .append("')");
+        }
     }
 
     class FieldPathTranslator extends EJBQLPathTranslator {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?view=diff&rev=562743&r1=562742&r2=562743
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Sat Aug  4 10:46:32 2007
@@ -52,6 +52,11 @@
         multiColumnOperands.add(operand);
     }
 
+    public boolean visitAggregate(EJBQLExpression expression) {
+        expression.visit(new EJBQLAggregateColumnTranslator(context, false));
+        return false;
+    }
+
     public boolean visitAnd(EJBQLExpression expression, int finishedChildIndex) {
         afterChild(expression, " AND", finishedChildIndex);
         return true;
@@ -299,7 +304,7 @@
         processParameter(parameter);
         return true;
     }
-    
+
     public boolean visitBooleanLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
             context.append("null");
@@ -359,7 +364,7 @@
             // "X = NULL". The 'VARCHAR' parameter is totally bogus, but seems to work on
             // all tested DB's... Also note what JPA spec, chapter 4.11 says: "Comparison
             // or arithmetic operations with a NULL value always yield an unknown value."
-            
+
             // TODO: andrus 6/28/2007 Ideally we should track the type of the current
             // expression to provide a meaningful type.
             context.append(" #bind($").append(boundName).append(" 'VARCHAR')");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java?view=diff&rev=562743&r1=562742&r2=562743
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
Sat Aug  4 10:46:32 2007
@@ -49,7 +49,7 @@
     }
 
     public boolean visitAggregate(EJBQLExpression expression) {
-        expression.visit(new EJBQLAggregateColumnTranslator(context));
+        expression.visit(new EJBQLAggregateColumnTranslator(context, true));
         return false;
     }
 

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=562743&r1=562742&r2=562743
==============================================================================
--- 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
Sat Aug  4 10:46:32 2007
@@ -124,12 +124,29 @@
                 + " 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]);
+        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]);
+    }
+
+    public void testGroupByHavingOnAggregateMultipleConditions() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p.estimatedPrice, count(p) FROM Painting p"
+                + " GROUP BY p.estimatedPrice"
+                + " HAVING count(p) > 2 AND p.estimatedPrice < 10";
+        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