EJB設計模式1 (轉)

worldblog發表於2007-12-09
EJB設計模式1 (轉)[@more@]

 

設計 1
第一個設計模式非常簡單。一個公司和僱員的Entity Bean和
下面給出的Entity Bean的程式碼片斷是類似的。它們是由jbuilder4的
EntityBean模版生成的。所有的欄位都宣告為public的cmp欄位。


Code snippet for Company Entity Bean
public class CompanyBean implements EntityBean {
EntityContext entityContext;
public Integer comId; //the primary key
public String comName; //the company name
public String comDescription //basic description
public Timestamp mutationDate //explained later
public Integer Create() throws
CreateException {
return null;
}
//various get() and set() for every column/field
// which are exposed in the Remote Interface as well

Code snippet for Employee Entity Bean
public class EmployeeBean implements EntityBean {
EntityContext entityContext;
public Integer empId; //the primary key
public Integer comId; //the company foreign key
public String empFirstName; //the employee firstname
public String empLastName // the employee lastname
public Timestamp mutationDate //explained later
public Integer ejbCreate() throws
CreateException {
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並沒有展示出在僱員和公司之間有何
關係。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-990172/,如需轉載,請註明出處,否則將追究法律責任。

相關文章