EJB方法总结

来源:互联网 发布:mac系统excel下拉菜单 编辑:程序博客网 时间:2024/05/22 10:58

通用的接口

Interface EJBObject

EJBHome

getEJBHome()得到beanHome.

 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".

 

 

 

 

javax.ejb
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对象的一个桩――就是-stubrmi中运用的

 

 

 

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

 

 

ContextsessionBean的作用

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.       homeEJB对象桩返回给客户。

 

实体创建期间可以做的Bean工作

Bean方法

 

 ejbCreate

 

得到home的一个引用

得到EJB对象的一个引用

得到有关客户的安全信息

要求一个事务回滚(CMT Bean

确定事务是否回滚(CMT Bean

ejbPostCreate()

得到home的一个引用

得到EJB对象的一个引用

得到主键

得到有关客户的安全信息

要求一个事务回滚(CMT Bean

确定事务是否回滚(CMT Bean

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 高铁票订错时间怎么办 微信音频视频打出没反应怎么办 海尔超低温保存箱低温报警怎么办 孕期吃了烧烤蔬菜怎么办 百姓动迁政府说话不算数怎么办 孕妇用了青草膏怎么办 药材不知道啥名怎么办 诛仙手游鸿蒙紫气不见了怎么办 紫叶兰叶干了怎么办 绿萝叶子中毒了怎么办? 怀孕初期胃疼的厉害怎么办 怀孕胃疼的厉害怎么办 天然气热水器风口一封闭怎么办 热水器着火后火变大怎么办? 人如果没有天魂怎么办 被鬼魂附体了该怎么办 被吸血蠓咬了怎么办 股份公司大股东占用资金怎么办 抱小孩抱的胳膊疼怎么办 一个月好几个性伴侣怎么办 惹了势力大的人怎么办 给佛像换新法器旧的怎么办 cad填充图案拾取不了点怎么办 cad填充图案太密怎么办 桃木葫芦挂件裂口了怎么办 皮肤被太阳晒伤变黑怎么办 皮肤又粗又黑该怎么办 盆栽红薯长疯了怎么办 四叶草叶子发黄怎么办 美篇不想让别人看到怎么办 黑魂3暗灵入侵怎么办 问道手游账号忘了怎么办 问道手游密码忘了怎么办 毒蚂蚁咬了红肿怎么办 电脑开机后有电流声怎么办 小学生阅读方面不会总结怎么办 天龙八部手游转职装备怎么办 投简历没回应该怎么办? 开车开的腰疼怎么办 开车腰疼怎么办吃什么 58简历投错了怎么办