>  > >  2. doSelect creating subclass of the data object : As I ready
expained in
>  > >  some mails earlier ([Proposal] Change *Peer.doSelect() generation -
>  > Torque)
>  > >  . This is the resolution of the problem is that the Peer object
knows the
>  > >  data object. An example : an Address table/object. I have the
MyAddress
>  > >  extends Address (with more methods). The doSelect() method create a
>  > vector
>  > >  of Address. But I can't cast from Address to MyAddress. So I have to
>  > modify
>  > >  the doSelect method to generate a vector of MyAddress. What I
propose is
>  > to
>  > >  modify the doSelect method. We transmit to this method the className
to
>  > >  generate. That meens :public static Vector doSelect(Criteria
criteria,
>  > >  String className).
>  >
>  > I think I have a better solution:
>  >
>  > DoSelect should not use "new Address()" in this case. Rather than that
it
>  > should define a method:
>  >
>  > protected Address createObject()
>  > {
>  >   return new Address();
>  > }
>  >
>  > and in doSelect simply use "createObject()" instead of "new"
>  >
>  > this way, if you simply want MyAddressPeer.doSelect to return a vector
of
>  > MyAddress all you need to do is to overload createObject():
>  >
>  > protected Address createObject()
>  > {
>  >    return new MyAddress();
>  > }
>  >
>  >
>  > this should be completely transparent and backward-compatible.
>  > Does it make sense?
>  
>  The problems comes in when you change your db schema and you want to
re-generate
>  your classes.  Any changes that you have made will be overwritten by the
newly
>  generated classes.  If you edit the createObject() method to return a
subclass
>  then your changes will also be lost when you re-generate new classes. 
You might
>  also want to have different subclasses instantiated at different times. 
doSelect
>  (Criteria, Classname) makes this possible, plus it will not break when
you
>  re-generate classes.

I believe you misunderstood me. Here is another explanation:

Generated AddressPeer should look like this:
----
public class AddressPeer extends BasePeer{
....   
    protected Address createObject()
    {
     return new Address();
    }

....
    public Vector doSelect(...)
    {
      ....
-     new Address();
+     createObject();      
    }
-----

MyAddressPeer would look smth like:
-----
public class MyAddressPeer extends AddressPeer
{
  .... 
  protected Address createObject()
  {
    return new MyAddress();
  }
}
---

this way you do not need to edit generated AddressPeer and if you regenerate
AddressPeer all your changes (which you made in MyAddressPeer) won't go
away.

Makes more sense?

fedor.





_______________________________________________________
Say Bye to Slow Internet!
http://www.home.com/xinbox/signup.html



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to