Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 76998 invoked from network); 20 Jun 2006 16:25:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jun 2006 16:25:17 -0000 Received: (qmail 44562 invoked by uid 500); 20 Jun 2006 16:25:17 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 44542 invoked by uid 500); 20 Jun 2006 16:25:16 -0000 Mailing-List: contact cayenne-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-user@incubator.apache.org Delivered-To: mailing list cayenne-user@incubator.apache.org Received: (qmail 44533 invoked by uid 99); 20 Jun 2006 16:25:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 09:25:16 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.18.42.249] (HELO nwkea-pix-1.sun.com) (192.18.42.249) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 09:25:15 -0700 Received: from d1-sfbay-04.sun.com ([192.18.39.114]) by nwkea-pix-1.sun.com (8.13.6+Sun/8.12.9) with ESMTP id k5KGOshG028783 for ; Tue, 20 Jun 2006 09:24:55 -0700 (PDT) Received: from conversion-daemon.d1-sfbay-04.sun.com by d1-sfbay-04.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0J160030129E9F00@d1-sfbay-04.sun.com> (original mail from Craig.Russell@Sun.COM) for cayenne-user@incubator.apache.org; Tue, 20 Jun 2006 09:24:54 -0700 (PDT) Received: from [129.145.133.119] by d1-sfbay-04.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0J1600KY92XI7700@d1-sfbay-04.sun.com> for cayenne-user@incubator.apache.org; Tue, 20 Jun 2006 09:24:54 -0700 (PDT) Date: Tue, 20 Jun 2006 09:24:49 -0700 From: Craig L Russell Subject: Re: modifying relationship list In-reply-to: <110DED9F5106CC47A186602C0DD3938201168B60@EXVF.fanniemae.com> Sender: Craig.Russell@Sun.COM To: cayenne-user@incubator.apache.org Message-id: <1D080DEA-A9BF-4808-9A6F-EAF2889C24EF@SUN.com> MIME-version: 1.0 X-Mailer: Apple Mail (2.750) Content-type: multipart/signed; protocol="application/pkcs7-signature"; boundary=Apple-Mail-165-714799694; micalg=sha1 References: <110DED9F5106CC47A186602C0DD3938201168B60@EXVF.fanniemae.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Apple-Mail-165-714799694 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed I hate to be a curmudgeon, but it sounds like this might go in the wrong direction, if I understand correctly. You need two sets of functionality: one that the user sees and transparently updates both sides of the relationship; the other, internal, that is called by the external methods and individually updates only one side. Many users would see void add(Room theRoom) and expect to call it instead of void removeObjectFromBothSidesOfRelationshipWithKey(Room theRoom, Site theSite). Or perhaps it's really static void RelationshipHelper.removeObjectFromBothSidesOfRelationshipWithKey (Object oneSide, Object theOtherSide) which can be called from any context and has to be omniscient. If the removeObjectFromBothSidesOfRelationshipWithKey is intended to be the user-visible method, then it's very descriptive. Is this the user-visible method? By the way, this is one case where I really miss the "friend" annotation of C++. You don't want the internal methods to be visible to users, just to the classes on the other side of the relationship. Nothing like this semantic exists for Java. :-( Craig On Jun 20, 2006, at 6:04 AM, Gentry, Michael (Contractor) wrote: > Monstrous? That was my favorite method name! It stated precisely > what > it was doing, too. :-) We hardly ever removed anything, so never got > to use removeObjectFromBothSidesOfRelationshipWithKey all that much. > Sigh. > > /dev/mrg > > PS. For me, it was actually > addObject:toBothSidesOfRelationshipWithKey: > ... Much better. > > > > -----Original Message----- > From: Andrus Adamchik [mailto:andrus@objectstyle.org] > Sent: Tuesday, June 20, 2006 2:19 AM > To: cayenne-user@incubator.apache.org > Subject: Re: modifying relationship list > > >> >> "Someone" should write a paper. > > Yep :-) > > I recall back in my WebObjects/EOF days, instead of using property > setters I always used a generic method with monstrous name of the > Objective C heritage - "addObjectToBothSidesOfRelationshipWithKey" > and its counterpart "removeObjectFromBothSidesOfRelationshipWithKey" > exactly because it helped with graph consistency. > > So bidirectional relationship management was one of the first > features in the early Cayenne to address that. > > Andrus > > > On Jun 19, 2006, at 8:51 PM, Craig L Russell wrote: > >> Hi, >> >> This relationship change issue is a very old one in object modeling >> and made even more interesting when mapping to a relational >> database, where typically there is only one database column value >> that represents both sides of the relationship. >> >> Among the standards for persistence (J2EE CMP, JDO 1, JDO 2, and >> EJB3) the requirements are all over the map, with little to guide >> you. >> >> CMP defines the behavior as I understand Cayenne currently >> implements it. That is, the relationship on the other side is >> silently changed to be consistent. >> >> JDO 1 is silent on the issue. >> >> JDO 2 defines the behavior as "undefined until commit or flush", at >> which point the relationships on both sides are silently changed to >> be consistent. >> >> EJB3 is silent, and allows relationships to be inconsistent after >> commit. >> >> I believe it is tricky to code defensively if you want to manage >> relationships in memory. The issue is the possibility of updating >> the relationship from either side. The apparently straightforward >> technique is to implement the Room.setSite method to call >> oldRoom.remove(this) and newRoom.add(this). And the Site.remove >> method to call theRoom.setSite(null) and Site.add method to call >> theRoom.setSite(this). But this causes recursion, unless you use >> special add, remove, and set methods, that need to be protected >> from public callers. That is, define package protected methods >> uncoordinatedAdd, uncoordinatedRemove, and uncoordinatedSet that >> don't manage the other side, but are called from within the public- >> visible implementations of add, remove, and set. But clearly this >> is a lot of work for developers, so it's nice that the persistence >> implementation does some of the hard work for you. >> >> "Someone" should write a paper. >> >> Craig >> >> On Jun 19, 2006, at 1:12 AM, Tomi NA wrote: >> >>> On 6/19/06, Marcin Skladaniec wrote: >>>> Hello >>>> Just run into interesting cayenne feature. >>>> >>>> This code: >>>> >>>> rooms = site.getRooms(); >>>> rooms.remove(aRoom); >>>> >>>> would alter the relationship >>>> >>>> so aRoom.getSite() is now null >>>> >>>> I'm wondering if this is a desired effect ? >>>> This behavior might cause bugs. When someone actually puts code to >>>> know the fact of relationship being changed (ie. put code into Room >>>> setSite() and Site add/removeFromRooms()/setRooms() methods ) he >>>> might be disappointed, as those methods would not run, but the >>>> relationship will change... >>> >>> I'm wrestling with this issue myself: I've extended the basic >>> templates so that events are fired on setter calls, but this >>> practice >>> has the exact shortcomings you pointed out. >>> Is there a very good reason why cayenne objects don't fire events >>> on a >>> lower level (circumventing this problem) out of the box? >>> Alternatively, if I expand my object code generation templates >>> further >>> so that objectA.removeFrom(objectB) fires a property change event >>> for >>> it's objectA.getBArray() as well as objectB.getToA() - will this >>> completely solve the problem? >>> >>> t.n.a. >> >> Craig Russell >> Architect, Sun Java Enterprise System http://java.sun.com/products/ >> jdo >> 408 276-5638 mailto:Craig.Russell@sun.com >> P.S. A good JDO? O, Gasp! >> > Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-165-714799694 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGUDCCAwkw ggJyoAMCAQICEB7Y7fLHmKoeHTUdbtYrvpAwDQYJKoZIhvcNAQEEBQAwYjELMAkGA1UEBhMCWkEx JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0ZSBQ ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA1MTIxNTIxNDc0NFoXDTA2MTIxNTIxNDc0 NFowbDEQMA4GA1UEBBMHUnVzc2VsbDEUMBIGA1UEKhML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