V
VRGL
Unregistered / Unconfirmed
GUEST, unregistred user!
Design Pattern III
As we saw in Design Pattern II, there was a lot of code repetition in the Struct as
well as the Entity Bean with regard to declaring the fields (columns in the database).
Having the Entity Bean inherit from the Struct can eliminate this problem of code
redundancy. At this point, the Entity Bean(s) stilldo
not model the relationship
between them.
Code snippet for Company Entity Bean
public class CompanyBean extends CompanyStruct
implements EntityBean {
EntityContext entityContext;
//all fields in CompanyStruct are available for CMP
public Integer ejbCreate(CompanyStruct Struct)
throws CreateException {
this.comId = struct.comId;
//set the primary key
setData(struct);//this removes some redundant code
return null;
}
The rest of the code in the Entity Bean, i.e. the getData() and setData()
methods, remains exactly the same as in Design Pattern II.
As we saw in Design Pattern II, there was a lot of code repetition in the Struct as
well as the Entity Bean with regard to declaring the fields (columns in the database).
Having the Entity Bean inherit from the Struct can eliminate this problem of code
redundancy. At this point, the Entity Bean(s) stilldo
not model the relationship
between them.
Code snippet for Company Entity Bean
public class CompanyBean extends CompanyStruct
implements EntityBean {
EntityContext entityContext;
//all fields in CompanyStruct are available for CMP
public Integer ejbCreate(CompanyStruct Struct)
throws CreateException {
this.comId = struct.comId;
//set the primary key
setData(struct);//this removes some redundant code
return null;
}
The rest of the code in the Entity Bean, i.e. the getData() and setData()
methods, remains exactly the same as in Design Pattern II.