JBoss EAP 6.4 で JNDI ループアップから TimesTenDataSource を取得しようとしました。timesten 用に standalone.xml でデータベースを構成しています。標準の Jdbc オブジェクト、つまり DataSource、Connection、PreparedStatement を使用すると、すべて機能します。何らかの理由で、ttjdbc8.jar から TimesTen 固有の TimesTenDataSource、TimesTenConnection、および TimesTenCallableStatement オブジェクトを使用したいと考えています。この jar ファイルは JBoss モジュール ディレクトリに置かれます。
InitialContext ic = new InitialContext();
TimesTenDataSource ds = null;
DataSource ods = (DataSource) ic.lookup(databaseJDNIName);
log.info("Original data source is " + ods);
/*** above line prints -- Original data source is org.jboss.jca.adapters.jdbc.WrapperDataSource@16174fbf ***/
TimesTenDataSource ds = ods.unwrap(com.timesten.jdbc.TimesTenDataSource.class);
/** ds is null here **/
TimesTenConnection tconn = ds.getConnection(); // throws null pointer exception
このスレッドへの参照として、基になる TimesTen 接続を取得するために unwrap を呼び出します。
上記のコードをデバッグすると、WrapperDataSource が拡張クラス JBossWrapper にある getWrappedObject() メソッドを実装していないことがわかります。
/**
* Get the wrapped object - override in sub-classes
* @return The object
* @exception SQLException Thrown if an error occurs
*/
protected Object getWrappedObject() throws SQLException
{
return null;
}
JbossWrapper クラスの unwrap メソッドは次のとおりです。
if (iface == null)
throw new IllegalArgumentException("Null interface");
if (iface.isAssignableFrom(getClass()))
return iface.cast(this);
Object wrapped = unwrapInnerMost(**getWrappedObject()**, iface);
getWrappedObject() が null を返すため、すべてが失敗します。
また、WrapperDataSource を TimesTenDataSource に直接キャストすることもできませんでした。これを行うと、ClassCastException が発生します。