cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r561449 - 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 Tue, 31 Jul 2007 19:20:18 GMT
Author: aadamchik
Date: Tue Jul 31 12:20:17 2007
New Revision: 561449

URL: http://svn.apache.org/viewvc?view=rev&rev=561449
Log:
CAY-836 EJBQL Delete Statement Support

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java?view=diff&rev=561449&r1=561448&r2=561449
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
Tue Jul 31 12:20:17 2007
@@ -43,10 +43,16 @@
         context.append("DELETE");
         return true;
     }
-    
+
     public boolean visitFrom(EJBQLExpression expression, int finishedChildIndex) {
         context.append(" FROM");
         expression.visit(new EJBQLFromTranslator(context));
+        return false;
+    }
+
+    public boolean visitWhere(EJBQLExpression expression) {
+        context.append(" WHERE");
+        expression.visit(new EJBQLConditionTranslator(context));
         return false;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java?view=diff&rev=561449&r1=561448&r2=561449
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
Tue Jul 31 12:20:17 2007
@@ -18,13 +18,19 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
+import org.apache.art.Painting;
+import org.apache.cayenne.DataObjectUtils;
 import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.unit.CayenneCase;
 
 public class DataContextEJBQLDeleteTest extends CayenneCase {
+    
+    protected void setUp() throws Exception {
+        deleteTestData();
+    }
 
-    public void testDelete() throws Exception {
+    public void testDeleteNoQualifier() throws Exception {
         createTestData("prepare");
 
         String ejbql = "delete from Painting AS p";
@@ -36,5 +42,24 @@
         assertNotNull(count);
         assertEquals(1, count.length);
         assertEquals(2, count[0]);
+    }
+
+    public void testDeleteSameEntityQualifier() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "delete from Painting AS p WHERE p.paintingTitle = 'P2'";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        QueryResponse result = createDataContext().performGenericQuery(query);
+
+        int[] count = result.firstUpdateCount();
+        assertNotNull(count);
+        assertEquals(1, count.length);
+        assertEquals(1, count[0]);
+
+        assertNotNull(DataObjectUtils
+                .objectForPK(createDataContext(), Painting.class, 33001));
+        assertNull(DataObjectUtils
+                .objectForPK(createDataContext(), Painting.class, 33002));
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml?view=diff&rev=561449&r1=561448&r2=561449
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLDeleteTest.xml
Tue Jul 31 12:20:17 2007
@@ -6,46 +6,17 @@
 	<!-- Named Queries -->
 	<!-- ======================================= -->
 	
-	<!-- ARTIST -->
-	<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, 'AA1')
-		</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, 'AA2')
-		</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, 'BB1')
-		</value></constructor-arg>
-	</bean>
-	
-	<bean id="A4" 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 (33004, 'BB2')
-		</value></constructor-arg>
-	</bean>
-	
 	<bean id="P11" 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, ARTIST_ID, ESTIMATED_PRICE) VALUES (33001,
'P1', 33001, 3000)
+		INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) VALUES (33001,
'P1', NULL, 3000)
 		</value></constructor-arg>
 	</bean>
 	
 	<bean id="P12" 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, ARTIST_ID, ESTIMATED_PRICE) VALUES (33002,
'P2', 33002, 5000)
+		INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) VALUES (33002,
'P2', NULL, 5000)
 		</value></constructor-arg>
 	</bean>
 	
@@ -57,10 +28,6 @@
 	<bean id="prepare" class="java.util.ArrayList">
 		<constructor-arg>
 			<list>
-				<ref bean="A1"/>
-				<ref bean="A2"/>
-				<ref bean="A3"/>
-				<ref bean="A4"/>
 				<ref bean="P11"/>
 				<ref bean="P12"/>
 			</list>



Mime
View raw message