cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1576302 - in /cayenne/main/trunk: cayenne-server/src/main/java/org/apache/cayenne/access/ cayenne-server/src/test/java/org/apache/cayenne/access/ docs/doc/src/main/resources/
Date Tue, 11 Mar 2014 12:11:24 GMT
Author: aadamchik
Date: Tue Mar 11 12:11:23 2014
New Revision: 1576302

URL: http://svn.apache.org/r1576302
Log:
CAY-1905 Multi-step prefetching NPE : 1..N..1 with absent N and root with no qualifier

Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/ResultScanParentAttachmentStrategy.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepTest.java
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/ResultScanParentAttachmentStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/ResultScanParentAttachmentStrategy.java?rev=1576302&r1=1576301&r2=1576302&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/ResultScanParentAttachmentStrategy.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/ResultScanParentAttachmentStrategy.java
Tue Mar 11 12:11:23 2014
@@ -100,6 +100,12 @@ class ResultScanParentAttachmentStrategy
         partitionByChild = new HashMap<Object, List<Persistent>>();
 
         List<Persistent> objects = parentNode.getObjects();
+        
+        // this can be null if parent node returned no rows
+        if(objects == null) {
+            return;
+        }
+        
         List<DataRow> rows = parentNode.getDataRows();
         int size = objects.size();
         for (int i = 0; i < size; i++) {

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepTest.java?rev=1576302&r1=1576301&r2=1576302&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepTest.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepTest.java
Tue Mar 11 12:11:23 2014
@@ -39,6 +39,7 @@ import org.apache.cayenne.test.jdbc.Tabl
 import org.apache.cayenne.testdo.testmap.ArtistExhibit;
 import org.apache.cayenne.testdo.testmap.Exhibit;
 import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -100,6 +101,15 @@ public class DataContextPrefetchMultiste
         tArtistExhibit.insert(101, 2);
         tArtistExhibit.insert(101, 4);
     }
+    
+    protected void createGalleriesAndArtists() throws Exception {
+        tArtist.insert(11, "artist2");
+        tArtist.insert(101, "artist3");
+
+        tGallery.insert(25, "gallery1");
+        tGallery.insert(31, "gallery2");
+        tGallery.insert(45, "gallery3");
+    }
 
     public void testToManyToManyFirstStepUnresolved() throws Exception {
 
@@ -258,4 +268,44 @@ public class DataContextPrefetchMultiste
         ArtistExhibit ae1 = aexhibits.get(0);
         assertEquals(PersistenceState.COMMITTED, ae1.getPersistenceState());
     }
+    
+    public void testToManyToOne_EmptyToMany() throws Exception {
+
+        createGalleriesAndArtists();
+
+        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, Gallery.GALLERY_NAME.eq("gallery2"));
+        q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
+        q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
+
+        List<Gallery> galleries = context.select(q);
+        assertEquals(1, galleries.size());
+
+        Gallery g2 = galleries.get(0);
+
+        // this relationship should be resolved
+        assertTrue(g2.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName()) instanceof ValueHolder);
+        List<Painting> exhibits = (List<Painting>) g2.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName());
+        assertFalse(((ValueHolder) exhibits).isFault());
+        assertEquals(0, exhibits.size());
+    }
+    
+    public void testToManyToOne_EmptyToMany_NoRootQualifier() throws Exception {
+
+        createGalleriesAndArtists();
+
+        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class);
+        q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
+        q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
+
+        List<Gallery> galleries = context.select(q);
+        assertEquals(3, galleries.size());
+
+        Gallery g = galleries.get(0);
+
+        // this relationship should be resolved
+        assertTrue(g.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName()) instanceof ValueHolder);
+        List<Painting> exhibits = (List<Painting>) g.readPropertyDirectly(Gallery.PAINTING_ARRAY.getName());
+        assertFalse(((ValueHolder) exhibits).isFault());
+        assertEquals(0, exhibits.size());
+    }
 }

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1576302&r1=1576301&r2=1576302&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Tue Mar 11 12:11:23 2014
@@ -56,6 +56,7 @@ CAY-1877 In-memory evaluation of express
 CAY-1880 objectStore snapshots never cleared from RefreshQuery when "use shared cache" unchecked
 CAY-1881 CayenneModeler (Mac version) doesn't work with Java 7
 CAY-1885 Null value in subclass's field.
+CAY-1905 Multi-step prefetching NPE : 1..N..1 with absent N and root with no qualifier
 
 ----------------------------------
 Release: 3.2M1



Mime
View raw message