AW: [Objectbridge-developers] RE: [objectbridge - Open Discussion] Polymorphism support?
Brought to you by:
thma
From: <tho...@it...> - 2001-02-01 12:36:13
|
Hi David, -----Urspr=FCngliche Nachricht----- Von: David Forslund [mailto:dw...@la...] Gesendet: Donnerstag, 1. Februar 2001 01:28 An: Mahler Thomas; objectbridge Betreff: Re: [Objectbridge-developers] RE: [objectbridge - Open Discussion] Polymorphism support? At 04:41 PM 1/31/2001 +0100, Mahler Thomas wrote: Hi Sascha, > -----Urspr=FCngliche Nachricht----- > Von: nobody [mailto:no...@so...] > Gesendet: Dienstag, 30. Januar 2001 22:31 > An: no...@so... > Betreff: [objectbridge - Open Discussion] Polymorphism support? > > > Read and respond to this message at: > http://sourceforge.net/forum/message.php?msg_id=3D103071 > By: koenig > > Hi, > > I looked into ObjectBridge as a O/R mapping tool for our OpenEMed project > (http://telemed.lanl.gov/OpenEMed). > Thanks for your interest! It would be a great opportunity to proof th= e usability of OJB if it could solve your persistence needs. > Unfortunately I didn't found a mechanism for supporting polymorph > objects. You are right. As of today there is no support for Polymorphism. But of course it is an essential feature. It is also required by the ODMG spec. If it is a feature you need urgently I can start to work on it immediately. I have already a design in mind, so it will take only a few days... We urgently need this feature. Our only other option in open source is castor. After finishing a first draft of a persistent collection implementation I started working on support for polymorphism yesterday. May solution will work for interfaces implemented by several classes or w= ith a baseclass extended by several other classes. It will work for Collections as well as for simple references. There is only one impact on the application: Assume we have an Interface I implemented by classes X, Y and Z. X, Y, Z that are mapped to three different tables TX, TY, TZ. All these tables ha= ve a primary key column ID. Further we have a business class B (mapped to TB) with an attribute value= of Type I. We also need a private attribute value_id holding the foreign key= ID of one of the tables TX, TY, TZ. This will work only if ID's are unique across all tables representing objects of Type I. There will be a class SequenceManager with a static method getUniqueId(..= .) that is responsible for generating such unique numbers, so the impact on your app's code we be pretty small... Right now I don't have a precise Idea how to extend the Query engine to search through polymorphic Extends. Any Ideas are welcome! > > In particular: > Our main class has a field 'value' of an interface type. This > interface type > is implemented by several concrete classes that get stored in the > 'value' field > of the main object. > I'd like to store these objects in separate tables referenced > from the main > object, but even storing them as embedded objects would be fine. > > Is there a way to do this with ObjectBridge? As long as I'm not finished with a real solution, you could try the following: you can use an additional field 'valueOID' of type String which takes= a serialized representation of the concrete values Identity: valueOID =3D new Identity(value).serialize(); instead of making the field value persistent you store the serialized OID in a db column. Of course your value field is then transient. On loading your Object = you have to reconstruct it e.g. in a constructor by: value =3D (YourInterface) broker.getObjectByIdentity(Identity.forName(valueOID)); I'm using this approach for untyped Collections (like org.odmg.DList) and it works quite well. But of course it's not type safe and brings one additional level of indirection into the mapping... Of course you can also store complete serialized "embedded" objects i= n a single db column, but this is even worse from a design point of view.= .. The difficulty with what you suggest is that we are trying to do all of this through an interface that lets us talk to multiple database sources. So we ne= ed a "generic" solution that we don't have to wire much into our objects. We are willing to do some specializations (such as implementing the Persistent interface), but don't like to have to get i= nto the details of the objects much. I totally agree with you. This was only meant as a "quick hack" for getti= ng some examples running. So I hope to get something running within the next days and will keep you informed. Thomas Thanks, Dave best regards, Thomas _______________________________________________ Objectbridge-developers mailing list Obj...@li... http://lists.sourceforge.net/lists/listinfo/objectbridge-developers David W. Forslund dw...@la... Computer and Computational Sciences http://www.acl.lanl.gov/~dwf Los Alamos National Laboratory Los Alamos, NM 87545 505-665-1907 FAX: 505-665-4939 |