BATCH-1261: Update "Passing data to future steps" to include retrieval
This commit is contained in:
@@ -537,13 +537,14 @@
|
||||
during <classname>Step</classname> execution and if the
|
||||
<classname>Step</classname> fails, that data will be lost.</para>
|
||||
|
||||
<programlisting>public void MyItemWriter implements ItemWriter<Object> {
|
||||
<programlisting>public void SavingItemWriter implements ItemWriter<Object> {
|
||||
private StepExecution stepExecution;
|
||||
|
||||
public void write(List<? extends Object> items) throws Exception {
|
||||
// ...
|
||||
|
||||
this.stepExecution.getExecutionContext().put("someKey", someObject);
|
||||
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
|
||||
stepContext.put("someKey", someObject);
|
||||
}
|
||||
|
||||
@BeforeStep
|
||||
@@ -564,22 +565,41 @@
|
||||
listeners, it must be registered on the
|
||||
<classname>Step</classname>.</para>
|
||||
|
||||
<programlisting><step id="step1">
|
||||
<tasket>
|
||||
<chunk reader="reader" writer="writer" commit-interval="10"/>
|
||||
<listeners>
|
||||
<listener ref="promotionListener"/>
|
||||
</listeners>
|
||||
</tasklet>
|
||||
</step>
|
||||
<programlisting><job id="job1">
|
||||
<step id="step1">
|
||||
<tasket>
|
||||
<chunk reader="reader" writer="savingWriter" commit-interval="10"/>
|
||||
<listeners>
|
||||
<emphasis role="bold"><listener ref="promotionListener"/></emphasis>
|
||||
</listeners>
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
<step id="step2">
|
||||
...
|
||||
</step>
|
||||
<step id="step2">
|
||||
...
|
||||
</step>
|
||||
</job>
|
||||
|
||||
<beans:bean id="promotionListener"
|
||||
<emphasis role="bold"><beans:bean id="promotionListener"
|
||||
class="org.spr....ExecutionContextPromotionListener">
|
||||
<beans:property name="keys" value="someKey"/>
|
||||
</beans:bean></programlisting>
|
||||
</beans:bean></emphasis></programlisting>
|
||||
|
||||
<para>Finally, to the saved values must be retrieved from the
|
||||
<classname>Job</classname> <classname>ExeuctionContext</classname>:</para>
|
||||
|
||||
<programlisting>public void RetrievingItemWriter implements ItemWriter<Object> {
|
||||
private Object someObject;
|
||||
|
||||
public void write(List<? extends Object> items) throws Exception {
|
||||
// ...
|
||||
}
|
||||
|
||||
@BeforeStep
|
||||
public void saveStepExecution(StepExecution stepExecution) {
|
||||
ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
|
||||
this.someObject = jobContext.get("someKey");
|
||||
}
|
||||
}</programlisting>
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
Reference in New Issue
Block a user