Comments
Description
Transcript
目 次
目 次 はじめに 第 1 章 EJB コンポーネントとは············································································ 15 1.1 これまでの C/S システムと分散オブジェクト ·············································· 16 1.1.1 クライアント/サーバと分散オブジェクト······················································ 16 1.1.2 分散オブジェクト ······························································································ 18 1.1.3 CORBA による分散オブジェクト ··································································· 20 1.1.4 Java 標準の分散オブジェクト−Java-RMI ·················································· 22 1.1.5 Java ローカルコンポーネント−JavaBeans ················································· 24 1.2 EJB 仕様の目的と概要 ····················································································· 27 1.2.1 EJB が目指すもの ····························································································· 27 1.2.2 ネットワーク/分散の隠蔽 ················································································· 28 1.2.3 インスタンス管理の分離 ·················································································· 29 1.2.4 永続性の分離 ······································································································ 30 (1) JDBC アクセス ·································································································· 30 (2) トランザクション制御との連携 ······································································ 30 (3) エンティティとインスタンスの分離······························································· 31 1.2.5 トランザクション管理の分離 ·········································································· 31 (1) JTS(Java Transaction Service)······································································ 32 (2) JTA(Java Transaction API) ··········································································· 32 (3) リソースマネージャ ·························································································· 33 7 第 2 章 EJB アーキテクチャ ····················································································· 35 2.1 EJB の全体像 ····································································································· 36 2.2 6 つのロールとシナリオ ··················································································· 38 (1) エンタプライズ Bean プロバイダ ··································································· 39 (2) アプリケーションアセンブラ ·········································································· 39 (3) デプロイヤ ·········································································································· 39 (4) EJB サーバプロバイダ ····················································································· 40 (5) EJB コンテナプロバイダ ················································································· 40 (6) システム管理者 ·································································································· 40 (7) シナリオ ·············································································································· 41 2.3 EJB アクセスモデル ························································································· 42 (1) EJBHome オブジェクトと home インタフェース ······································· 42 (2) EJBObject と remote インタフェース ··························································· 43 (3) エンタプライズ Bean 開発の 3 つの基本セット ··········································· 43 2.4 EJB サーバ(EJB コンテナとネーミングサービス) ······································ 44 (1) EJB コンテナ ····································································································· 44 (2) ネーミングサービス ·························································································· 44 2.5 EJBHome と home インタフェース······························································· 45 2.6 EJBObject と remote インタフェース ··························································· 46 2.7 Bean の種類 ······································································································· 47 2.8 Bean インスタンスの一生 ················································································ 48 (1) エンタプライズ Bean の識別 ··········································································· 49 (2) remove メソッド ······························································································· 50 2.9 セッション Bean ······························································································· 50 2.9.1 ステートレスセッション Bean ········································································ 52 2.9.2 ステートフルセッション Bean ········································································ 53 2.9.3 ステートフルセッション Bean の非活性化 ··················································· 54 2.10 エンティティ Bean ··························································································· 55 2.10.1 主キークラス ······································································································ 57 2.10.2 BMP エンティティ Bean ················································································· 58 2.10.3 CMP エンティティ Bean ················································································· 59 8 2.10.4 エンティティ Bean の home インタフェース ··············································· 60 2.10.5 エンティティ Bean の home インタフェースの例外 ··································· 63 2.10.6 エンティティ Bean の永続化コード ······························································· 64 2.11 トランザクション管理 ······················································································ 66 2.11.1 Bean 管理によるトランザクション区切り ···················································· 66 2.11.2 コンテナ管理によるトランザクション区切り ··············································· 67 2.11.3 BeanManaged ··································································································· 68 2.11.4 NotSupported ···································································································· 69 2.11.5 Required ············································································································· 70 2.11.6 Supports ············································································································· 72 2.11.7 RequiresNew ····································································································· 73 2.11.8 Mandatory ········································································································· 74 2.11.9 Never ·················································································································· 75 2.11.10 クライアント管理によるトランザクション区切り ······································· 75 2.11.11 分離レベル ·········································································································· 76 2.11.12 SessionSynchronization インタフェース······················································ 78 2.12 セキュリティ ······································································································ 79 (1) アプリケーションアセンブラが行うこと······················································· 79 (2) デプロイヤが行うこと ······················································································ 80 (3) Bean クラスが行うこと···················································································· 80 2.13 エンタプライズ Bean からの例外 ··································································· 81 (1) アプリケーション例外 ······················································································ 81 (2) システム例外 ······································································································ 82 (3) EJB クライアントでの例外処理 ····································································· 82 2.14 デプロイメント記述 ·························································································· 84 2.15 エンタプライズ Bean 環境 ··············································································· 86 (1) EJBContext.getEnvironment()メソッド ······················································ 87 (2) JNDI からの取得 ······························································································· 87 2.16 J2EE での位置づけと開発モデル ··································································· 88 2.17 開発手法とデプロイ ·························································································· 89 9 第 3 章 EJB 仕様の変遷 ······························································································ 93 3.1 EJB 誕生前夜から EJB2.0 まで ······································································ 93 3.1.1 アプレット用簡易言語から実用言語への道 ··················································· 93 3.1.2 サーバサイドコンポーネントモデルの誕生 ··················································· 96 3.1.3 Java 2 と EJB1.1 ······························································································ 98 3.1.4 JCP と EJB2.0··································································································· 99 3.2 EJB1.0 から EJB1.1 への移行 ······································································ 104 (1) デプロイメント記述の変換 ············································································ 104 (2) コンテナ管理による永続性(CMP)を利用するときの ejbCreate の返却値型 ··························································································································· 104 (3) 例外の取り扱い ································································································ 105 (4) エンタプライズ Bean 環境(EBE)変数の取得 ·············································· 105 (5) home インタフェースの取得 ········································································· 105 (6) UserTransaction クラスの違い ···································································· 106 (7) セッション Bean の transient 変数 ······························································ 106 (8) 主キークラスの hashCode と equals ··························································· 106 3.3 最新 EJB 仕様紹介 ·························································································· 108 3.3.1 ローカルインタフェース ················································································ 108 3.3.2 メッセージドリブン Bean ·············································································· 115 3.3.3 抽象永続スキーマによる CMP ······································································ 122 3.3.4 コンテナ管理によるエンティティ Bean 間関連 ········································· 129 3.3.5 Enterprise JavaBeans Query Language(EJB QL) ·································· 134 (1) FROM 句 ·········································································································· 136 (2) WHERE 句 ······································································································· 136 (3) SELECT 句 ······································································································ 137 3.3.6 home インタフェースの機能拡張 ································································· 138 第 4 章 EJB コンポーネント流通の取り組み ·················································· 141 10 4.1 コンポーネント流通市場(マーケットプレイス)の誕生 ······························ 142 4.2 EJB コンポーネントに関するコンソーシアム ············································ 143 4.2.1 コンソーシアムの活動内容 ············································································ 144 4.3 ポータブルなコンポーネントを作るために ················································· 147 4.3.1 ポータブルコンポーネント規約策定の目的 ················································· 148 4.3.2 ポータブルコンポーネント規約の対象範囲 ················································· 149 4.3.3 ポータビリティの定義 ···················································································· 152 4.3.4 ポータビリティの定義に含まないこと························································· 157 4.3.5 規約···················································································································· 159 (1) エンタプライズ Bean 全般 ············································································· 159 (1-1) プロセス境界に依存した操作の禁止····························································· 159 (1-2) エンタプライズ Bean 呼び出しに関する規約 ············································· 162 (1-3) セキュリティ管理に関する規約 ···································································· 172 (1-4) 分散処理管理に関する規約 ············································································ 175 (1-5) 入出力に関する規約 ························································································ 175 (1-6) オブジェクト同一性の仮定の禁止 ································································ 177 (1-7) コールバックメソッドでのタイミング依存ロジック実装の禁止 ············· 181 (1-8) 利用コンポーネント/クラスの等価性 ··························································· 182 (1-9) handle の有効性仮定の禁止··········································································· 186 (2) セッション Bean ····························································································· 186 (2-1) データフィールド使用方法の制約 ································································ 186 (2-2) ejbRemove への依存禁止 ··············································································· 191 (3) エンティティ Bean ························································································· 192 (3-1) データベースに格納しないデータフィールドに関する処理 ····················· 192 (4) Bean 管理による永続性(BMP) ······································································ 196 (4-1) 主キーオブジェクトの同一性を前提とした実装の禁止 ····························· 196 (5) コンテナ管理による永続性(CMP) ································································ 198 (5-1) コンテナ管理による永続性の機能範囲························································· 198 (5-2) 主キーの制限 ···································································································· 199 (6) トランザクション ···························································································· 200 (6-1) 伝播するトランザクションのロールバック検出の制限 ····························· 200 (7) エンタプライズ Bean 環境 ············································································· 201 (7-1) エンタプライズ Bean 環境へのアクセス ····················································· 201 11 第 5 章 EJB コンポーネント作成技法 ································································ 203 5.1 EJB コンポーネントをデザインする···························································· 204 5.1.1 外部仕様の決定 ································································································ 204 5.1.2 内部仕様の決定 ································································································ 206 5.2 例題:商品コンポーネント ············································································ 208 5.2.1 要求仕様 ············································································································ 208 5.2.2 データ構造 ········································································································ 209 5.2.3 アプリケーションとしてのモデル化····························································· 210 (1) セッション Bean でラッピングする ····························································· 211 (2) アクセス用のプロキシクラスを作る····························································· 212 5.3 名前の整理 ········································································································ 213 5.4 例外クラスの定義 ···························································································· 214 5.5 home ヘルパー ································································································· 218 5.6 home インタフェースの定義 ········································································· 222 5.7 remote インタフェースの定義 ······································································ 225 5.8 エンタプライズ Bean クラスの実装 ····························································· 229 5.8.1 主キークラス ···································································································· 229 5.8.2 CMP エンティティ Bean ··············································································· 231 5.8.3 カスタム finder ································································································ 243 5.8.4 BMP エンティティ Bean ··············································································· 244 (1) setEntityContext,unsetEntityContext ···················································· 244 (2) ejbCreate,ejbFindXXX,ejbStore,ejbLoad,ejbRemove ··················· 245 5.9 ラッピング用のセッション Bean ·································································· 245 5.9.1 ステートレスセッション Bean ······································································ 245 5.9.2 ステートフルセッション Bean ······································································ 254 5.9.3 トランザクショナルセッション Bean ·························································· 254 5.10 クライアントコードの実装 ············································································ 256 5.11 アクセス用プロキシクラス ············································································ 261 5.12 課題点と改善のアイデア ················································································ 266 5.12.1 home ヘルパーのデザイン ············································································· 266 5.12.2 エンティティ Bean メソッドの粒度 ····························································· 267 12 索 引 ································································································································ 269 13