Danny,
Your answers are on the right track - but do not take
into account the EJB 2.0 CMP model. The code below
should work with both the EJB 1.1 and EJB 2.0 model.
Of course for it work in the EJB 1.1 model, you need
the entity bean implementation class to define all
the CMP fields.
So, the value object could be amended to look like:
public class VendorVO implements java.io.Serializable {
private String seller;
private String description;
/* getters and setters for the above - in other
words, a JavaBean model */
public VendorVO() {}
public VendorVO(String seller, String description) {
setSeller(seller);
setDescription(description);
}
public void copyFrom(VendorVO anotherVO) {
setSeller(anotherVO.getSeller());
setDescription(anotherVO.getDescription());
}
}
And now your EJB 2.0 CMP Entity Bean could look like:
public abstract class SomeBean extends VendorVO
implements EntityBean {
public java.lang.String ejbCreate(VendorVO vo)
throws CreateException {
setData(vo);
return null;
}
public VendorVO getData() {
VendorVO result = new VendorVO();
result.copyFrom(this);
return result;
}
public void setData(VendorVO vo) {
this.copyFrom(vo);
}
/* rest of methods not shown such as ejbPostCreate,
abstract getters and setters etc */
}
And of course you would expose the getData() and setData()
in the local interface (or remote) of the entity bean.
-krish
> -----Original Message-----
> From: A mailing list for Enterprise JavaBeans development
> [mailto:[EMAIL PROTECTED]]On Behalf Of Danny
> Sent: Friday, December 21, 2001 5:19 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Value Object Design Pattern
>
>
> In the book "Core J2EE Patterns Best Practices and Design Strategies", there
> is an Entity Inherits Object Strategy (pg 282) for the Value Object pattern.
> This looks like it is close to what you are implementing. In this strategy,
> the entity bean extends the value object which has an init method that sets
> the object values. The Value Object has 3 constructors, the default, one
> constructor with parameters for each property in the VO, and one constructor
> with the VO as a parameter. Both constructors call the init method which
> sets the VO properties. The following is an example:
>
> public class VendorVO implements java.io.Serializable {
> public String seller;
> public String description;
>
> public VendorVO () {}
>
> public VendorVO(String seller, String description) {
> init(seller, description);
> }
>
> public VendorVO(VenderVO vendor) {
> init(vendor.seller, vendor.description);
> }
>
> // method to set all the values.
> public void init(String seller, String description) {
> this.seller = seller;
> this.description = description;
> }
>
> public VendorVO getData() {
> return new VendorVO(this);
> }
>
> }
>
> public class VendorEntity extends VendorVO
> implements javax.ejb.Entitybean {
> ...
> ...
> }
>
> Danny
>
> ----- Original Message -----
> From: "Eric Dunn" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, December 20, 2001 4:22 PM
> Subject: Value Object Design Pattern
>
>
> > Dear all,
> >
> > I am trying to design a large scale system with optimal EJB communication.
> I was wondering with the Value Object Design Pattern, how would a CMP 2.0
> spec use the Value Object to SET the values in the entity bean? The way I
> retrieve values is exactly how WROX does it in "Professional EJB, Common EJB
> Design Patterns Page 520).
> >
> > There are the mapped variables which are persisted automatically by the
> containers persistence engine as normal in the main implementation class. As
> a change, the entity bean extends my value object class which has a
> getData() method which basically returns this.seller, this.description, etc
> in a class.
> >
> > This is all fine and dandy, as the Value Object is not a field managed by
> the bean. But is it possible to set in the same manner, where I send it a
> value object (using CMP2.0 keep in mind), and I set the variables then
> inside the set method? Should I make a method called
> setValueObject(ValueObject v) that calls say setSeller and setDescription()
> explicitly? Would this set off then a EJBStore after every set call then? Is
> there a way I could have only one EJBStore command be called every time I
> set a value object using EJB2.0? Keep in mind I'm trying to avoid BMP.
> >
> > Warmest Regards,
> > Eric Dunn
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".