EJB方法总结

通用的接口

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值