编写 Entity Bean类(Part2) //Part1 public String ejbCreate(String state Code, float tax eibStore throws CreateException 容器将数据从 entity if(state Code ==null bean中存储到数据库中之前,会 throw new CreateEXcepti调用bean类的 o Store方法 this state code= state Code 在此方法中可以对要存 this. taxRate taxRate 储的的数据进行一些预处理 return null public void ejbPostCreate(String state Code, float taxRate)3 public void ejbLoadot if(state Code!=null state Code. trimo public void ejbstore os public void ejbRemoveot 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() {} } ejbStore: 容器将数据从entity bean中存储到数据库中之前,会 调用bean类的ejbStore方法。 在此方法中可以对要存 储的的数据进行一些预处理
编写 Entity Bean类(Part2) eib remove //Part1 public String ejbCreate(String state Code, float taxR 容器将数据数据库中删 if(/state throws Create Exception(除之前,会调用bean类的 de = null ejbremove方法。 throw new CreateException 在此方法中可以进行一 些整理工作 this state code= state Code 对于CMP,客户调用 this. taxRate taxRate remove方法会导致删除数据库中 return null 的数据。 public void ejbPostCreate(String state Code, float taxRate)3 public void ejbLoadot f( state Code∠nul‖ state Code. trimo } public void ejbStoreon publicvoid ejb Remove(tM public void unsetEntityContexto0 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() {} } ejbRemove: 容器将数据数据库中删 除之前,会调用bean类的 ejbRemove方法。 在此方法中可以进行一 些整理工作 对于CMP,客户调用 remove方法会导致删除数据库中 的数据
编写 Entity Bean类(Part2) //Part1 public String ejbCreate(String state Code, float taxR throws CreateException if(state Code ==null Entity Context throw new create Exceptio Entity Context是 Entity bean与容器交互的接口。 this state code= state Code this. taxRate taxRate return null public void ejbPostCreate(String state Code, float taxRate)3 public void ejbLoadot if(state Code != null state Code. trj/ho } public void ejbstoreot public void ejbremoveot public void unsetEntity Context(t public yoid setEntity 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() {} } EntityContext: EntityContext是Entity bean与容器交互的接口