通用的接口
Interface EJBObject
getEJBHome()得到bean的Home. | |
getHandle()保存EjbObject的一个引用 | |
getPrimaryKey() 得到实体bean的主键 | |
boolean | isIdentical(EJBObject obj) 比较两个EJBObject是否引用同一个 |
void | remove() 对会话bean说释放这个bean为客户保留的资源 对实体bean来说 删除一行记录 |
Interface EJBMetaData
getEJBHome() | |
getHomeInterfaceClass() | |
getPrimaryKeyClass() | |
getRemoteInterfaceClass() | |
boolean | isSession() |
boolean | isStatelessSession() |
javax.ejb | |
getEJBMetaData() 从Bean得到反射子类的信息 | |
getHomeHandle() 对home串行化,可以通过这个方法再次得到和使用这个home,无需通过JNDI | |
void | remove(Handle handle) 删除会话bean |
void | remove(Object primaryKey)删除实体Bean |
I 会话bean
Stateful sessionBean 的生命周期
当客户端调用Home上的create()方法
容器会建立Ejb对象和SessionContext
当容器构造Bean实例
容器会调用setSessionContext()和EjbCreate() 把bean和他的上下文和ejb对象连接起来。
容器向客户发送EJB对象的一个桩――就是-stub是rmi中运用的
StateLess SessionBean的生命周期
序列图
在无状态会话bean
客户在无状态会话bean Home调用创建方法
1. 客户在home调用创建方法
2. 容器建立EJB对象。
3. 容器给客户发送EJB对象的一个桩――就是stub
无状态会话bean创建―――与客户无关
1.容器构造SessionContext对象和bean实例,然后在这个bean上调用
setSessionContext()
2. 容器把这个bean(现在已经与他自己的上下文连接)放到这种类型bean的池中。
业务方法调用
1.客户在原先的EJB对象桩上调用一个业务方法。
2.容器从池中拉出一个bean。将他和客户的EJB对象连接
3.容器在bean上调用业务方法,方法返回给EJB对象,然后容器把这个bean发回到池中。
Interface EJBContext
| |
getCallerIdentity() | |
getCallerPrincipal() | |
getEJBHome() | |
getEJBLocalHome() | |
getEnvironment() | |
boolean | getRollbackOnly() |
getTimerService() | |
getUserTransaction() | |
boolean | isCallerInRole(Identity role) |
boolean | isCallerInRole(String roleName) |
void | setRollbackOnly() |
public interface SessionContext
extends EJBContext
getEJBLocalObject() | |
getEJBObject() | |
getMessageContext() |
Interface SessionBean—里面的方法是容器回调的方法
void | ejbActivate() |
void | ejbPassivate() |
void | ejbRemove() |
void | setSessionContext(SessionContext ctx) |
Context在sessionBean的作用
Bean方法 | 有状态 | 无状态 |
ejbCreate ejbRemove | sessionContext可以做 得到home的一个引用 得到EJB对象的一个引用 得到有关客户的安全信息 得到一个事务的引用,并在上面调用方法(BMT) | sessionContext可以做 得到home的一个引用 得到EJB对象的一个引用
|
ejbPassivate ejbActivate | sessionContext可以做 得到home的一个引用 得到EJB对象的一个引用 得到有关客户的安全信息 得到一个事务的引用,并在上面调用方法(BMT) |
其实 不适用 其实可以用适配器模式 实现无状态的会话bean不用写这些无用的方法 |
业务方法 | sessionContext可以做 得到home的一个引用 得到EJB对象的一个引用 得到有关客户的安全信息 要求一个事务回滚(CMT Bean) 确定事务是否回滚(CMT Bean) 得到一个事务的引用,并在上面调用方法(BMT) | sessionContext可以做 得到home的一个引用 得到EJB对象的一个引用 得到有关客户的安全信息 要求一个事务回滚(CMT Bean) 确定事务是否回滚(CMT Bean) 得到一个事务的引用,并在上面调用方法(BMT) |
实体bean
Interface EntityBean
void | ejbActivate() 个方法 |
void | ejbLoad() |
void | ejbPassivate() |
void | ejbRemove() |
void | ejbStore() |
void | setEntityContext(EntityContext ctx) |
void | unsetEntityContext() |
EntityBean的生命周期
序列图
实体Bean实例的构造过程
1. 容器建立一个新的EntityContext()
2. 容器建立bean类的一个新实例(运行bean的构造函数)
3. 容器在bean上调用setEntityContext();这是bean实例一生中惟一的一次调用这个方法
4. 容器把bean(现在有一个上下文)放入池中。
注意:creat()不会得到调用!create()方法只是用于向数据库中插入一个新实体,而与bean实例的创建无关。
实体bean创建过程
1. 客户在home桩上调用create(“zhuang”);――home桩指通过JNDI容器返回给客户端的一个home-stub
2. create(“zhuang”)方法调用传递到用home对象――这个值得是远程对象
3. 从池中取出一个bean来完成创建
4. 容器子bean实例上调用ejbcreate(“zhuang”);
5. 容器在数据库中插入一个对象的主键#55的新实例(行)
6. 容器把这个主键值交给EJB对象和EntityContext。
7. 容器在Bean上调用ejbPostCreate(“zhuang”),使bean有机会自行完成初始化。
8. home把EJB对象桩返回给客户。
实体创建期间可以做的Bean工作
Bean方法 |
|
ejbCreate
| 得到home的一个引用 得到EJB对象的一个引用 得到有关客户的安全信息 要求一个事务回滚(CMT Bean) 确定事务是否回滚(CMT Bean) |
ejbPostCreate() | 得到home的一个引用 得到EJB对象的一个引用 得到主键 得到有关客户的安全信息 要求一个事务回滚(CMT Bean) 确定事务是否回滚(CMT Bean)
|