Search in sources :

Example 1 with ExecutionContext

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;
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) DateTime(org.joda.time.DateTime) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ExecutionContext

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;
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext)

Example 3 with ExecutionContext

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;
}
Also used : LongValueRowMapper(cz.mzk.recordmanager.server.jdbc.LongValueRowMapper) ExecutionContext(org.springframework.batch.item.ExecutionContext)

Example 4 with ExecutionContext

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;
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) HashMap(java.util.HashMap) Resource(org.springframework.core.io.Resource)

Example 5 with ExecutionContext

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.");
}
Also used : Line(org.baeldung.taskletsvschunks.model.Line) ExecutionContext(org.springframework.batch.item.ExecutionContext)

Aggregations

ExecutionContext (org.springframework.batch.item.ExecutionContext)17 Test (org.junit.Test)6 StepExecution (org.springframework.batch.core.StepExecution)5 HashMap (java.util.HashMap)4 Rule (com.navercorp.pinpoint.web.alarm.vo.Rule)2 AlarmServiceImpl (com.navercorp.pinpoint.web.service.AlarmServiceImpl)2 LinkedList (java.util.LinkedList)2 Line (org.baeldung.taskletsvschunks.model.Line)2 Resource (org.springframework.core.io.Resource)2 DefaultDivider (com.navercorp.pinpoint.batch.common.DefaultDivider)1 AlarmDao (com.navercorp.pinpoint.web.dao.AlarmDao)1 WebhookSendInfoDao (com.navercorp.pinpoint.web.dao.WebhookSendInfoDao)1 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)1 LongValueRowMapper (cz.mzk.recordmanager.server.jdbc.LongValueRowMapper)1 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 CloserUtil (htsjdk.samtools.util.CloserUtil)1 IOUtil (htsjdk.samtools.util.IOUtil)1 StringUtil (htsjdk.samtools.util.StringUtil)1 SAMSequenceDictionaryExtractor (htsjdk.variant.utils.SAMSequenceDictionaryExtractor)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1