2017-02-05 9 views
1

hiber-jdbc.jarを使用して、WebSphere 8.5.5.11でJNDIデータソースを設定しようとしています。 WebSphereでコンソールを使用し、フォームを使用して新しいJDBCプロバイダーを作成する場合、実装クラス名のフィールドがあります。 WebSphereでは、クラスにjavax.sql.XADataSourceまたはjavax.sql.ConnectionPoolDataSourceを実装する必要があります。しかし、hive-jdbcドライバはこれらのものを実装しておらず、java.sql.DataSourceしか実装していません。 このため、動作しません.WebSphereは、フォームの保存時にエラーを報告します。WebSphereでhive-jdbc JNDIデータソースを定義します。

enter image description here

私はこれについて何ができるか任意のアイデア?

答えて

2

javax.sql.DataSourceの実装に委譲するjavax.sql.ConnectionPoolDataSourceの簡単な実装を書くことができます。ここでは、JDBCドライバのJAR(複数可)と一緒にJARにコンパイルしたクラス

package example.datasource; 

import java.sql.*; 
import javax.sql.*; 

public class HiveConnectionPoolDataSource extends org.apache.hive.jdbc.HiveDataSource implements ConnectionPoolDataSource { 
    public PooledConnection getPooledConnection() throws SQLException { 
     return new HivePooledConnection(null, null); 
    } 

    public PooledConnection getPooledConnection(String user, String password) throws SQLException { 
     return new HivePooledConnection(user, password); 
    } 

    public boolean isWrapperFor(Class<?> iface) throws SQLException { 
     return ConnectionPoolDataSource.class.equals(iface) || super.isWrapperFor(iface); 
    } 

    public <T> T unwrap(Class<T> iface) throws SQLException { 
     return ConnectionPoolDataSource.class.equals(iface) ? (T) this : super.unwrap(iface); 
    } 

    class HivePooledConnection implements PooledConnection { 
     private Connection con; 
     private final String user; 
     private final String password; 

     HivePooledConnection(String user, String password) { 
      this.user = user; 
      this.password = password; 
     } 

     public void addConnectionEventListener(ConnectionEventListener listener) {} 

     public void addStatementEventListener(StatementEventListener listener) {} 

     public void close() throws SQLException { 
      if (con != null) { 
       con.close(); 
       con = null; 
      } 
     } 

     public Connection getConnection() throws SQLException { 
      if (con == null || con.isClosed()) { 
       con = user == null 
         ? HiveConnectionPoolDataSource.this.getConnection() 
         : HiveConnectionPoolDataSource.this.getConnection(user, password); 
       return con; 
      } else 
       throw new IllegalStateException(); 
     } 

     public void removeConnectionEventListener(ConnectionEventListener listener) {} 

     public void removeStatementEventListener(StatementEventListener listener) {} 
    } 
} 

パッケージ、一例であり、それはの一部であるかのように、このJARを指すようにWebSphere Application ServerでカスタムJDBCプロバイダーを設定JDBCドライバ実装クラス名をexample.datasource.HiveConnectionPoolDataSourceと指定するか、独自の実装に選択したパッケージ/名前を指定します。これで、JDBCドライバを使用できるようになります。

また、誰でもjavax.sql.DataSourceのサポートをリクエストしたい場合は、WebSphere Application Server request for enhancements pageへのリンクを追加してください。

+0

@ njrの回答に追加:WebSphere traditionalではjava.sql.DataSourceを作成できません。 ConnectionPoolまたはXAのバリアントのみが許可されます。 –

関連する問題