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へのリンクを追加してください。
出典
2017-02-06 15:21:43
njr
@ njrの回答に追加:WebSphere traditionalではjava.sql.DataSourceを作成できません。 ConnectionPoolまたはXAのバリアントのみが許可されます。 –