2011年5月10日 星期二

SCEA Ch07(2) - enterprise JavaBeans and the EJB Container Model

這章節好長喔 我的天兒阿 ~~

  • Entity Beans


EJB 3.0當中對於 persistence提供了三種的解決方案

  1. Use Entity beans for persistence

  2. Use Persistence API entities

  3. Use other persistence technology such as Java Data Objects or JDBC


所以從這裡可以發現,對於既有的entitybean 還是全數支援的,但不敢貿然抽掉想必也是為了向下相容吧


  • Session Bean 用法介紹


interface Count{

// biz methods

}

@Stateful  --> 標記為stateful session bean

@Remote(Count.class) --> remote interface 為 Count

@Interceptors(CountCallbacks.class)  --> bean class 的 life cycle call back interceptor class

public class CountBean implements Count{

//biz methods

}

對於要能提供一個完整的stateful bean class ,那麼給予他一個interceptor 是必然的

interceptor通常會包含有 @PostConstruct , @PostActivate , @Prepassivate , @PreDestroy

而在DD的設置上,以下提供參考(DD非必備的)

// Page 106 - Mastering EJB 3.0


  • Session Bean Life Cycle


EJB container在實體化business bean class時,是以下列方式進行

Class.newInstance("HelloBean.class"); 但這必須在bean class中至少保有 default non-arg constructor 才可以達成...

Container 會透過注入的方式塞入任何必要或需要的context到 bean instance。

接續對於有任何設置callback apis 的method則會在對應的事件當中去執行!!

// Page 111 , 113

沒有留言: