사용자 정의 DataStoreHelper 클래스 개발

WebSphere® 확장, GenericDataStoreHelper 클래스를 적용하여 Application Server가 지원하지 않는 데이터 소스에 대한 자신의 데이터 저장소 헬퍼를 작성합니다. 이 헬퍼 클래스로 JDBC 구성은 트랜잭션 중에 데이터베이스별 기능을 사용할 수 있습니다.

시작하기 전에

Application Server가 지원하지 않는 데이터 소스가 있는 구성을 사용 중인 경우 사용자 정의 데이터 저장소 헬퍼를 작성할 수 있습니다. 이 헬퍼로 데이터베이스를 이용하여 트랜잭션 중에 기능을 수행할 수 있습니다. 이는 헬퍼가 없으면 사용 불가능합니다. 사용자 정의 DataStoreHelper 클래스를 작성할 필요가 있으며, 사용자 정의 데이터 핸들러 사용으로 인해 발생할 수 있는 예외를 발견하기 위해 새 예외 핸들러를 작성하기 위한 정보가 있습니다.

이 태스크 정보

제거된 기능 제거된 기능: 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 클래스를 컴파일하십시오. 컴파일하려면 클래스 경로에 다음 JAR 파일이 필요합니다.
    • app_server_root/dev/JavaEE/j2ee.jar
    • app_server_root/dev/was_public.jar
      문제점 방지 문제점 방지: 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. 단계 1에 표시된 대로, GenericDataStoreHelper 또는 다른 데이터 저장소 헬퍼를 확장하는 .java 파일을 작성하십시오.
      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. 단일 또는 복수 클래스를 컴파일하십시오. 예를 들어, Windows 운영 체제는 다음 명령을 입력합니다(이 명령은 지정한 디렉토리의 모든.java 파일을 컴파일함).
        C:\javac your_directory\*.java
      5. Java 디렉토리에서 자신의 디렉토리에 컴파일한 모든 클래스 파일의 JAR 파일을 작성하십시오. 예를 들어, Windows 운영 체제에서는 다음 명령을 입력하십시오. (myFile을 JAR 파일에 원하는 이름으로 변경하십시오.)
         C:\Java> jar cf myFile.jar *.class
        javac 컴파일러 사용에 관한 자세한 정보는 Oracle 웹 사이트에서 Java™ 컴파일러에 대한 내용을 참조하십시오.
  4. 컴파일한 JAR 파일을 디렉토리에 배치하고 JDBC 제공자에 대한 클래스 경로를 이 위치를 포함하도록 업데이트하십시오. 예를 들어, JAR 파일이 c:\myFile.jar이면 JDBC 클래스 경로를 c:\myFile.jar을 포함하도록 수정하십시오.
    1. 자원 > JDBC > JDBC 제공자 > JDBC_provider를 클릭하십시오.
    2. 클래스 경로 필드에 컴파일한 JAR 파일의 위치를 추가하십시오. 예를 들어, 필드에서 ENTER를 누르고 새 행을 추가하십시오.
      c:\myFile.jar
  5. 새 사용자 정의 DataStoreHelper 클래스를 사용하도록 Application Server를 구성하십시오.
    1. 관리 콘솔에서 자원 > JDBC > 데이터 소스를 선택하십시오.
    2. 사용자 정의 DataStoreHelper 클래스와 구성하려는 데이터 소스를 선택하십시오.
    3. 섹션 레이블 지정된 데이터 저장소 헬퍼 클래스 이름이라 레이블 지정된 섹션에서 사용자 정의 데이터 저장소 헬퍼 지정을 선택하십시오.
    4. 작성한 데이터 저장소 헬퍼의 클래스 이름을 입력하십시오.
    5. 변경사항을 적용하고 확인을 선택하십시오.

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tdat_cusdatstore
파일 이름:tdat_cusdatstore.html