cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r479269 - /incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java
Date Sun, 26 Nov 2006 04:10:29 GMT
Author: aadamchik
Date: Sat Nov 25 20:10:29 2006
New Revision: 479269

URL: http://svn.apache.org/viewvc?view=rev&rev=479269
Log:
CAY-682:Generic Cayenne POJO enhancer
(added tests for to-one prefetching)

Modified:
    incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java

Modified: incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java?view=diff&rev=479269&r1=479268&r2=479269
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java
(original)
+++ incubator/cayenne/main/trunk/integration-test/pojo/src/test/java/org/apache/cayenne/itest/pojo/ManyToOneObjectTest.java
Sat Nov 25 20:10:29 2006
@@ -21,6 +21,8 @@
 import java.lang.reflect.Field;
 import java.util.List;
 
+import org.apache.cayenne.DataObjectUtils;
+import org.apache.cayenne.Persistent;
 import org.apache.cayenne.query.SelectQuery;
 
 public class ManyToOneObjectTest extends PojoContextCase {
@@ -53,5 +55,47 @@
         assertNotNull(or);
 
         assertEquals(Boolean.TRUE, f.get(o1));
+    }
+
+    public void testSelectToOneWithPrefetch() throws Exception {
+        getDbHelper().deleteAll("many_to_one_entity1");
+        getDbHelper().deleteAll("one_to_many_entity1");
+        getDbHelper().insert("one_to_many_entity1", new String[] {
+            "id"
+        }, new Object[] {
+            5
+        });
+
+        getDbHelper().insert("many_to_one_entity1", new String[] {
+                "id", "one_to_many_entity1_id"
+        }, new Object[] {
+                16, 5
+        });
+
+        SelectQuery q = new SelectQuery(ManyToOneEntity1.class);
+        q.addPrefetch("toOne");
+        List results = context.performQuery(q);
+        assertEquals(1, results.size());
+
+        ManyToOneEntity1 o1 = (ManyToOneEntity1) results.get(0);
+
+        // at this point the relationship is still fault, but it must resolve from cache
+        // without going to db
+        OneToManyEntity1 or;
+
+        blockDomainQueries();
+        try {
+            or = o1.getToOne();
+            assertNotNull(or);
+
+            Field f = ManyToOneEntity1.class.getDeclaredField("$cay_faultResolved_toOne");
+            assertEquals(Boolean.TRUE, f.get(o1));
+            assertEquals(5, DataObjectUtils.intPKForObject((Persistent) or));
+        }
+        finally {
+            unblockDomainQueries();
+        }
+
+        assertSame(o1, or.getToMany().get(0));
     }
 }



Mime
View raw message