EJB设计模式(一)

第一个设计模式非常简单。一个公司和雇员的Entity Bean和下面给出的Entity Bean的代码片断是类似的。它们是由jbuilder4的EntityBean模版生成的。所有的字段都声明为public的cmp字段。

Code snippet for Company Entity Beanpublic class CompanyBean implements EntityBean {EntityContext entityContext;public Integer comId; //the primary keypublic String comName; //the company namepublic String comDescription //basic descriptionpublic Timestamp mutationDate //explained laterpublic Integer ejbCreate() throwsCreateException {return null;}//various get() and set() for every column/field// which are exposed in the Remote Interface as wellCode snippet for Employee Entity Beanpublic class EmployeeBean implements EntityBean {EntityContext entityContext;public Integer empId; //the primary keypublic Integer comId; //the company foreign keypublic String empFirstName; //the employee firstnamepublic String empLastName // the employee lastnamepublic Timestamp mutationDate //explained laterpublic Integer ejbCreate() throwsCreateException {return null;}//various get() and set() for every column/field// which are exposed in the Remote Interface as well

这个设计模式虽然很简单,但是却有很多缺点,比如,对每一个字段的访问都会导致对get()和set()方法的一次远程调用。而远程过程调用(RPCs)是非常耗费资源的,并且,对于在实际中通常要求的组合的访问会导致一系列的远程调用。可以说,这个模式在实际中可用性很差。上面展示的设计模式可以作为其他设计模式的基础,比如RAD,原型设计,测试等。这时,那个代表雇员的Employee Entity Bean并没有展示出在雇员和公司之间有何关系。

你说,你可以把它取下来吗?当我要取的时候,你淘气的躲开了,

EJB设计模式(一)

相关文章:

你感兴趣的文章:

标签云: