cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562941 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/ test/resources/dml/
Date Sun, 05 Aug 2007 19:28:35 GMT
Author: aadamchik
Date: Sun Aug  5 12:28:34 2007
New Revision: 562941

URL: http://svn.apache.org/viewvc?view=rev&rev=562941
Log:
CAY-841 EJBQL Support for LIKE/ESCAPE and IN conditions
(IN subqueries)

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/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml

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=562941&r1=562940&r2=562941
==============================================================================
--- 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 12:28:34 2007
@@ -30,6 +30,7 @@
 import org.apache.cayenne.ejbql.EJBQLException;
 import org.apache.cayenne.ejbql.EJBQLExpression;
 import org.apache.cayenne.ejbql.parser.EJBQLPositionalInputParameter;
+import org.apache.cayenne.ejbql.parser.EJBQLSubselect;
 
 /**
  * @since 3.0
@@ -246,12 +247,22 @@
             if (expression.isNegated()) {
                 context.append(" NOT");
             }
-            context.append(" IN (");
+            context.append(" IN");
+
+            // a cosmetic hack for preventing extra pair of parenthesis from being
+            // appended in 'visitSubselect'
+            if (expression.getChildrenCount() == 2
+                    && expression.getChild(1) instanceof EJBQLSubselect) {
+                visitSubselect(expression.getChild(1));
+                return false;
+            }
+            
+            context.append(" (");
         }
-        else if(finishedChildIndex == expression.getChildrenCount() - 1) {
+        else if (finishedChildIndex == expression.getChildrenCount() - 1) {
             context.append(")");
         }
-        else if(finishedChildIndex > 0) {
+        else if (finishedChildIndex > 0) {
             context.append(',');
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java?view=diff&rev=562941&r1=562940&r2=562941
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
Sun Aug  5 12:28:34 2007
@@ -131,7 +131,7 @@
         assertTrue(ids.contains(new Integer(33006)));
         assertTrue(ids.contains(new Integer(33007)));
     }
-    
+
     public void testNotIn() throws Exception {
         createTestData("prepareIn");
 
@@ -149,6 +149,28 @@
         }
 
         assertTrue(ids.contains(new Integer(33008)));
+    }
+
+    public void testInSubquery() throws Exception {
+        createTestData("prepareIn");
+
+        String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle IN ("
+                + "SELECT a1.artistName FROM Artist a1"
+                + ")";
+
+        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(33006)));
+        assertTrue(ids.contains(new Integer(33007)));
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml?view=diff&rev=562941&r1=562940&r2=562941
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
Sun Aug  5 12:28:34 2007
@@ -99,7 +99,26 @@
 		</constructor-arg>
 	</bean>
 	
-
+	<bean id="A1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33001, 'B')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="A2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33002, 'A')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="A3" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33003, 'D')
+		</value></constructor-arg>
+	</bean>
 
 	<!-- ======================================= -->
 	<!-- Data Sets -->
@@ -123,6 +142,9 @@
 				<ref bean="P6" />
 				<ref bean="P7" />
 				<ref bean="P8" />
+				<ref bean="A1" />
+				<ref bean="A2" />
+				<ref bean="A3" />
 			</list>
 		</constructor-arg>
 	</bean>



Mime
View raw message