Return-Path: X-Original-To: apmail-cayenne-commits-archive@www.apache.org Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A50BAD362 for ; Wed, 26 Dec 2012 15:00:47 +0000 (UTC) Received: (qmail 37219 invoked by uid 500); 26 Dec 2012 15:00:47 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 37190 invoked by uid 500); 26 Dec 2012 15:00:47 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 37176 invoked by uid 99); 26 Dec 2012 15:00:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Dec 2012 15:00:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Dec 2012 15:00:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4EFDE2388B9B; Wed, 26 Dec 2012 15:00:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121226150026.4EFDE2388B9B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 { } 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 q = new SelectQuery(Artist.class); - q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY); + q.addPrefetch(Artist.PAINTING_ARRAY.disjoint()); final List 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 q = new SelectQuery(Artist.class); + q.addPrefetch(Artist.ARTIST_EXHIBIT_ARRAY.joint()); + q.addOrdering(Artist.ARTIST_NAME.asc()); + + final List 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