cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r546953 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test: java/org/apache/cayenne/access/DataContextSQLTemplateTest.java resources/dml/access.DataContextSQLTemplateTest.xml
Date Wed, 13 Jun 2007 16:55:33 GMT
Author: aadamchik
Date: Wed Jun 13 09:55:32 2007
New Revision: 546953

URL: http://svn.apache.org/viewvc?view=rev&rev=546953
Log:
CAY-805: SQLTemplate improvement: new #bindObjectEqual #bindObjectNotEqual directives
compound key test

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

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java?view=diff&rev=546953&r1=546952&r2=546953
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateTest.java
Wed Jun 13 09:55:32 2007
@@ -20,10 +20,13 @@
 package org.apache.cayenne.access;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.art.Artist;
+import org.apache.art.CompoundFkTestEntity;
+import org.apache.art.CompoundPkTestEntity;
 import org.apache.art.Painting;
 import org.apache.cayenne.DataObjectUtils;
 import org.apache.cayenne.DataRow;
@@ -211,7 +214,62 @@
         Painting p = (Painting) objects.get(0);
         assertEquals(33001, DataObjectUtils.intPKForObject(p));
     }
+
+    public void testBindObjectEqualCompound() throws Exception {
+        createTestData("testBindObjectEqualCompound");
+
+        ObjectContext context = createDataContext();
+
+        Map pk = new HashMap();
+        pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
+        pk.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "a2");
+
+        CompoundPkTestEntity a = (CompoundPkTestEntity) DataObjectUtils.objectForPK(
+                context,
+                CompoundPkTestEntity.class,
+                pk);
+
+        String template = "SELECT * FROM COMPOUND_FK_TEST t0"
+                + " WHERE #bindObjectEqual($a [ 't0.F_KEY1', 't0.F_KEY2' ] [ 'KEY1', 'KEY2'
] ) ORDER BY PKEY";
+        SQLTemplate query = new SQLTemplate(CompoundFkTestEntity.class, template);
+        query.setColumnNamesCapitalization(SQLTemplate.UPPERCASE_COLUMN_NAMES);
+        query.setParameters(Collections.singletonMap("a", a));
+
+        List objects = context.performQuery(query);
+        assertEquals(1, objects.size());
+
+        CompoundFkTestEntity p = (CompoundFkTestEntity) objects.get(0);
+        assertEquals(33001, DataObjectUtils.intPKForObject(p));
+    }
     
+    public void testBindObjectNotEqualCompound() throws Exception {
+        createTestData("testBindObjectEqualCompound");
+
+        ObjectContext context = createDataContext();
+
+        Map pk = new HashMap();
+        pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
+        pk.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "a2");
+
+        CompoundPkTestEntity a = (CompoundPkTestEntity) DataObjectUtils.objectForPK(
+                context,
+                CompoundPkTestEntity.class,
+                pk);
+
+        String template = "SELECT * FROM COMPOUND_FK_TEST t0"
+                + " WHERE #bindObjectNotEqual($a [ 't0.F_KEY1', 't0.F_KEY2' ] [ 'KEY1', 'KEY2'
] ) ORDER BY PKEY";
+        SQLTemplate query = new SQLTemplate(CompoundFkTestEntity.class, template);
+        query.setColumnNamesCapitalization(SQLTemplate.UPPERCASE_COLUMN_NAMES);
+        query.setParameters(Collections.singletonMap("a", a));
+
+        List objects = context.performQuery(query);
+        assertEquals(1, objects.size());
+
+        CompoundFkTestEntity p = (CompoundFkTestEntity) objects.get(0);
+        assertEquals(33002, DataObjectUtils.intPKForObject(p));
+    }
+
+
     public void testBindObjectNotEqualNull() throws Exception {
         createTestData("prepare");
 
@@ -228,11 +286,10 @@
 
         Painting p1 = (Painting) objects.get(0);
         assertEquals(33001, DataObjectUtils.intPKForObject(p1));
-        
+
         Painting p2 = (Painting) objects.get(1);
         assertEquals(33002, DataObjectUtils.intPKForObject(p2));
     }
-
 
     public void testFetchLimit() throws Exception {
         getAccessStack().createTestData(DataContextCase.class, "testArtists", null);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextSQLTemplateTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextSQLTemplateTest.xml?view=diff&rev=546953&r1=546952&r2=546953
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextSQLTemplateTest.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextSQLTemplateTest.xml
Wed Jun 13 09:55:32 2007
@@ -49,6 +49,40 @@
 		</value></constructor-arg>
 	</bean>
 	
+	<bean id="P13" 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 (33003,
'P3', null, 5000)
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="CP1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.CompoundPkTestEntity</value></constructor-arg>
+		<constructor-arg><value>
+		insert into COMPOUND_PK_TEST (KEY1, KEY2) values ('a1', 'a2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="CP2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.CompoundPkTestEntity</value></constructor-arg>
+		<constructor-arg><value>
+		insert into COMPOUND_PK_TEST (KEY1, KEY2) values ('b1', 'b2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="CF1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.CompoundFkTestEntity</value></constructor-arg>
+		<constructor-arg><value>
+		insert into COMPOUND_FK_TEST (PKEY, F_KEY1, F_KEY2) values (33001, 'a1', 'a2')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="CF2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.apache.art.CompoundFkTestEntity</value></constructor-arg>
+		<constructor-arg><value>
+		insert into COMPOUND_FK_TEST (PKEY, F_KEY1, F_KEY2) values (33002, 'b1', 'b2')
+		</value></constructor-arg>
+	</bean>
 
 	<!-- ======================================= -->
 	<!-- Data Sets -->
@@ -63,6 +97,18 @@
 				<ref bean="A4"/>
 				<ref bean="P11"/>
 				<ref bean="P12"/>
+				<ref bean="P13"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testBindObjectEqualCompound" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="CP1"/>
+				<ref bean="CP2"/>
+				<ref bean="CF1"/>
+				<ref bean="CF2"/>
 			</list>
 		</constructor-arg>
 	</bean>



Mime
View raw message