-1

フラットファイルを読み取るためにSpringBatchを使用しています。ファイルには関連するレコードがあります。つまり、親レコードと、すべてのレコードを読み取り、Webサービスを呼び出して保存したい子レコードがいくつでも存在する可能性があります。また、関係をキャプチャして保存したかったのです。1つの課題は、子レコードをファイルのどこにでも配置できることです。そして、子供も多くの子供たちの記録を持つことができます。私は春のバッチでこの問題の解決策を見つけることができません。あなたの提案を提供してください

更新:データベースをデータの一時ストレージとして使用するオプションがありません。

4

1 に答える 1

0

ファイルを複数回処理することで、このような問題を解決しました。

すべてのパスで、次のような 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;
    }
}

}

于 2013-03-07T10:05:21.697 に答える