pureQuery Generator ユーティリティーは、アノテーション付きメソッドを宣言するインターフェースを実装するクラスと、Data インターフェースのインプリメンテーションを拡張するクラスの両方を生成します。通常、アプリケーションでは Data インターフェースの多くのメソッドにアクセスする必要はないので、特定のアノテーション付きメソッド・インターフェースのインプリメンテーション・クラスをインスタンス化する DataFactory 内のメソッドは、実行時にそうしたアノテーション付きメソッド・インターフェースのインスタンスを戻します。
例えば、そうした DataFactory メソッドの 1 つがインターフェース MyInterface のインプリメンテーションをインスタンス化する場合に、myObject がメソッドの戻り値に設定されていると、myObject の型は MyInterface になります。myObject 内で Data メソッドにアクセスするアプリケーションの場合には、アプリケーションが myObject を Data オブジェクトにキャストする必要があります。
pureQuery Generator ユーティリティーがインプリメンテーション・クラスを生成する際に、そのクラスは BaseData という名前の Data インターフェースのインプリメンテーションをデフォルトで拡張します。 ただし、このインプリメンテーション・クラスは、BaseData を拡張する別のクラスを拡張することもできます。
データ・オブジェクトはスレッド・セーフではありません。 それらは複数のスレッドで共用しないでください。 Data オブジェクトは、作成されたのと同じスレッドでのみ使用してください。
Generator ユーティリティーが生成するインプリメンテーション・クラスからクラスを拡張する方法
package customer; public interface CommonInterface { public void startHeterogeneousBatch (); // this method "renames" the Data Interface method public int[][] endHeterogeneousBatch (); // this method "renames" the Data Interface method public int dynamicSQLUpdate (String updateSQL, Object... parameters); // this method "renames" the Data Interface method public <T> T[] dynamicQueryArray (String sql, Class<T> returnClass, Object... parameters); // this method "renames" the Data Interface method public void commit (); public void rollback (); // 他の Data インターフェース・メソッドもここにコーディングできます。 }
package customer; public class BaseData extends com.ibm.pdq.runtime.generator.BaseData implements CommonInterface { public <T> T[] dynamicQueryArray (String sql, Class<T> returnClass, Object... parameters) { return queryArray (sql, returnClass, parameters); } public int dynamicSQLUpdate (String updateSQL, Object... parameters) { return update (updateSQL, parameters); } public void startHeterogeneousBatch () { startBatch (heterogeneousModify__); return; } public int[][] endHeterogeneousBatch () { return endBatch (); } }
このクラスは、com.ibm.pdq.runtime.generator.BaseData を拡張することに注意してください。
import com.ibm.pdq.annotation.Update; public interface AutoGeneratedKeysInterface { @Update(sql = "insert into MYEMPLOYEE (name, salary, deptno) values(:name, :salary, :deptno)") int createEmployee (MyEmployeeBean bean); }
import com.ibm.pdq.annotation.Update; public interface AutoGeneratedKeysInterface extends customer.CommonInterface { @Update(sql = "insert into MYEMPLOYEE (name, salary, deptno) values(:name, :salary, :deptno)") int createEmployee (MyEmployeeBean bean); }
pureQuery ジェネレーターを使用してこのインターフェースのインプリメンテーション・クラスを生成する場合、オプション baseDataOverride に customer.BaseData を指定します。