Example usage for org.springframework.batch.item ExecutionContext putInt

List of usage examples for org.springframework.batch.item ExecutionContext putInt

Introduction

In this page you can find the example usage for org.springframework.batch.item ExecutionContext putInt.

Prototype

public void putInt(String key, int value) 

Source Link

Document

Adds an Integer value to the context.

Usage

From source file:org.geoserver.backuprestore.reader.CatalogMultiResourceItemReader.java

/**
 * Store the current resource index and position in the resource.
 *///from ww  w  . j a v  a2  s.c o m
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
    super.update(executionContext);
    if (saveState) {
        executionContext.putInt(getExecutionContextKey(RESOURCE_KEY), currentResource);
        delegate.update(executionContext);
    }
}

From source file:org.springframework.batch.core.step.item.ChunkMonitor.java

@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
    super.update(executionContext);
    if (streamsRegistered) {
        ChunkMonitorData data = getData();
        if (data.offset == 0) {
            // Only call the underlying update method if we are on a chunk
            // boundary
            stream.update(executionContext);
            executionContext.remove(getExecutionContextKey(OFFSET));
        } else {//ww  w .  j a v  a  2 s  . c  o  m
            executionContext.putInt(getExecutionContextKey(OFFSET), data.offset);
        }
    }
}

From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java

private void setUp() throws Exception {

    step = new TaskletStep("stepName");

    ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
    step.setTransactionManager(transactionManager);

    RepeatTemplate chunkTemplate = new RepeatTemplate();
    chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
    step.setTasklet(new TestingChunkOrientedTasklet<String>(new ListItemReader<String>(items), itemProcessor,
            itemWriter, chunkTemplate));

    jobRepository = new JobRepositorySupport();
    step.setJobRepository(jobRepository);

    TaskExecutorRepeatTemplate template = new TaskExecutorRepeatTemplate();
    template.setThrottleLimit(throttleLimit);
    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setConcurrencyLimit(concurrencyLimit);
    template.setTaskExecutor(taskExecutor);
    step.setStepOperations(template);/*w w  w  . j a  va  2 s  .  c o m*/

    step.registerStream(new ItemStreamSupport() {
        private int count = 0;

        @Override
        public void update(ExecutionContext executionContext) {
            super.update(executionContext);
            executionContext.putInt("counter", count++);
        }
    });

}

From source file:org.springframework.batch.item.database.JdbcPagingRestartIntegrationTests.java

@Test
@Ignore //FIXME/*from   w w w .j av  a2  s . c o m*/
public void testReaderOnRestart() throws Exception {

    ItemReader<Foo> reader = getItemReader();

    int total = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS");
    int count = (total / pageSize) * pageSize;
    int pagesToRead = Math.min(3, total / pageSize);
    if (count >= pagesToRead * pageSize) {
        count -= pagesToRead * pageSize;
    }

    ExecutionContext executionContext = new ExecutionContext();
    executionContext.putInt("JdbcPagingItemReader.read.count", count);
    // Assume the primary keys are in order

    List<Map<String, Object>> ids = jdbcTemplate.queryForList("SELECT ID,NAME FROM T_FOOS ORDER BY ID ASC");
    logger.debug("Ids: " + ids);
    int startAfterValue = (new Long(ids.get(count - 1).get("ID").toString())).intValue();
    logger.debug("Start after: " + startAfterValue);
    Map<String, Object> startAfterValues = new LinkedHashMap<String, Object>();
    startAfterValues.put("ID", startAfterValue);
    executionContext.put("JdbcPagingItemReader.start.after", startAfterValues);
    ((ItemStream) reader).open(executionContext);

    for (int i = count; i < total; i++) {
        Foo item = reader.read();
        logger.debug("Item: " + item);
        assertNotNull(item);
    }

    Foo item = reader.read();
    logger.debug("Item: " + item);
    assertNull(item);

}