use of org.springframework.batch.item.ExecutionContext in project RecordManager2 by moravianlibrary.
the class DateIntervalPartitioner method partition.
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
Map<String, ExecutionContext> partitions = new LinkedHashMap<String, ExecutionContext>();
int index = 1;
DateTime nextFrom = from;
DateTime nextTo = to;
while (nextFrom.isBefore(to)) {
nextTo = nextFrom.plus(period);
if (nextTo.isAfter(to)) {
nextTo = to;
}
ExecutionContext partition = new ExecutionContext();
partition.put(fromKey, nextFrom.toDate());
partition.put(toKey, nextTo.toDate());
partitions.put(Integer.toString(index), partition);
nextFrom = nextTo;
index++;
}
return partitions;
}
use of org.springframework.batch.item.ExecutionContext in project RecordManager2 by moravianlibrary.
the class SqlCommandTasklet method execute.
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
ExecutionContext ctx = chunkContext.getStepContext().getStepExecution().getExecutionContext();
int index = 0;
if (ctx.containsKey("index")) {
index = ctx.getInt("index");
}
if (index >= commands.length) {
return RepeatStatus.FINISHED;
}
String sql = commands[index];
logger.debug("Before execute sql: {}", sql);
jdbcTemplate.execute(sql);
logger.debug("After execute sql: {}", sql);
index++;
ctx.putInt("index", index);
return (index >= commands.length) ? RepeatStatus.FINISHED : RepeatStatus.CONTINUABLE;
}
use of org.springframework.batch.item.ExecutionContext in project RecordManager2 by moravianlibrary.
the class UniqueRecordsDedupTasklet method execute.
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
ExecutionContext ctx = chunkContext.getStepContext().getStepExecution().getExecutionContext();
long harvestedRecordId = ctx.getLong("harvestedRecordId", 0L);
Long nextHarvestedRecordId = DataAccessUtils.singleResult(jdbcTemplate.query(command, new Object[] { harvestedRecordId }, new LongValueRowMapper()));
if (nextHarvestedRecordId != null) {
ctx.putLong("harvestedRecordId", nextHarvestedRecordId);
}
logger.debug("nextHarvestedRecordId: {}", nextHarvestedRecordId);
return (nextHarvestedRecordId == null) ? RepeatStatus.FINISHED : RepeatStatus.CONTINUABLE;
}
use of org.springframework.batch.item.ExecutionContext in project tutorials by eugenp.
the class CustomMultiResourcePartitioner method partition.
/**
* Assign the filename of each of the injected resources to an
* {@link ExecutionContext}.
*
* @see Partitioner#partition(int)
*/
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
int i = 0, k = 1;
for (Resource resource : resources) {
ExecutionContext context = new ExecutionContext();
Assert.state(resource.exists(), "Resource does not exist: " + resource);
context.putString(keyName, resource.getFilename());
context.putString("opFileName", "output" + k++ + ".xml");
map.put(PARTITION_KEY + i, context);
i++;
}
return map;
}
use of org.springframework.batch.item.ExecutionContext in project tutorials by eugenp.
the class LinesProcessor method beforeStep.
@Override
public void beforeStep(StepExecution stepExecution) {
ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext();
this.lines = (List<Line>) executionContext.get("lines");
logger.debug("Lines Processor initialized.");
}
Aggregations