We are trying to implement a batch job using spring batch separation. This in “step 2” shows a sectioned step where I need some data from step 1 to process. I used StepExecutionContext, which will be promoted to the context job in step 1 to store this data.
I tried using the @BeforeStep annotation in the separator class to get the stepExecutionContext from which I can extract the data stored earlier and put it in the ExecutionContext of the separator. But the method with the annotation @BeforeStep does not start in the delimiter.
Is there any other way to achieve this.
Partitioner implementation
public class NtfnPartitioner implements Partitioner {
private int index = 0;
String prev_job_time = null;
String curr_job_time = null;
private StepExecution stepExecution ;
ExecutionContext executionContext ;
@Override
public Map<String, ExecutionContext> partition(int gridSize)
{
System.out.println("Entered Partitioner");
List<Integer> referencIds = new ArrayList<Integer>();
for (int i = 0; i < gridSize;i++) {
referencIds.add(index++);
}
Map<String, ExecutionContext> results = new LinkedHashMap<String,ExecutionContext>();
for (int referencId : referencIds) {
ExecutionContext context = new ExecutionContext();
context.put("referenceId", referencId);
context.put(NtfnConstants.PREVIOUS_JOB_TIME, prev_job_time);
context.put(NtfnConstants.JOB_START_TIME, curr_job_time);
results.put("partition." + referencId, context);
}
return results;
}
@BeforeStep
public void beforeStep(StepExecution stepExecution) {
System.out.println("Entered Before step in partion");
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
System.out.println("ExecutionContext"+jobContext);
String prev_job_time = (String) jobContext.get(NtfnConstants.PREVIOUS_JOB_TIME);
String curr_job_time = (String) jobContext.get(NtfnConstants.JOB_START_TIME);
}