WebSphere Application Server Version 6.1 Feature Pack for Web Services   
             オペレーティング・システム: AIX , HP-UX, i5/OS, Linux, Solaris, Windows, Windows Vista, z/OS

             目次と検索結果のパーソナライズ化

カスタム DataStoreHelper クラスの開発

WebSphere 拡張機能である GenericDataStoreHelper クラスを適用して、Application Server がサポートしないデータ・ソースに、独自のデータ・ストア・ヘルパーを作成します。 このヘルパー・クラスにより、JDBC 構成は、トランザクション中にデータベース固有の機能を使用できます。

始める前に

Application Server がサポートしないデータ・ソースを持つ構成を使用している場合、カスタム・データ・ストア・ヘルパーを作成することがあります。 このヘルパーを使用すると、データベースを活用して、トランザクション中に、それ以外の場合には利用可能にならない機能を実行できます。 ユーザー定義 DataStoreHelper クラスを定義する必要があります。そのクラスには、カスタム・データ・ハンドラーの利用に伴い発生する可能性のあるすべての例外をキャッチする、新規の例外ハンドラーを作成するための情報があります。

プロシージャー

  1. com.ibm.websphere.rsadapter.GenericDataStoreHelper.java クラスを拡張するクラスを作成します。 次のコードをサンプルとして使用してください (このデータ・ソースのタイプは、 ユーザー定義の JDBC プロバイダーに基づいています)。
    package com.ibm.websphere.examples.adapter;
    
    import java.sql.SQLException;
    import javax.resource.ResourceException;
    
    import com.ibm.websphere.appprofile.accessintent.AccessIntent;
    import com.ibm.websphere.ce.cm.*;
    import com.ibm.websphere.rsadapter.WSInteractionSpec;
    
    /**
    * Example DataStoreHelper class, demonstrating how to create a user-defined DataStoreHelper.
    * Implementation for each method is provided only as an example.  More detail would likely be
    * required for any custom DataStoreHelper created for use by a real application.
    * In this example, we will override the doStatementCleanup(),getIsolationLevel(), and set userDefined
    * exception map
    */
    public class ExampleDataStoreHelper extends com.ibm.websphere.rsadapter.GenericDataStoreHelper
    {
    
        public ExampleDataStoreHelper(java.util.Properties props)
        {
            super(props);
    
            // Update the DataStoreHelperMetaData values for this helper.
            getMetaData().setGetTypeMapSupport(false);
    
            // Update the exception mappings for this helper.
            java.util.Map xMap = new java.util.HashMap();
    
            // Add an Error Code mapping to StaleConnectionException.
            xMap.put(new Integer(2310),  StaleConnectionException.class);
            // Add an Error Code mapping to DuplicateKeyException.
            xMap.put(new Integer(1062),  DuplicateKeyException.class);
            // Add a SQL State mapping to the user-defined ColumnNotFoundException
            xMap.put("S0022",            ColumnNotFoundException.class);
            // Undo an inherited StaleConnection SQL State mapping.
            xMap.put("S1000",            Void.class);
    
            setUserDefinedMap(xMap);
    
            // If you are extending a helper class, it is
            // normally not necessary to issue 'getMetaData().setHelperType(...)'
            // because your custom helper will inherit the helper type from its
            // parent class.                          
    
             }
    
        public void doStatementCleanup(java.sql.PreparedStatement stmt) throws SQLException
        {
            // Clean up the statement so it may be cached and reused.
    
            stmt.setCursorName("");
            stmt.setEscapeProcessing(true);
            stmt.setFetchDirection(java.sql.ResultSet.FETCH_FORWARD);
            stmt.setMaxFieldSize(0);
            stmt.setMaxRows(0);
            stmt.setQueryTimeout(0);
        }
    
    
    
        public int getIsolationLevel(AccessIntent intent) throws ResourceException
        {
            // Determine an isolation level based on the AccessIntent.
    
            // set WebSphere default isolation level to TRANSACTION_SERIALIZABLE.
            if (intent == null) return java.sql.Connection.TRANSACTION_SERIALIZABLE;
    
            return intent.getConcurrencyControl() == AccessIntent.CONCURRENCY_CONTROL_OPTIMISTIC ?
                   java.sql.Connection.TRANSACTION_READ_COMMITTED :
                   java.sql.Connection.TRANSACTION_REPEATABLE_READ;
        }
            public int getLockType(AccessIntent intent) {
               if ( intent.getConcurrencyControl() == AccessIntent.CONCURRENCY_CONTROL_PESSIMISTIC) {
                  if ( intent.getAccessType() == AccessIntent.ACCESS_TYPE_READ ) {
                      return WSInteractionSpec.LOCKTYPE_SELECT;
                  }
                  else {
                      return WSInteractionSpec.LOCKTYPE_SELECT_FOR_UPDATE;
                   }
               }
               return WSInteractionSpec.LOCKTYPE_SELECT;
            }
    }
    
  2. オプション: 独自の例外ハンドラー・クラスを作成します。 次のコードをガイドとして使用してください。
    package com.ibm.websphere.examples.adapter;
    
    import java.sql.SQLException;
    import com.ibm.websphere.ce.cm.PortableSQLException;
    
    /**
    * Example PortableSQLException subclass, which demonstrates how to create a user-defined
    * exception for exception mapping.
    */
    public class ColumnNotFoundException extends PortableSQLException
    {
        public ColumnNotFoundException(SQLException sqlX)
        {
            super(sqlX);
        }
    }
    
  3. 新規作成の DataStoreHelper クラスを 1 つまたは複数コンパイルします。 これらをコンパイルするには、クラスパスに以下の JAR ファイルが必要です。
    • app_server_root¥lib¥j2ee.jar
    • app_server_root¥lib¥rsahelpers.jar
    • app_server_root¥plugins¥com.ibm.ws.runtime_version.jar.
      注: version の数値は、稼働している Application Server のバージョンに応じて異なります。 最近の Application Server のリリースでは、このファイル名からバージョン番号が除外されている可能性があります。
    • Eclipse のような開発環境を使用している場合、コンパイルを行えるようにするには、上記の JAR ファイルをクラスパスに設定する必要があります。 ファイルの編集が終了したら、プロジェクトの JAR ファイルを作成します (個々の指示については、ご使用の開発環境のヘルプ文書を参照してください)。
    • 開発環境を持たず、javac コンパイラーを使用している場合の手順は、次のとおりです。
      1. GenericDataStoreHelper を拡張する .java ファイルを (ステップ 1 に従って) 作成します。
      2. コマンド行ユーティリティーでファイルを編集した後で、ホーム・ディレクトリーに移動します。
      3. 次のコマンドを使用してクラスパスを設定します。
        [Windows] Windows オペレーティング・システムの場合:
        set CLASSPATH=%CLASSPATH%;app_server_root¥lib¥j2ee.jar;app_server_root¥lib¥rshelpers.jar;app_server_root¥plugins¥com.ibm.ws.runtime_version.jar
        
        [AIX] [HP-UX] [Linux] [Solaris] UNIX オペレーティング・システム (またはその類似システム) の場合:
         set CLASSPATH=$CLASSPATH:app_server_root/lib/j2ee.jar:app_server_root/lib/rshelpers.jar:app_server_root/plugins/com.ibm.ws.runtime_version.jar
      4. クラスを 1 つまたは複数コンパイルします。 例えば、Windows オペレーティング・システムでは次のコマンドを入力します (この場合、指定ディレクトリーにある .java ファイルがすべてコンパイルされます)。
        C:¥javac your_directory¥*.java
      5. Java ディレクトリーから、独自のディレクトリー内にすべてのコンパイル済みクラス・ファイルを入れる JAR ファイルを作成します。 例えば、Windows オペレーティング・システムでは、次のコマンドを入力します (myFile は、使用したい JAR ファイル名に変更してください)。
         C:¥Java> jar cf myFile.jar *.class
        javac コンパイラーの使用の詳細については、Sun Microsystems の java コンパイラー関連の Web サイトを参照してください。
  4. コンパイル済みの JAR ファイルを app_server_root¥lib¥ext ディレクトリーに配置します。 このディレクトリーはデフォルトでは存在しない場合があります。その場合は、 app_server_root¥lib ディレクトリーに ext ディレクトリーを作成する必要があります。
  5. 新規のクラスを使用するように Application Server を構成します。
    注: この構成は、例外ハンドラーの追加のみが必要である場合には必要ありません。
    1. 管理コンソールから、「リソース」 > 「JDBC」 > 「データ・ソース」 を選択します。
    2. リスト内にデータ・ソースがない場合は、有効範囲を「すべての有効範囲」に変更します。
    3. デフォルトのデータ・ソースを選択します。
    4. 「名前」 フィールドにデータ・ソースの名前を入力します。
    5. 「データ・ストアのヘルパー・クラス名」というラベルの付いたセクションで、 「ユーザー定義のデータ・ストア・ヘルパーを指定」を選択します。
    6. 作成したデータ・ストア・ヘルパーのクラス名を入力します。
    7. 変更を適用して、「OK」を選択します。



関連概念
リソース・アダプター
タスク・トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 4:10:06 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/tdat_cusdatstore.html