目次 > 第2章 バッチフレームワークチュートリアル > 2.4 分割ジョブ > 2.4.1 ジョブBean定義ファイルの作成
2.4.1 ジョブBean定義ファイルの作成
本節では、分割ジョブのジョブBean定義ファイルの作成方法について説明する。
設計情報例
ジョブ定義例
手順
1.“JB0003.xml”を作成
- “batchapps\tutorial\UC0001”フォルダーを右クリックする。
- 「新規」→「ファイル」を選択し、ファイル名に“JB0003.xml”と入力し「終了」を押下する。
- “JB0001.xml”の内容を“JB0003.xml”にコピーする。
- “JB0001.xml”の内容
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> <!-- トランザクションモデル別Bean定義ファイルの雛形をインポート --> <import resource="classpath:template/ChunkTransactionBean.xml"/> <!--SqlMapConfig--> <bean id="sqlMapConfigFileName" class="java.lang.String"> <constructor-arg value="tutorial/UC0001/UC0001_sqlMapConfig.xml"/> </bean> <!--ジョブコンテキスト--> <bean id="jobContext" class="jp.terasoluna.batch.tutorial.uc0001.JB0001JobContext" /> <!--ジョブ前処理--> <util:list id="jobPreLogicList"> <bean class="jp.terasoluna.batch.tutorial.uc0001.jb0001.DBJobPreLogic"> <property name="queryDAO" ref="queryDAO" /> </bean> </util:list> <!--コレクタ定義--> <bean id="collector" parent="IBatisDbChunkCollector"> <property name="sql" value="UC0001.getNyukinData"/> </bean> <!--ビジネスロジック--> <bean id="blogic" class="jp.terasoluna.batch.tutorial.uc0001.jb0001.DBBLogic"> <property name="queryDAO" ref="queryDAO" /> <property name="updateDAO" ref="updateDAO" /> <property name="messageAccessor" ref="messageAccessor"/> </bean> <!--ジョブ後処理--> <util:list id="jobPostLogicList"> <bean class="jp.terasoluna.batch.tutorial.uc0001.jb0001.DBJobPostLogic"> <property name="updateDAO" ref="updateDAO" /> </bean> </util:list> </beans>
2. トランザクションモデル別Bean定義ファイルの雛形をインポート
本節では、チャンク別トランザクションモデル(分割ジョブ)を採用する。
そのため、“partitionChunkTransactionBean.xml”をインポートする必要がある。
“<import resource="classpath:template/chunkTransactionBean.xml"/>”の定義を以下のように修正する。
<import resource="classpath:template/partitionChunkTransactionBean.xml"/>
3. 多重実行数の定義
分割ジョブでは、分割したジョブの同時実行数を“multiplicity”に指定する必要がある。
以下の定義を<beans></beans>内に追加する。
<!-- 多重実行数 --> <bean id="multiplicity" class="java.lang.Integer"> <constructor-arg value="3"/> </bean>
4. 親ジョブ前処理の定義
「2.2.3 ジョブ前処理の実装」で作成したジョブ前処理は、ジョブを分割する前に起動する。
ジョブ前処理のBean“jobPreLogicList”を、親ジョブ前処理のBeanである“parentjobPreLogicList”に変更する。
<!-- 親ジョブ前処理 --> <util:list id="parentjobPreLogicList"> <bean class="jp.terasoluna.batch.tutorial.uc0001.jb0001.DBJobPreLogic"> <property name="queryDAO" ref="queryDAO" /> </bean> </util:list>
参考資料
- 『BA-01 トランザクション管理機能』
- 『BD-01 ビジネスロジック実行機能』