cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1425937 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/Property.java test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
Date Wed, 26 Dec 2012 15:00:26 GMT
Author: aadamchik
Date: Wed Dec 26 15:00:25 2012
New Revision: 1425937

URL: http://svn.apache.org/viewvc?rev=1425937&view=rev
Log:
CAY-1784 Improving 'Property' class to handle a few extra common cases

prefetches

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java?rev=1425937&r1=1425936&r2=1425937&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
Wed Dec 26 15:00:25 2012
@@ -251,6 +251,9 @@ public class Property<E> {
     }
 
     PrefetchTreeNode prefetch() {
+
+        // TODO: not very efficient - we are creating a prefetch that
+        // SelectQuery would throw away and recreate...
         PrefetchTreeNode root = new PrefetchTreeNode();
         PrefetchTreeNode node = root.addPath(name);
         node.setPhantom(false);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java?rev=1425937&r1=1425936&r2=1425937&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
Wed Dec 26 15:00:25 2012
@@ -148,7 +148,7 @@ public class DataContextPrefetchTest ext
         createTwoArtistsAndTwoPaintingsDataSet();
 
         SelectQuery<Artist> q = new SelectQuery<Artist>(Artist.class);
-        q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
+        q.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
 
         final List<Artist> artists = context.select(q);
 
@@ -243,7 +243,7 @@ public class DataContextPrefetchTest ext
             }
         });
     }
-
+    
     /**
      * Test that a to-many relationship is initialized when a target entity has a compound
      * PK only partially involved in relationship.
@@ -292,6 +292,47 @@ public class DataContextPrefetchTest ext
             }
         });
     }
+    
+    
+    public void testPrefetchToManyOnJoinTableJoinedPrefetch_ViaProperty() throws Exception
{
+        createTwoArtistsWithExhibitsDataSet();
+
+        SelectQuery<Artist> q = new SelectQuery<Artist>(Artist.class);
+        q.addPrefetch(Artist.ARTIST_EXHIBIT_ARRAY.joint());
+        q.addOrdering(Artist.ARTIST_NAME.asc());
+
+        final List<Artist> artists = context.select(q);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+
+                assertEquals(2, artists.size());
+
+                Artist a1 = artists.get(0);
+                assertEquals("artist2", a1.getArtistName());
+                List<?> toMany = (List<?>) a1.readPropertyDirectly(Artist.ARTIST_EXHIBIT_ARRAY.getName());
+                assertNotNull(toMany);
+                assertFalse(((ValueHolder) toMany).isFault());
+                assertEquals(2, toMany.size());
+
+                ArtistExhibit artistExhibit = (ArtistExhibit) toMany.get(0);
+                assertEquals(PersistenceState.COMMITTED, artistExhibit.getPersistenceState());
+                assertSame(a1, artistExhibit.getToArtist());
+
+                Artist a2 = artists.get(1);
+                assertEquals("artist3", a2.getArtistName());
+                List<?> toMany2 = (List<?>) a2.readPropertyDirectly(Artist.ARTIST_EXHIBIT_ARRAY.getName());
+                assertNotNull(toMany2);
+                assertFalse(((ValueHolder) toMany2).isFault());
+                assertEquals(3, toMany2.size());
+
+                ArtistExhibit artistExhibit2 = (ArtistExhibit) toMany2.get(0);
+                assertEquals(PersistenceState.COMMITTED, artistExhibit2.getPersistenceState());
+                assertSame(a2, artistExhibit2.getToArtist());
+            }
+        });
+    }
 
     /**
      * Test that a to-many relationship is initialized when a target entity has a compound



Mime
View raw message