Java Code Examples for org.springframework.batch.item.ExecutionContext#putInt()

The following examples show how to use org.springframework.batch.item.ExecutionContext#putInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeedMultiResourceItemReader.java    From seed with Apache License 2.0 5 votes vote down vote up
/**
 * Store the current resource index and position in the resource.
 */
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
    super.update(executionContext);
    if (saveState) {
        executionContext.putInt(getExecutionContextKey(RESOURCE_KEY), currentResource);
        delegate.update(executionContext);
    }
}
 
Example 2
Source File: ExecutionContextDeserializer.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionContext deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
		throws IOException, JsonProcessingException {
	ObjectCodec oc = jsonParser.getCodec();
	JsonNode node = oc.readTree(jsonParser);

	final ExecutionContext executionContext = new ExecutionContext();
	final boolean dirty = node.get("dirty").asBoolean();

	for (JsonNode valueNode : node.get("values")) {

		final JsonNode nodeValue = valueNode.fields().next().getValue();
		final String nodeKey = valueNode.fields().next().getKey();

		if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToInt()) {
			executionContext.putInt(nodeKey, nodeValue.asInt());
		}
		else if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToLong()) {
			executionContext.putLong(nodeKey, nodeValue.asLong());
		}
		else if (nodeValue.isFloatingPointNumber()) {
			executionContext.putDouble(nodeKey, nodeValue.asDouble());
		}
		else if (nodeValue.isBoolean()) {
			executionContext.putString(nodeKey, String.valueOf(nodeValue.asBoolean()));
		}
		else if (nodeValue.isTextual()) {
			executionContext.putString(nodeKey, nodeValue.asText());
		}
		else {
			executionContext.put(nodeKey, nodeValue.toString());
		}
	}

	if (!dirty && executionContext.isDirty()) {
		executionContext.clearDirtyFlag();
	}

	return executionContext;
}
 
Example 3
Source File: StepExecutionJacksonMixInTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private StepExecution getStepExecution() {
	JobExecution jobExecution = new JobExecution(1L, null, "hi");
	final StepExecution stepExecution = new StepExecution("step1", jobExecution);
	jobExecution.createStepExecution("step1");
	final ExecutionContext executionContext = stepExecution.getExecutionContext();

	executionContext.putInt("counter", 1234);
	executionContext.putDouble("myDouble", 1.123456d);
	executionContext.putLong("Josh", 4444444444L);
	executionContext.putString("awesomeString", "Yep");
	executionContext.put("hello", "world");
	executionContext.put("counter2", 9999);

	return stepExecution;
}
 
Example 4
Source File: ColumnRangePartitioner.java    From spring-batch-performance-tuning with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
	int min = jdbcTemplate.queryForObject("SELECT MIN(" + column + ") from " + table, Integer.class);
	int max = jdbcTemplate.queryForObject("SELECT MAX(" + column + ") from " + table, Integer.class);

	int targetSize = (max - min) / gridSize;

	Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();

	int number = 0;
	int start = min;
	int end = start + targetSize - 1;

	while (start <= max) {
		ExecutionContext value = new ExecutionContext();
		result.put("partition" + number, value);

		if (end >= max) {
			end = max;
		}

		value.putInt("minValue", start);
		value.putInt("maxValue", end);

		start += targetSize;
		end += targetSize;
		number++;
	}

	return result;
}