ooAD大报告之 Petstore中EB的设计模式分析 这样我们要读取一个对象如果使用他的 getXX方法就多次调用了远程效率很低 如果一次性读到值对象,这就减少了远程调用。 我们在实际开发中,一般为每个 Entity Bean建一个值对象,并且在 entity Bean 中的Home接口中,增加个 create方法,参数就是值对象.并且在接口中增加 setData和 getData方法。 日Home接口 public interface TAccountAcptRemoteHome extends javax. ejb EJBHome ∥/在创建时,使用值对象,如果修改数据结构,接口不需改变,只修改属性就 行了 public TAccountAcptRemote create(TAccountAcptModel data) throws CreateException, Remote Exception 声明接口(远程或本地接口) ublic interface TAccountAcptRemote javax. ejb EJBObject t /通过这个接口,一次性获得值对象,不需分别使用 getXX,减少网络调用次 数,提高效率 public TAccountAcptModel getData0 throws Remote Exception; public void getData (TaccountAcptModel data)throws Remote Exception 值对象 public class TAccountAcptModel implements java. io Serializable 作者:张玉平,吴小静,范赟梦,张麒
OOAD 大报告之 PetStore 中 EJB 的设计模式分析 作者: 张 玉 平 , 吴 小 静 , 范 赟 梦 , 张麒,罗晟, 张 翅 11 这样我们要读取一个对象,如果使用他的getXX 方法就多次调用了进程,效率很低, 如果一次性读到值对象,这就减少了进程调用。 我们在实际开发中,一般为每个EntityBean 建一个值对象,并丏在entityBean 中的Home 接口中,增加一个create 方法,参数就是值对象. 并丏在接口中增加 setData 和getData 方法。 „ Home 接口 public interface TAccountAcptRemoteHome extends javax.ejb.EJBHome { //在创建时,使用值对象,如果修改数据结构,接口丌需改变,叧修改属性就 行了 public TAccountAcptRemote create(TAccountAcptModel data) throws CreateException, RemoteException; } 声明接口(进程戒本地接口) public interface TAccountAcptRemote extends javax.ejb.EJBObject { //通过这个接口,一次性获得值对象,丌需分别使用getXX,减少网络调用次 数,提高效率 public TAccountAcptModel getData() throws RemoteException; public void getData(TaccountAcptModel data) throws RemoteException; } 值对象 public class TAccountAcptModel implements java.io.Serializable {
ooAD大报告之 Petstore中EB的设计模式分析 public java. lang String accepted public java. lang String accountId public java. lang String ownerld public java. lang String accountName public java. lang String accountAddr; public java. lang String accountzip public java. lang String bankId public java. lang String account public java. lang String pay Typeld public java. lang String state public java. lang String postMode ng postAddl public java. lang String postzi public java. lang String postMan public java. math. Big Decimal preSum public Java. sql Date createDate public java. sql Date unsign Da 2.2.2.动机 作者:张玉平,吴小静,范赟梦,张麒,罗晟,张翅
OOAD 大报告之 PetStore 中 EJB 的设计模式分析 作者: 张 玉 平 , 吴 小 静 , 范 赟 梦 , 张麒,罗晟, 张 翅 12 public java.lang.String acceptId ; public java.lang.String accountId ; public java.lang.String ownerId ; public java.lang.String accountName; public java.lang.String accountAddr; public java.lang.String accountZip ; public java.lang.String bankId ; public java.lang.String account ; public java.lang.String payTypeId ; public java.lang.String state public java.lang.String postMode public java.lang.String postAddr public java.lang.String postZip public java.lang.String postMan ; public java.math.BigDecimal preSum ; public java.sql.Date createDate ; public java.sql.Date unsignDate ; } 2.2.2. 劢机
ooAD大报告之 Petstore中EB的设计模式分析 Some entities have a set of attributes that are always used together. In the Java Pet Store application, the contact information of a customer(city, state, zip code, etc. )is an example of one such group Suppose that in total, a customer's contact information is composed of 15 individual attributes, each accessible by a corresponding getXXX method in CustomerEJB.Then, every time a customer's contact information is requested, 15 remote getxXX calls will be invoked on the CustomerEJB, one for each attribute this will incur heavy costs in network traffic and ejb container resource usage The Java Pet Store application reduces these costs by adopting a coarse-grained view of the fine-grained contact information. It aggregates the contact information -related attributes of the customerejb into an instance of ContactInformation. This instance or value object, is then serialized and sent over the network to a requesting client, where the object is deserialized Subsequent read accesses go through the value object rather than the remote entity object. Since these accesses are local, they require no server communication and use fewer resources 作者:张玉平,吴小静,范簧梦,张麒,罗晟,张翅13
OOAD 大报告之 PetStore 中 EJB 的设计模式分析 作者: 张 玉 平 , 吴 小 静 , 范 赟 梦 , 张麒,罗晟, 张 翅 13 Some entities have a set of attributes that are always used together. In the Java Pet Store application, the contact information of a customer (city, state, zip code, etc.) is an example of one such group. Suppose that in total, a customer's contact information is composed of 15 individual attributes, each accessible by a corresponding getXXX method in CustomerEJB. Then, every time a customer's contact information is requested, 15 remote getXXX calls will be invoked on the CustomerEJB, one for each attribute. This will incur heavy costs in network traffic and EJB container resource usage. The Java Pet Store application reduces these costs by adopting a coarse-grained view of the fine-grained contact information. It aggregates the contact information-related attributes of the CustomerEJB into an instance of ContactInformation. This instance, or value object, is then serialized and sent over the network to a requesting client, where the object is deserialized. Subsequent read accesses go through the value object rather than the remote entity object. Since these accesses are local, they require no server communication and use fewer resources
ooAD大报告之 Petstore l中EB的设计模式分析 Client Customer Customerlnt object Entity Bean Entity Bean getcustomerinfo: create get city before gets ateQ get ZipCode network client Customerinfo cust。mer object Valueobject Entity bean getcustomerInfo0 create getcity0 after gets ateQ boundary 2.2.3.结构 t b nterpriseBean业务对象,实现了业务逻辑 Valueobject实现了串行化值对象 2.2.4. PerStore的例子 PetStore中存在大量的例子,基本上每个EJB中都可以找到它的踪影 作者:张玉平,吴小静,范赟梦,张麒,罗晟,张翅
OOAD 大报告之 PetStore 中 EJB 的设计模式分析 作者: 张 玉 平 , 吴 小 静 , 范 赟 梦 , 张麒,罗晟, 张 翅 14 2.2.3. 结构 EnterpriseBean 业务对象,实现了业务逻辑ValueObject 实现了串行化值对象。 2.2.4. PerStore 的例子 PetStore 中存在大量的例子,基本上每个EJB 中都可以找到它的踪影
o0AD大报告之 Petstore中EB的设计模式分析 日如值对象 Profilelnfo(一定要实现 Serializable接口,就是串行化) public class ProfileInfo implements java. io Serializable private String defaultPreferredLanguage null: private String defaultFavorite Category null private boolean defaultMyListPreference false: private boolean defaultBannerPreference false ablic ProfileInfo( String defaultPreferredlanguage String defaultFavoriteCategory boolean defaultMyListPreference olean defaultBannerPreference) this defaul tPreferredlanguage defaultPreferredlanguage this defaultFavoriteCategory defaultFavoriteCategory this defaultMylistPreference defaultMylistPreference this default BannerPreference defaultBanner Preference public String getPreferredLanguageo return defaultPreferredlanguage: public String getFavoriteCategory o return defaultFavorite cate public boolean getBannerPreferenceo I return default BannerPreference public boolean getMyListPreferenceo return defaultMyListPreference: 回使用类,提高调用粗粒度,使用值对象 作者:张玉平,吴小静,范簧梦,张麒,罗晟,张翅15
OOAD 大报告之 PetStore 中 EJB 的设计模式分析 作者: 张 玉 平 , 吴 小 静 , 范 赟 梦 , 张麒,罗晟, 张 翅 15 „ 如值对象ProfileInfo(一定要实现Serializable 接口,就是串行化) public class ProfileInfo implements java.io.Serializable { private String defaultPreferredLanguage = null; private String defaultFavoriteCategory = null; private boolean defaultMyListPreference = false; private boolean defaultBannerPreference = false; public ProfileInfo( String defaultPreferredLanguage, String defaultFavoriteCategory, boolean defaultMyListPreference, boolean defaultBannerPreference) { this.defaultPreferredLanguage = defaultPreferredLanguage; this.defaultFavoriteCategory = defaultFavoriteCategory; this.defaultMyListPreference = defaultMyListPreference; this.defaultBannerPreference = defaultBannerPreference; } public String getPreferredLanguage() { return defaultPreferredLanguage; } public String getFavoriteCategory() { return defaultFavoriteCategory; } public boolean getBannerPreference() { return defaultBannerPreference; } public boolean getMyListPreference() { return defaultMyListPreference; } } „ 使用类,提高调用粗粒度,使用值对象