EJB方法总结
来源:互联网 发布:mac系统excel下拉菜单 编辑:程序博客网 时间:2024/05/22 10:58
通用的接口
Interface EJBObject
EJBHome
getEJBHome()得到bean的Home.
Handle
getHandle()保存EjbObject的一个引用
Object
getPrimaryKey() 得到实体bean的主键
boolean
isIdentical(EJBObject obj) 比较两个EJBObject是否引用同一个
void
remove() 对会话bean说释放这个bean为客户保留的资源
对实体bean来说 删除一行记录
Interface EJBMetaData
EJBHome
getEJBHome()
Obtain the remote home interface of the enterprise Bean.
Class
getHomeInterfaceClass()
Obtain the Class object for the enterprise Bean's remote home interface.
Class
getPrimaryKeyClass()
Obtain the Class object for the enterprise Bean's primary key class.
Class
getRemoteInterfaceClass()
Obtain the Class object for the enterprise Bean's remote interface.
boolean
isSession()
Test if the enterprise Bean's type is "session".
boolean
isStatelessSession()
Test if the enterprise Bean's type is "stateless session".
Interface EJBHome
EJBMetaData
getEJBMetaData() 从Bean得到反射子类的信息
Obtain the EJBMetaData interface for the enterprise Bean.
HomeHandle
getHomeHandle() 对home串行化,可以通过这个方法再次得到和使用这个home,无需通过JNDI
Obtain a handle for the remote home object.
void
remove(Handle handle) 删除会话bean
Remove an EJB object identified by its handle.
void
remove(Object primaryKey)删除实体Bean
Remove an EJB object identified by its primary key.
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
Identity
getCallerIdentity()
Deprecated. Use Principal getCallerPrincipal() instead.
Principal
getCallerPrincipal()
Obtain the java.security.Principal that identifies the caller.
EJBHome
getEJBHome()
Obtain the enterprise bean's remote home interface.
EJBLocalHome
getEJBLocalHome()
Obtain the enterprise bean's local home interface.
Properties
getEnvironment()
Deprecated. Use the JNDI naming context java:comp/env to access enterprise bean's environment.
boolean
getRollbackOnly()
Test if the transaction has been marked for rollback only.
TimerService
getTimerService()
Get access to the EJB Timer Service.
UserTransaction
getUserTransaction()
Obtain the transaction demarcation interface.
boolean
isCallerInRole(Identity role)
Deprecated. Use boolean isCallerInRole(String roleName) instead.
boolean
isCallerInRole(String roleName)
Test if the caller has a given security role.
void
setRollbackOnly()
Mark the current transaction for rollback.
public interface SessionContext
extends EJBContext
EJBLocalObject
getEJBLocalObject()
Obtain a reference to the EJB local object that is associated with the instance.
EJBObject
getEJBObject()
Obtain a reference to the EJB object that is currently associated with the instance.
MessageContext
getMessageContext()
Obtain a reference to the JAX-RPC MessageContext.
Interface SessionBean—里面的方法是容器回调的方法
void
ejbActivate()
The activate method is called when the instance is activated from its "passive" state.
void
ejbPassivate()
The passivate method is called before the instance enters the "passive" state.
void
ejbRemove()
A container invokes this method before it ends the life of the session object.
void
setSessionContext(SessionContext ctx)
Set the associated session context
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()
从池中取出bean,为客户的业务方法调用提供服务时调用这
个方法
void
ejbLoad()
bean已经用底层持久存储库的数据刷新时调用这个方法
void
ejbPassivate()
bean在事务结束之后要返回到池中时会调用这个方法.
void
ejbRemove()
客户调用remove().想从数据库中删除这个实体时调用这个方法
void
ejbStore()
当容器要更新数据库来反映bean状态时调用这个方法.
void
setEntityContext(EntityContext ctx)
Set the associated entity context.
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)
- EJB方法总结
- Weblogic中EJB调用方法总结
- EJB 总结
- EJB总结
- EJB总结
- EJB总结
- EJB总结
- weblogic——远程/近程调用EJB的方法总结
- EJB核心技术应用总结
- 第一次编写EJB总结!
- EJB 3.0 总结
- @EJB注释的总结
- EJB学习总结
- ejb学习总结
- EJB 理解学习总结
- EJB总结一
- EJB总结(一)
- ejb知识点总结
- 数学之美 系列九 -- 如何确定网页和查询的相关性
- C#2.0学习--反射与程序集
- Google 黑板報 - 數學之美系列
- js获取table中td的绝对坐标
- 一个小的OS内核,一些感受,一些总结。
- EJB方法总结
- 我的第一个blog
- 股指鹰击长空 个股百舸争流
- 改写JSTL标签
- 如何得到鼠标的坐标
- FCKeditor 2.2 + Asp.Net 设置(收藏)
- DOM属性用法速查手册
- 分析:百度的日本梦
- 常见网络错误代码