cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562871 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/ejbql/parser/ test/java/org/apache/cayenne/access/
Date Sun, 05 Aug 2007 14:17:48 GMT
Author: aadamchik
Date: Sun Aug  5 07:17:47 2007
New Revision: 562871

URL: http://svn.apache.org/viewvc?view=rev&rev=562871
Log:
CAY-840 EJBQL Subquery support
(ALL subselect)

Modified:
    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/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLSubqueryTest.java

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=562871&r1=562870&r2=562871
==============================================================================
--- 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
Sun Aug  5 07:17:47 2007
@@ -82,6 +82,11 @@
         context.append(" EXISTS");
         return true;
     }
+    
+    public boolean visitAll(EJBQLExpression expression) {
+        context.append(" ALL");
+        return true;
+    }
 
     public boolean visitOr(EJBQLExpression expression, int finishedChildIndex) {
         afterChild(expression, " OR", finishedChildIndex);

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=562871&r1=562870&r2=562871
==============================================================================
--- 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
Sun Aug  5 07:17:47 2007
@@ -68,10 +68,6 @@
 
                 DbAttribute dbAttribute = (DbAttribute) attribute.getDbAttribute();
 
-                // TODO: andrus 6/27/2007 - the last parameter is an unofficial "jdbcType"
-                // pending CAY-813 implementation, switch to #column directive
-                String columnAlias = context.nextColumnAlias();
-
                 if (context.isAppendingResultColumns()) {
                     context.append(" #result('");
                 }
@@ -82,6 +78,11 @@
                 context.append(alias).append('.').append(dbAttribute.getName());
 
                 if (context.isAppendingResultColumns()) {
+                    String columnAlias = context.nextColumnAlias();
+                    
+                    // TODO: andrus 6/27/2007 - the last parameter is an unofficial
+                    // "jdbcType"
+                    // pending CAY-813 implementation, switch to #column directive
                     context
                             .append("' '")
                             .append(attribute.getType())

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java?view=diff&rev=562871&r1=562870&r2=562871
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
Sun Aug  5 07:17:47 2007
@@ -44,6 +44,10 @@
  */
 class Compiler {
 
+    // a flag indicating whether column expressions should be treated as result columns or
+    // not.
+    private boolean appendingResultColumns;
+
     private String rootId;
     private EntityResolver resolver;
     private Map descriptorsById;
@@ -135,6 +139,16 @@
 
     class CompilationVisitor extends EJBQLBaseVisitor {
 
+        public boolean visitSelect(EJBQLExpression expression) {
+            appendingResultColumns = true;
+            return true;
+        }
+
+        public boolean visitFrom(EJBQLExpression expression, int finishedChildIndex) {
+            appendingResultColumns = false;
+            return true;
+        }
+
         public boolean visitSelectExpression(EJBQLExpression expression) {
             expression.visit(rootDescriptorVisitor);
             return false;
@@ -310,12 +324,14 @@
         }
 
         private void addResultSetColumn() {
-            if (resultSetMapping == null) {
-                resultSetMapping = new SQLResultSetMapping();
-            }
+            if (appendingResultColumns) {
+                if (resultSetMapping == null) {
+                    resultSetMapping = new SQLResultSetMapping();
+                }
 
-            String column = "sc" + resultSetMapping.getColumnResults().size();
-            resultSetMapping.addColumnResult(column);
+                String column = "sc" + resultSetMapping.getColumnResults().size();
+                resultSetMapping.addColumnResult(column);
+            }
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLSubqueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLSubqueryTest.java?view=diff&rev=562871&r1=562870&r2=562871
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLSubqueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLSubqueryTest.java
Sun Aug  5 07:17:47 2007
@@ -58,4 +58,28 @@
         assertTrue(ids.contains(new Integer(33001)));
         assertTrue(ids.contains(new Integer(33003)));
     }
+    
+    public void testAll() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p FROM Painting p"
+                + " WHERE p.estimatedPrice > ALL ("
+                + " SELECT p1.estimatedPrice FROM Painting p1"
+                + " WHERE p1.paintingTitle = 'P2'"
+                + ")";
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        List objects = createDataContext().performQuery(query);
+        assertEquals(2, objects.size());
+
+        Set ids = new HashSet();
+        Iterator it = objects.iterator();
+        while (it.hasNext()) {
+            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+            ids.add(id);
+        }
+
+        assertTrue(ids.contains(new Integer(33003)));
+        assertTrue(ids.contains(new Integer(33004)));
+    }
 }



Mime
View raw message