Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 89819 invoked from network); 13 Mar 2009 14:05:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Mar 2009 14:05:08 -0000 Received: (qmail 53078 invoked by uid 500); 13 Mar 2009 14:05:07 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 52889 invoked by uid 500); 13 Mar 2009 14:05:07 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 52878 invoked by uid 99); 13 Mar 2009 14:05:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2009 07:05:06 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [200.71.214.72] (HELO ronin.welinux.cl) (200.71.214.72) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2009 14:04:57 +0000 Received: from localhost (localhost [127.0.0.1]) by ronin.welinux.cl (Postfix) with ESMTP id CF02379C0CD for ; Fri, 13 Mar 2009 11:00:05 -0300 (CLST) X-Virus-Scanned: amavisd-new at X-Spam-Score: -4.399 X-Spam-Level: Received: from ronin.welinux.cl ([127.0.0.1]) by localhost (ronin.welinux.cl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bddr7hSs4LsA for ; Fri, 13 Mar 2009 10:59:57 -0300 (CLST) Received: from ronin.welinux.cl (localhost [127.0.0.1]) by ronin.welinux.cl (Postfix) with ESMTP id 5EA9F79C0A6 for ; Fri, 13 Mar 2009 10:59:57 -0300 (CLST) Date: Fri, 13 Mar 2009 09:59:56 -0400 (GMT-04:00) From: hans@welinux.cl To: user@cayenne.apache.org Message-ID: <318014388.1241236952796909.JavaMail.root@ronin> In-Reply-To: <1314533533.4601236030009204.JavaMail.root@ronin> Subject: Re: Factory method subclassing cayenne data objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Mailer: Zimbra 5.0.9_GA_2533.UBUNTU8_64 (ZimbraWebClient - FF3.0 (Linux)/5.0.9_GA_2533.UBUNTU8_64) X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Flag: NO X-Old-Spam-Status: No, score=-4.399 tagged_above=-10 required=6.6 tests=[ALL_TRUSTED=-1.8, BAYES_00=-2.599] List, I'm answering myself, but may be of help to somebody. Finally i have found the problem: The Qualifier (or Discriminator) has to b= e of type character and not Integer. ...my first intent was to use integer in order to follow our local policies= for enumerations. Hans ----- hans@welinux.cl escribi=C3=B3: > Dave, >=20 > I've implemented the inheritance as the tutorial say, it worked fine, > but the factory method still need to get the initial artist class to > know the type, then ask cayenne again to give the right class to > instantiate.=20 >=20 > I think there may be another way to get the object without doing this > double call to objectForPK. >=20 > =09public static Artist getArtist(String id) { >=20 > =09=09if (id =3D=3D null || id.equals("")) > =09=09=09return null; >=20 > =09=09DataContext context =3D DataContext.getThreadDataContext(); >=20 > =09=09Artist c =3D (Artist) DataObjectUtils.objectForPK(context, > =09=09=09=09Artist.class, Integer.parseInt(id)); >=20 > =09=09if (c.getTipoEnum() =3D=3D EnumTipoArtist.EXPERT) > =09=09=09return (Artist) DataObjectUtils.objectForPK(context, > =09=09=09=09=09ExpertArtist.class, Integer.parseInt(id)); > =09=09else > =09=09=09return c; > =09} >=20 > Thanks > Hans >=20 > ----- "Dave Lamy" escribi=C3=B3: >=20 > > Hey Hans-- > >=20 > > While I'm certain that the inheritance structure isn't data based > to > > you, I > > imagine that Cayenne is going to HAVE to have a data value to know > > which > > subclass to instantiate. It's effectively going to get back a row > > from the > > Artist table and be asked to transform that row into an Artist > object. > > How > > can it determine which kind? Through some sort of data analysis.=20 > > Either a > > particular attribute value (ARTIST_TYPE) or via a linked table > > structure > > (don't think Cayenne supports that yet?). That data attribute > should > > not be > > of particular importance to your application, however. It's just > an > > ORM > > crutch. > >=20 > > Dave > >=20 > > On Mon, Mar 2, 2009 at 8:41 AM, wrote: > >=20 > > > Michael, > > > > > > Thank you, i already saw it, but my intent was to make it > entirely > > outside > > > cayenne mappings, the problem i need to solve is just behavioral, > > not data > > > based... by the way, it's not clear how to try the example using > > the > > > modeler: creating an empty class with no attributes or something. > > > > > > Hans > > > > > > ----- "Michael Gentry" escribi=C3=B3: > > > > > > > Is this what you are after? > > > > > > > > http://cayenne.apache.org/doc/handling-inheritance.html > > > > > > > > > > > > On Sun, Mar 1, 2009 at 7:46 PM, wrote: > > > > > Hi, > > > > > > > > > > I'm trying to implement a factory method pattern based on a > > cayenne > > > > data object. > > > > > > > > > > Say for example i have a class (cayenne based) called Artist, > i > > want > > > > to make a subclass of Artist, say ExpertArtist that implements > > some > > > > specific behavior. > > > > > > > > > > Actually i have a big static Factory class that give me the > all > > > > objects, i have a method like this: > > > > > > > > > > public static Artist getArtist(String id) { > > > > > > > > > > if (id =3D=3D null || id.equals("")) > > > > > return null; > > > > > > > > > > DataContext context =3D > > > > DataContext.getThreadDataContext(); > > > > > > > > > > Artist object =3D (Artist) > > > > DataObjectUtils.objectForPK( > > > > > context, Artist.class, > > > > Integer.parseInt(id)); > > > > > return object; > > > > > } > > > > > > > > > > Obviously i can declare ExpertArtist as an subclass of > Artist. > > > > > > > > > > package xxx.xxx; > > > > > > > > > > public class EspertArtist extends Artist { > > > > > public String getName() { > > > > > return super.getName() + " i'am expert !!"; > > > > > } > > > > > } > > > > > > > > > > I've tried to instantiate an ExpertArtist, just modifying the > > > > Factory method, with no results. I don't know how to bouild the > > parent > > > > class calling super or something... > > > > > > > > > > Obviously these are not the real classes, the actual classes > > are > > > > really big and this solution: just modifying the factory method > is > > the > > > > best for me. > > > > > > > > > > > > > > > Thanks > > > > > Hans > > > > > > > > > > > > > > > > > > > > > -- > > > Hans Poo, WeLinux S.A. > > > Oficina: 697.25.42, Celular: 09-319.93.05 > > > Bombero Ossa # 1010, Santiago > > > > > > >=20 > --=20 > Hans Poo, WeLinux S.A. > Oficina: 697.25.42, Celular: 09-319.93.05 > Bombero Ossa # 1010, Santiago --=20 Hans Poo, WeLinux S.A. Oficina: 697.25.42, Celular: 09-319.93.05 Bombero Ossa # 1010, Santiago