cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r550207 [2/2] - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/ejbql/ main/java/org/apache/cayenne/ejbql/parser/ main/java/org/apache/cayenne/query/ ma...
Date Sun, 24 Jun 2007 11:06:56 GMT
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLUpdate.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLUpdate.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLUpdate.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLUpdate.java
Sun Jun 24 04:06:54 2007
@@ -31,11 +31,6 @@
     }
 
     protected boolean visitNode(EJBQLExpressionVisitor visitor) {
-        return visitor.visitUpdate(this, -1);
-    }
-
-    protected boolean visitChild(EJBQLExpressionVisitor visitor, int childIndex) {
-        return super.visitChild(visitor, childIndex)
-                && visitor.visitUpdate(this, childIndex);
+        return visitor.visitUpdate(this);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLWhere.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLWhere.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLWhere.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLWhere.java
Sun Jun 24 04:06:54 2007
@@ -31,11 +31,6 @@
     }
 
     protected boolean visitNode(EJBQLExpressionVisitor visitor) {
-        return visitor.visitWhere(this, -1);
-    }
-
-    protected boolean visitChild(EJBQLExpressionVisitor visitor, int childIndex) {
-        return super.visitChild(visitor, childIndex)
-                && visitor.visitWhere(this, childIndex);
+        return visitor.visitWhere(this);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/SimpleNode.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/SimpleNode.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/SimpleNode.java
Sun Jun 24 04:06:54 2007
@@ -46,7 +46,7 @@
     public String getText() {
         return text;
     }
-    
+
     public boolean isNegated() {
         return not;
     }
@@ -55,24 +55,21 @@
      * A recursive visit method that passes a visitor to this node and all its children,
      * depth first.
      */
-    public boolean visit(EJBQLExpressionVisitor visitor) {
+    public void visit(EJBQLExpressionVisitor visitor) {
 
-        if (!visitNode(visitor)) {
-            return false;
-        }
+        if (visitNode(visitor)) {
 
-        int len = getChildrenCount();
-        for (int i = 0; i < len; i++) {
-            if (!visitChild(visitor, i)) {
-                return false;
+            int len = getChildrenCount();
+            for (int i = 0; i < len; i++) {
+                if (!visitChild(visitor, i)) {
+                    break;
+                }
             }
         }
-
-        return true;
     }
 
     /**
-     * Visits this not without recursion. Default implementation simply returns true.
+     * Visits this node without recursion. Default implementation simply returns true.
      * Subclasses override this method to call an appropriate visitor method.
      */
     protected boolean visitNode(EJBQLExpressionVisitor visitor) {
@@ -84,7 +81,8 @@
      * if they desire to implement callbacks after visiting each child.
      */
     protected boolean visitChild(EJBQLExpressionVisitor visitor, int childIndex) {
-        return children[childIndex].visit(visitor);
+        children[childIndex].visit(visitor);
+        return true;
     }
 
     public EJBQLExpression getChild(int index) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQueryMetadata.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/EJBQLQueryMetadata.java
Sun Jun 24 04:06:54 2007
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
 
@@ -29,8 +30,21 @@
  */
 class EJBQLQueryMetadata extends BaseQueryMetadata {
 
+    private SQLResultSetMapping resultSetMapping;
+
+    void setResultSetMapping(SQLResultSetMapping resultSetMapping) {
+        this.resultSetMapping = resultSetMapping;
+    }
+
+    public SQLResultSetMapping getResultSetMapping() {
+        return resultSetMapping;
+    }
+
     boolean resolve(EntityResolver resolver, EJBQLQuery query) {
-        ObjEntity root = query.getExpression(resolver).getRootDescriptor().getEntity();
+        EJBQLCompiledExpression expression = query.getExpression(resolver);
+        setResultSetMapping(expression.getResultSetMapping());
+        
+        ObjEntity root = expression.getRootDescriptor().getEntity();
 
         // TODO: andrus, 4/3/2007 - generate cache key based on EJBQL statement
         return super.resolve(root, resolver, null);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SQLResultSetMapping.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SQLResultSetMapping.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SQLResultSetMapping.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/query/SQLResultSetMapping.java
Sun Jun 24 04:06:54 2007
@@ -19,8 +19,8 @@
 package org.apache.cayenne.query;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * A metadata object that defines how a DataRow can be converted to result objects. This
@@ -35,7 +35,7 @@
 public class SQLResultSetMapping {
 
     protected String name;
-    protected Collection columnResults;
+    protected List columnResults;
 
     public SQLResultSetMapping() {
 
@@ -56,7 +56,7 @@
     /**
      * Returns a collection of mapped columns.
      */
-    public Collection getColumnResults() {
+    public List getColumnResults() {
         return columnResults != null ? columnResults : Collections.EMPTY_LIST;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
Sun Jun 24 04:06:54 2007
@@ -532,7 +532,7 @@
 }
 
 
-void distinct_path() #DistinctPath : { }
+void distinct_path() #Distinct : { }
 {
 	<DISTINCT> (LOOKAHEAD(path()) path() | identification_variable())
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLQueryTest.java
Sun Jun 24 04:06:54 2007
@@ -42,6 +42,74 @@
         deleteTestData();
     }
 
+    public void testSelectAggregate() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "select count(p), count(distinct p.estimatedPrice), max(p.estimatedPrice),
sum(p.estimatedPrice) from Painting p";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(1, data.size());
+        assertTrue(data.get(0) instanceof Object[]);
+        Object[] aggregates = (Object[]) data.get(0);
+        assertEquals(new Long(2), aggregates[0]);
+        assertEquals(new Long(2), aggregates[1]);
+        assertEquals(new BigDecimal(5000d), aggregates[2]);
+        assertEquals(new BigDecimal(8000d), aggregates[3]);
+    }
+
+    public void testSelectAggregateNull() throws Exception {
+
+        String ejbql = "select count(p), max(p.estimatedPrice), sum(p.estimatedPrice) "
+                + "from Painting p WHERE p.paintingTitle = 'X'";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(1, data.size());
+        assertTrue(data.get(0) instanceof Object[]);
+        Object[] aggregates = (Object[]) data.get(0);
+        assertEquals(new Long(0), aggregates[0]);
+        assertEquals(null, aggregates[1]);
+        assertEquals(null, aggregates[2]);
+    }
+
+    public void testSelectEntityPathsScalarResult() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "select p.paintingTitle"
+                + " from Painting p order by p.paintingTitle DESC";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(2, data.size());
+
+        assertEquals("P2", data.get(0));
+        assertEquals("P1", data.get(1));
+    }
+
+    public void testSelectEntityPathsArrayResult() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "select p.estimatedPrice, p.toArtist.artistName "
+                + "from Painting p order by p.estimatedPrice";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List data = createDataContext().performQuery(query);
+        assertEquals(2, data.size());
+
+        assertTrue(data.get(0) instanceof Object[]);
+        Object[] row0 = (Object[]) data.get(0);
+        assertEquals(2, row0.length);
+        assertEquals(new BigDecimal(3000d), row0[0]);
+        assertEquals("AA1", row0[1]);
+
+        assertTrue(data.get(1) instanceof Object[]);
+        Object[] row1 = (Object[]) data.get(1);
+        assertEquals(2, row1.length);
+        assertEquals(new BigDecimal(5000d), row1[0]);
+        assertEquals("AA2", row1[1]);
+    }
+
     public void testSimpleSelect() throws Exception {
         createTestData("prepare");
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java?view=diff&rev=550207&r1=550206&r2=550207
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
Sun Jun 24 04:06:54 2007
@@ -54,6 +54,10 @@
         assertTrue(sql, sql.indexOf("t0.ARTIST_NAME") > 0);
         assertTrue(sql, sql.indexOf("t0.DATE_OF_BIRTH") > 0);
         assertTrue(sql, sql.endsWith(" FROM ARTIST AS t0${marker0}"));
+
+        StringBuffer fromMarker = (StringBuffer) query.getParameters().get("marker0");
+        assertNotNull(fromMarker);
+        assertEquals("", fromMarker.toString());
     }
 
     public void testSelectMultipleJoinsToTheSameTable() throws Exception {
@@ -63,13 +67,17 @@
         String sql = query.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT "));
+
+        StringBuffer fromMarker = (StringBuffer) query.getParameters().get("marker0");
+        assertNotNull(fromMarker);
+        assertEquals("", fromMarker.toString());
+
         assertTrue(
                 sql,
                 sql.indexOf("INNER JOIN PAINTING AS t1 ON (t0.ARTIST_ID = t1.ARTIST_ID)")
> 0);
         assertTrue(
                 sql,
                 sql.indexOf("INNER JOIN PAINTING AS t2 ON (t0.ARTIST_ID = t2.ARTIST_ID)")
> 0);
-
     }
 
     public void testSelectDistinct() {
@@ -77,7 +85,6 @@
         String sql = query.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT DISTINCT "));
-        assertTrue(sql, sql.endsWith(" FROM ARTIST AS t0${marker0}"));
     }
 
     public void testSelectFromWhereEqual() {
@@ -85,6 +92,12 @@
         String sql = query.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT "));
+
+        StringBuffer fromMarker = (StringBuffer) query.getParameters().get("marker0");
+        assertNotNull(fromMarker);
+        String from = fromMarker.toString();
+        assertEquals("", from);
+
         assertTrue(sql, sql
                 .endsWith(" FROM ARTIST AS t0${marker0} WHERE t0.ARTIST_NAME ="
                         + " #bind('Dali' 'VARCHAR')"));
@@ -228,6 +241,36 @@
         assertTrue(sql, sql.startsWith("SELECT "));
         assertTrue(sql, sql
                 .endsWith("t0.ARTIST_NAME = #bind($id1) OR t0.ARTIST_NAME = #bind($id2)"));
+    }
+
+    public void testMax() {
+        SQLTemplate query = translateSelect("select max(p.estimatedPrice) from Painting p");
+        String sql = query.getDefaultTemplate();
+
+        assertTrue(sql, sql.startsWith("SELECT "
+                + "#result('MAX(t0.ESTIMATED_PRICE)' 'java.math.BigDecimal' 'sc0') "
+                + "FROM PAINTING AS t0"));
+    }
+
+    public void testDistinctSum() {
+        SQLTemplate query = translateSelect("select sum( distinct p.estimatedPrice) from
Painting p");
+        String sql = query.getDefaultTemplate();
+
+        assertTrue(
+                sql,
+                sql
+                        .startsWith("SELECT "
+                                + "#result('SUM(DISTINCT t0.ESTIMATED_PRICE)' 'java.math.BigDecimal'
'sc0') "
+                                + "FROM PAINTING AS t0"));
+    }
+
+    public void testColumnPaths() {
+        SQLTemplate query = translateSelect("select p.estimatedPrice, p.toArtist.artistName
from Painting p");
+        String sql = query.getDefaultTemplate();
+
+        assertTrue(sql, sql.startsWith("SELECT "
+                + "#result('t0.ESTIMATED_PRICE' 'java.math.BigDecimal' 'sc0'), "
+                + "#result('t1.ARTIST_NAME' 'java.lang.String' 'sc1') FROM"));
     }
 
     private int countDelimiters(String string, String delim, int fromIndex) {



Mime
View raw message