ファイルを複数回処理することで、このような問題を解決しました。
すべてのパスで、次のような alg を使用して、ファイル内のすべてのレコードを読み取り\処理しようとします。
- if record has parent - 親がすでに保存されているかどうかを確認します。いいえの場合 - プロセッサでスキップします
- レコードが変更されていない場合 (または、更新が不可能な場合は既に保存されている場合) - プロセッサでスキップします
- else - db に保存
そして、ループとディサイダーを宣言します。
<batch:step id="processParentAndChilds" next="loop">
<batch:tasklet>
<batch:chunk reader="processParentAndChildsReader"
commit-interval="1000">
<batch:processor>
<bean class="processParentAndChildsProcessor"/>
</batch:processor>
<batch:writer>
<bean class="processParentAndChildsWriter"/>
</batch:writer>
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:decision decider="processParentAndChildsRetryDecider" id="loop">
<batch:next on="NEXT_LEVEL" to="processprocessParentAndChilds"/>
<batch:next on="COMPLETED" to="goToNextSteps"/>
</batch:decision>
public class ProcessParentAndChildsRetryDecider implements JobExecutionDecider{
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
// if no on record written - no sense to try again
if (stepExecution.getWriteCount() > 0) {
return new FlowExecutionStatus("NEXT_LEVEL");
} else {
return FlowExecutionStatus.COMPLETED;
}
}
}