カスタム DataStoreHelper クラスの開発

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

始める前に

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

このタスクについて

非推奨の機能 (Deprecated feature) 非推奨の機能 (Deprecated feature): com.ibm.websphere.rsadapter.DataStoreHelper クラス API の CUSTOM_HELPER 定数フィールドは非推奨です。独自の DataStoreHelper 実装クラスを作成する場合は、 setHelperType(DataStoreHelper.CUSTOM_HELPER) を呼び出さないでください。その代わりに、 継承元の実装クラスによって HelperType 値が設定されるようにします。depfeat

手順

  1. 既存のデータ・ストア・ヘルパーを拡張するクラスを作成します。 次のコードをサンプルとして使用してください。このデータ・ソースのタイプは、 ユーザー定義の 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.
    * The implementation for each method is provided only as an example.  More detail is probably
    * required for any custom DataStoreHelper that is 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/dev/JavaEE/j2ee.jar
    • app_server_root/dev/was_public.jar
      トラブルの回避 (Avoid trouble) トラブルの回避 (Avoid trouble): was_public.jar は、カスタム DataStoreHelper クラスをコンパイルするのに必要な、app_server_root/lib/rsahelpers.jar のクラスを含んでいます。gotcha
    • app_server_root/plugins/com.ibm.ws.runtime.jar
    • Eclipse のような開発環境を使用している場合、コンパイルできるようにするには、これらの JAR ファイルをクラスパスに設定する必要があります。 ファイルの編集が終了したら、プロジェクトの JAR ファイルを作成します (個々の指示については、ご使用の開発環境のヘルプ文書を参照してください)。
    • 開発環境を持たず、javac コンパイラーを使用している場合の手順は、次のとおりです。
      1. GenericDataStoreHelper または他の任意のデータ・ストア・ヘルパーを拡張する .java ファイルを、ステップ 1 に従って作成します。
      2. コマンド行ユーティリティーでファイルを編集した後で、ホーム・ディレクトリーに移動します。
      3. 次のコマンドを使用してクラスパスを設定します。
        [Windows]
        set CLASSPATH=%CLASSPATH%;app_server_root¥dev¥JavaEE¥j2ee.jar;app_server_root¥dev¥was_public.jar;app_server_root¥plugins¥com.ibm.ws.runtime.jar
        [AIX][HP-UX][Linux][Solaris]
         set CLASSPATH=$CLASSPATH:app_server_root/dev/JavaEE/j2ee.jar:app_server_root/dev/was_public.jar:app_server_root/plugins/com.ibm.ws.runtime.jar
      4. クラスを 1 つまたは複数コンパイルします。 例えば、Windows オペレーティング・システムでは次のコマンドを入力します (この場合、指定ディレクトリーにある .java ファイルがすべてコンパイルされます)。
        C:¥javac your_directory¥*.java
      5. Java ディレクトリーから、独自のディレクトリー内にすべてのコンパイル済みクラス・ファイルを入れる JAR ファイルを作成します。 例えば、Windows オペレーティング・システムでは、次のコマンドを入力します (myFile は、使用する JAR ファイル名に変更してください)。
         C:¥Java> jar cf myFile.jar *.class
        javac コンパイラーの使用の詳細については、Java™ コンパイラー関連の Oracle Web サイトを参照してください。
  4. コンパイル済みの JAR ファイルをディレクトリー内に配置し、JDBC プロバイダーのクラスパスを更新してその場所を組み込みます。 例えば、JAR ファイルが c:¥myFile.jar の場合は、必ず JDBC クラスパスを変更して c:¥myFile.jar を組み込みます。
    1. 「リソース」 > 「JDBC」 > 「JDBC プロバイダー」> 「JDBC_provider」とクリックします。
    2. 「クラスパス」フィールドに、コンパイルした JAR ファイルの場所を追加します。 例えば、フィールド内で ENTER キーを押して、次の新しい行を追加します。
      c:¥myFile.jar
  5. 新規のカスタム DataStoreHelper クラスを使用するように、 アプリケーション・サーバーを構成します。
    1. 管理コンソールから、「リソース」>「JDBC」>「データ・ソース」を選択します。
    2. カスタム DataStoreHelper クラスで構成するデータ・ソースを選択します。
    3. 「データ・ストアのヘルパー・クラス名」というラベルの付いたセクションで、 「ユーザー定義のデータ・ストア・ヘルパーを指定」を選択します。
    4. 作成したデータ・ストア・ヘルパーのクラス名を入力します。
    5. 変更を適用して、「OK」を選択します。

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tdat_cusdatstore
ファイル名:tdat_cusdatstore.html