编写 Entity Bean类(Part2) //Part1 public String ejbcreate(string state Code, float taxRate throws CreateException if(state Code ==null throw new Create EXception " The State Code is required. " this state code= state Code this taxRate= taxRate return null public void ejbPostCreate(String state Code, float t! public void ejbLoadot if(state Code != null 返回nul state Code. trimo CMP要求 entity bean } 类的返回值为nul public void ejbstoreot public void ejbRemove0t public void unsetEntity Contextot public void set Entity Context(Entity Context context public void ejbActivateot ublic void ejbPassivate(仆 }
编写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() {} } 返回null CMP要求entity bean 类的返回值为null
编写 Entity Bean类(Part2) //Part1 public String ejbcreate(string state Code, float taxRate throws CreateException if(state Code ==null throw new Create EXception " The State Code is required. " this state code= state Code this. taxRate taxRate return null public void ejbPostCreate(String state Code, float t! public void ejbLoadot if(state Code != null 对于cMP, find By primary key state Code. trimo 方法由容器实现,不需要自己编 } 写代码 public void ejbstoreot public void ejbRemove0t public void unsetEntity Contextot public void set Entity Context(Entity Context context public void ejbActivateot ublic void ejbPassivate(仆 }
编写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() {} } 对于CMP,findByPrimaryKey 方法由容器实现,不需要自己编 写代码
编写 Entity Bean类(Part2) //Part1 public String ejbcreate(string state Code, float taxRate throws CreateException if(state Code ==null throw new Create EXception " The State Code is required. " this state code= state Code this. taxRate taxRate return null public void ejbPostCreate(String state Code, float t! public void ejbLoadot if(state Code != null 对于cMP, findInRange方法由 state Code. trimo 容器实现,但组装时需要用户填 } 写SQL语句中的 WHERE子句 public void ejbstoreot public void ejbRemove0t public void unsetEntity Contextot public void set Entity Context(Entity Context context public void ejbActivateot ublic void ejbPassivate(仆 }
编写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() {} } 对于CMP,findInRange方法由 容器实现,但组装时需要用户填 写SQL语句中的WHERE子句
编写 Entity Bean类(Part2) //Part1 public String ejbCreate(String state Code, float taxR throws CreateEXceptiont ejbPostCreate if(state Code ==null throw new CreateExceptio 编写在 Entity bean时 每个home接口中的 Icreate还要对 this state code= state Code 应一个 ejbPostcreate方法 this. taxRate taxRate return null public void ejbPostCreate(String state Code, float taxRate) public void ejbLoadot if(state Code != null state Code. trimo } public void ejbstoreot public void ejbRemove0t public void unsetEntity Contextot public void setEntity Context(Entity Context context)t public void ejbActivateot ublic void ejbPassivate(仆 }
编写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() {} } ejbPostCreate: 编写在Entity bean时, 每个home接口中的create还要对 应一个ejbPostCreate方法
编写 Entity Bean类(Part2) //Part1 public String ejbCreate(String state Code, float tax eibLoad throws CreateException 容器将数据从数据库中 if(state Code ==null throw new Create Exceptio 读取到 entity bean中后,会调用 bean类的 webload方法。 this state Code= state Code: 在此方法中可以对读出 this. taxRate taxRate 的数据进行一些预处理 return null public void ejb Postcreate(String state Code, float taxRateX3 public void ejbload if(state Code != null) state Code trim public void ejbstoreot public void ejbRemove0t public void unsetEntity Contextot public void setEntity Context(Entity Context contextt public void ejbActivateot ublic void ejbPassivate(仆 }
编写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() {} } ejbLoad: 容器将数据从数据库中 读取到entity bean中后,会调用 bean类的ejbLoad方法。 在此方法中可以对读出 的数据进行一些预处理