cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562757 - 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/ test/resources/dml/
Date Sat, 04 Aug 2007 20:08:02 GMT
Author: aadamchik
Date: Sat Aug  4 13:08:00 2007
New Revision: 562757

URL: http://svn.apache.org/viewvc?view=rev&rev=562757
Log:
CAY-840 EJBQL Subquery support
(preparing existing translators to handle subselects)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLSubqueryTest.xml
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/EJBQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLBaseVisitor.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLExpressionVisitor.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/main/java/org/apache/cayenne/ejbql/parser/EJBQLSelectClause.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=562757&r1=562756&r2=562757
==============================================================================
--- 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 13:08:00 2007
@@ -78,6 +78,11 @@
         return true;
     }
 
+    public boolean visitExists(EJBQLExpression expression) {
+        context.append(" EXISTS");
+        return true;
+    }
+
     public boolean visitOr(EJBQLExpression expression, int finishedChildIndex) {
         afterChild(expression, " OR", finishedChildIndex);
         return true;
@@ -328,6 +333,13 @@
             context.append(" #bind(").append(expression.getText()).append(" 'VARCHAR')");
         }
         return true;
+    }
+    
+    public boolean visitSubselect(EJBQLExpression expression) {
+        context.append('(');
+        expression.visit(new EJBQLSelectTranslator(context));
+        context.append(')');
+        return false;
     }
 
     private void processParameter(String boundName) {

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=562757&r1=562756&r2=562757
==============================================================================
--- 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
Sat Aug  4 13:08:00 2007
@@ -68,7 +68,7 @@
         return false;
     }
 
-    public boolean visitSelect(EJBQLExpression expression) {
+    public boolean visitSelectClause(EJBQLExpression expression) {
         context.append("SELECT");
         return true;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLBaseVisitor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLBaseVisitor.java?view=diff&rev=562757&r1=562756&r2=562757
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLBaseVisitor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLBaseVisitor.java
Sat Aug  4 13:08:00 2007
@@ -305,6 +305,10 @@
     public boolean visitSelect(EJBQLExpression expression) {
         return continueFlag;
     }
+    
+    public boolean visitSelectClause(EJBQLExpression expression) {
+        return continueFlag;
+    }
 
     public boolean visitSelectExpression(EJBQLExpression expression) {
         return continueFlag;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLExpressionVisitor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLExpressionVisitor.java?view=diff&rev=562757&r1=562756&r2=562757
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLExpressionVisitor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/EJBQLExpressionVisitor.java
Sat Aug  4 13:08:00 2007
@@ -280,6 +280,8 @@
     boolean visitPositionalInputParameter(EJBQLPositionalInputParameter expression);
 
     boolean visitSelect(EJBQLExpression expression);
+    
+    boolean visitSelectClause(EJBQLExpression expression);
 
     boolean visitSelectExpression(EJBQLExpression expression);
 

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=562757&r1=562756&r2=562757
==============================================================================
--- 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
Sat Aug  4 13:08:00 2007
@@ -167,12 +167,19 @@
 
         public boolean visitWhere(EJBQLExpression expression) {
             expression.visit(pathVisitor);
-            return false;
+
+            // continue with children as there may be subselects with their own id
+            // variable declarations
+            return true;
         }
 
         public boolean visitOrderBy(EJBQLExpression expression) {
             expression.visit(pathVisitor);
             return false;
+        }
+
+        public boolean visitSubselect(EJBQLExpression expression) {
+            return super.visitSubselect(expression);
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLSelectClause.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLSelectClause.java?view=diff&rev=562757&r1=562756&r2=562757
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLSelectClause.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/EJBQLSelectClause.java
Sat Aug  4 13:08:00 2007
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.ejbql.parser;
 
+import org.apache.cayenne.ejbql.EJBQLExpressionVisitor;
+
 /**
  * @since 3.0
  * @author Andrus Adamchik
@@ -28,6 +30,7 @@
         super(id);
     }
 
-    // no visitor method for now, as this node is semantical and not important in
-    // analyzing the query
+    protected boolean visitNode(EJBQLExpressionVisitor visitor) {
+        return visitor.visitSelectClause(this);
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLSubqueryTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLSubqueryTest.xml?view=auto&rev=562757
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLSubqueryTest.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLSubqueryTest.xml
Sat Aug  4 13:08:00 2007
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-lazy-init="true">
+
+	<bean id="P1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33001, 'P1', 3000)
+			</value>
+		</constructor-arg>
+	</bean>
+
+	<bean id="P2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33002, 'P2', 4000)
+			</value>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="P3" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33003, 'P1', 5000)
+			</value>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="P4" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33004, 'P4', 6000)
+			</value>
+		</constructor-arg>
+	</bean>
+
+
+	<!-- ======================================= -->
+	<!-- Data Sets -->
+	<!-- ======================================= -->
+
+	<bean id="prepare" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="P1" />
+				<ref bean="P2" />
+				<ref bean="P3" />
+				<ref bean="P4" />
+			</list>
+		</constructor-arg>
+	</bean>
+</beans>
\ No newline at end of file



Mime
View raw message