I ended up spending time trying to understand proxies... confusing stuff
when you start out with ojb... these days it's making a little more sense :)

a. yes, it has to be of type StateProxy (the interface) as ojb will try to
instanciate it with a proxy object that implements the interface.  If you
use a StateVO, ojb cant just point it to a proxy.

b. I didnt think so.  I'm pretty sure my code was not doing this, and was
working fine.

c. This is correct.  In fact you dont need the CityProxy interface at all.
Early on i got it into my head that i needed interfaces for collection
proxies like this.  It was only the other day that i realised otherwise!

d. dont quite understand the code here... i would use fkStateId and then
have "private int fkStateId;" in CityVO +interface.

To be honest, i barely ever use reference proxies any more as i found that
they didnt have much effect on performance of my apps, and i had to use
interfaces everywhere.  I almost always proxy collections though, as these
do make a big difference.

Daniel.

> -----Original Message-----
> From: Enrique Medina [mailto:[EMAIL PROTECTED]
> Sent: 20 May 2004 18:25
> To: [EMAIL PROTECTED]
> Subject: Reference proxies & Interfaces
>
>
> This is just a confirmation question about using reference
> proxies in OJB. I
> have been using them in all my applications, but I would like to confirm
> that I am making a good use of them.
>
> So my way of using reference proxies is:
>
> 1) Let's consider two business entities: state and city. So I have:
>
> public interface StateProxy
> {
>     public Integer getCodState();
>     public String getDescState();
>     public Collection getCities();
>
>     public void setCodState(Integer state);
>     public void setDescState(String description);
>     public void setCities(Collection cities);
> }
>
> public class StateVO implements StateProxy, Serializable
> {
>     private Integer codState;
>     private String descState;
>
>     private Collection cities;
>
>     public StateVO()
>     {
>     }
>
>     // Getters/Setters ....
> }
>
> public interface CityProxy
> {
>     public Integer getCodCity();
>     public String getDescCity();
>     public StateProxy getState();
>
>     public void setCodCity(Integer city);
>     public void setDescCity(String description);
>     public void setState(StateProxy state);
> }
>
> public class CityVO implements CityProxy, Serializable
> {
>     private Integer codCity;
>     private String descCity;
>
>     private StateProxy state;
>
>     public CityVO()
>     {
>         state = new StateVO();
>     }
>
>     // Getters/Setters ....
> }
>
> 2) Do the mapping in repository-user.xml:
>
> <class-descriptor
>     class="StateVO"
>     table="TBL_STATE"
> >
>
>     <field-descriptor
>         id="1"
>         name="codState"
>         column="ID_STATE"
>         jdbc-type="INTEGER"
>         primarykey="true" />
>
>     <field-descriptor
>         id="2"
>         name="descState"
>         column="DESC_STATE"
>         jdbc-type="VARCHAR" />
>
>     <collection-descriptor
>         name="cities"
>         element-class-ref="CityVO"
>         proxy="true">
>
>         <inverse-foreignkey  field-id-ref="3" />
>
>     </collection-descriptor>
>
> </class-descriptor>
>
> <class-descriptor
>     class="CityVO"
>     table="TBL_CITY"
> >
>
>     <field-descriptor
>         id="1"
>         name="codCity"
>         column="ID_CITY"
>         jdbc-type="INTEGER"
>         primarykey="true" />
>
>     <field-descriptor
>         id="2"
>         name="descCity"
>         column="DESC_CITY"
>         jdbc-type="VARCHAR" />
>
>     <field-descriptor
>         id="3"
>         name="state::codState"
>         column="ID_STATE"
>         jdbc-type="INTEGER" />
>
>     <reference-descriptor
>         name="state"
>         class-ref="StateVO"
>         proxy="true">
>
>         <foreignkey field-id-ref="3" />
>
>     </reference-descriptor>
>
> </class-descriptor>
>
> And my questions are the following:
>
> a) I declare the variable 'state' in class 'CityVO' as being of type
> 'StateProxy' (the interface). If not, I get errors from OJB indicating it
> can't obtain a getter/setter for the 'Proxy' object (I suppose it
> tries to
> obtain a getter/setter for the interface, not for the
> implementacion class).
> Is this the right behaviour?
>
> b) I have to instantiate the variable 'state' in class 'CityVO'
> inside the
> default constructor, because if not, OJB throws an exception saying it
> cannot instantiate 'StateProxy'. I suppose this must be correct.
>
> c) With the collection variable 'cities' in class 'StateVO',
> there's no need
> to instantiate it on the constructor, as OJB knows how to instantiate any
> collection. Am I right?
>
> d) Do you think is correct to map the 'foreign key' using the variable
> 'state' defined in class 'CityVO' in the way 'state::codState' in the
> class-descriptor for 'CityVO'?
>
> I would welcome any suggestions, critics and comments from anyone
> that has
> worked with reference proxies and interfaces with OJB.
>
> Thanks in advance,
> Enrique Medina.
>
> _________________________________________________________________
> �D�nde se esconden [EMAIL PROTECTED] [EMAIL PROTECTED] Encuentra miles de perfiles en
> MSN Amor &
> Amistad. http://match.msn.es/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to