当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

复旦大学:《高级Web技术》3-应用web_4-EJB_教学课件PPT_EJB开发-5-编写Entity Bean

资源类别:文库,文档格式:PPT,文档页数:53,文件大小:820KB,团购合买
◼ 创建EJB1.1 Entity Bean ◼ 创建EJB2.0 Entity Bean
点击下载完整版文档(PPT)

高级Meb技术 J阳a2 Enterprise Edtion

高级Web技术 Java 2 Enterprise Edtion

本次课程内容 ■创建EJB11 Entity Bean n创建EJB20 Entity Bean

本次课程内容 ◼ 创建EJB1.1 Entity Bean ◼ 创建EJB2.0 Entity Bean

创建EJB11 Entity Bean

创建EJB1.1 Entity Bean

数据库表模型 TaxBeanTable(记录了每个州的税率) statecode 文本类型;州代码(主键) taxRate 符点类型;税率 一个简单的 Entity Bean与数据库中的一条记录对应 根据数据库表结构抽象出 Entity Bean的结构

数据库表模型 ◼ 一个简单的Entity Bean与数据库中的一条记录对应 ◼ 根据数据库表结构抽象出Entity Bean的结构 TaxBeanTable(记录了每个州的税率) stateCode 文本类型;州代码(主键) taxRate 符点类型;税率

编写 Remote接口 / remote interface used by TaxBean package Data; import java rmi Remote Exception import javax.ejb EJBObject; public interface Tax extends EJBobject { public void setTaxRate(float taxRate) throws RemoteException; A publicfloat getTaxRate( throws Remote Exception; 代码中的 getXXx和 setxxx方法对应于数据库的读写操作 定义了两个方法支持税率的获取或修改

编写Remote接口 ◼ 代码中的getXxx和setXxx方法对应于数据库的读写操作 ◼ 定义了两个方法支持税率的获取或修改 //remote interface used by TaxBean package Data; import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface Tax extends EJBObject { public void setTaxRate(float taxRate) throws RemoteException; public float getTaxRate() throws RemoteException; }

Home接口 //home interface used by TaxBean package Data; import java. util. Collection; import java rmi RemoteException; import javax. ejb. K public interface TaxHome extends EJBHome public Tax create(string state Code, float taxRate throws RemoteException, Create; public Tax find By Primary key(string primarykey throws RemoteException, FinderException public Collection findInRange float lowerLimit, float upperlimit) throws Remote Exception, FinderException; Entity Bean标准方法 create find By Primary Key(必须具有该方法) 自定义方法 findIn Range

Home接口 ◼ Entity Bean标准方法 ◼ create ◼ findByPrimaryKey(必须具有该方法) ◼ 自定义方法 ◼ findInRange //home interface used by TaxBean package Data; import java.util.Collection; import java.rmi.RemoteException; import javax.ejb.*; public interface TaxHome extends EJBHome { public Tax create(String stateCode, float taxRate) throws RemoteException, CreateException; public Tax findByPrimaryKey(String primaryKey) throws RemoteException, FinderException; public Collection findInRange(float lowerLimit, float upperLimit) throws RemoteException, FinderException; }

编写 Entity Bean类(Part1) package Data import java. util. import javax. ejb. i public class TaxBean implements Entity Beant public string state Code public float taxRate: public void setTaxRate(float taxRate) his, taxRate taxRatei 属性定义 public float getTaxRateOt Entity Bean类中的属性 return this taxRate: 一般与数据库表中的字段——对 应 //Part2

编写Entity Bean类(Part 1) package Data; import java.util.*; import javax.ejb.*; public class TaxBean implements EntityBean{ public String stateCode; public float taxRate; public void setTaxRate(float taxRate){ this.taxRate = taxRate; } public float getTaxRate(){ return this.taxRate; } //Part2 属性定义: Entity Bean类中的属性 一般与数据库表中的字段一一对 应

编写 Entity Bean类(Part1) package Data import java. util. import javax. ejb. i public class Tax Bean implements Entity Beant public String state Code public float taxRate public void setTaxRate (float taxRate his taxRate taxRatej public float getTaxRate(t 商业方法实现: return this taxRate: 实现在 Remote接口中 的定义的方法。 //Part2

编写Entity Bean类(Part 1) package Data; import java.util.*; import javax.ejb.*; public class TaxBean implements EntityBean{ public String stateCode; public float taxRate; public void setTaxRate(float taxRate){ this.taxRate = taxRate; } public float getTaxRate(){ return this.taxRate; } //Part2 商业方法实现: 实现在Remote接口中 的定义的方法

编写 Entity Bean类(Part2) //Part1 public String ejbCreate(string state Code, float taxRate) throws Create Exception if(state Code == nullR throw new Create Exception ("the State Code is required )i this, state Code s statecode: this taxRate s taxRate: return null ejbCreate方法实现 public void ejbPostcreate(String state Cade, 实现在Home接口中的 public void ejbload ot 定义的 create方法对应的 if(state Code != null) ejbCreate方法 state Code. trim o; 对于CMP,客户调用 create会导致数据库中插入一条 public void ejbstore仆 public void ejbRemove0t 记录,在数据库插入记录之前, 容器会调用 ejbCreate方法,允 public void setEntitycontext(EntityContextd许用户设置各字段的值 public void ejbActivate(& public void ejbPassivateo]

编写Entity Bean类(Part 2) //Part1 public String ejbCreate(String stateCode, float taxRate) throws CreateException{ if(stateCode == null){ throw new CreateException("The State Code is required."); } this.stateCode = stateCode; this.taxRate = taxRate; return null; } public void ejbPostCreate(String stateCode, float taxRate){} public void ejbLoad(){ if(stateCode != null) stateCode.trim(); } public void ejbStore() {} public void ejbRemove() {} public void unsetEntityContext() {} public void setEntityContext(EntityContext context) {} public void ejbActivate() {} public void ejbPassivate() {} } ejbCreate方法实现: 实现在Home接口中的 定义的create方法对应的 ejbCreate方法。 对于CMP,客户调用 create会导致数据库中插入一条 记录,在数据库插入记录之前, 容器会调用ejbCreate方法,允 许用户设置各字段的值

编写 Entity Bean类(Part2) //Part1 public String ejbCreate( String stateCode, float taxRate) throws Create Exception if(state Code == nullR throw new Create Exception( The State Code is required. )i this state Code s statecode: this taxRate s taxRate: return null public void ejbPostcreate(String state Code, public void ejbload ot if(state Code != null) 设置属性值 state Code. trim o; 根据客户端传过来的参 数设置属性值 public void ejbstore仆 public void ejbRemove0t public void unsetEntity Contextot] public void setEntity Context(Entity Context public void ejbActivate(& public void ejbPassivateo]

编写Entity Bean类(Part 2) //Part1 public String ejbCreate(String stateCode, float taxRate) throws CreateException{ if(stateCode == null){ throw new CreateException("The State Code is required."); } this.stateCode = stateCode; this.taxRate = taxRate; return null; } public void ejbPostCreate(String stateCode, float taxRate){} public void ejbLoad(){ if(stateCode != null) stateCode.trim(); } public void ejbStore() {} public void ejbRemove() {} public void unsetEntityContext() {} public void setEntityContext(EntityContext context) {} public void ejbActivate() {} public void ejbPassivate() {} } 设置属性值 根据客户端传过来的参 数设置属性值

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共53页,可试读18页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有