本文整理了Java中org.springframework.batch.item.ExecutionContext
类的一些代码示例,展示了ExecutionContext
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext
类的具体详情如下:
包路径:org.springframework.batch.item.ExecutionContext
类名称:ExecutionContext
[英]Object representing a context for an ItemStream. It is a thin wrapper for a map that allows optionally for type safety on reads. It also allows for dirty checking by setting a 'dirty' flag whenever any put is called. Note that putting null
value is equivalent to removing the entry for the given key.
[中]对象,该对象表示ItemStream的上下文。它是一个映射的薄包装器,允许在读取时选择性地进行类型安全。它还允许通过在调用任何put时设置“dirty”标志进行脏检查。请注意,放入null
值相当于删除给定键的条目。
代码示例来源:origin: spring-projects/spring-batch
@Override
public void beforeJob(JobExecution jobExecution) {
ExecutionContext jobContext = jobExecution.getExecutionContext();
for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) {
jobContext.put(entry.getKey(), entry.getValue());
}
}
} });
代码示例来源:origin: spring-projects/spring-batch
private void copy(final StepExecution source, final StepExecution target) {
target.setVersion(source.getVersion());
target.setWriteCount(source.getWriteCount());
target.setFilterCount(source.getFilterCount());
target.setCommitCount(source.getCommitCount());
target.setExecutionContext(new ExecutionContext(source.getExecutionContext()));
}
代码示例来源:origin: spring-projects/spring-batch
@BeforeStep
public void createOutputNameFromInput(StepExecution stepExecution) {
ExecutionContext executionContext = stepExecution.getExecutionContext();
String inputName = stepExecution.getStepName().replace(":", "-");
if (executionContext.containsKey(inputKeyName)) {
inputName = executionContext.getString(inputKeyName);
}
if (!executionContext.containsKey(outputKeyName)) {
executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName)
+ ".csv");
}
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public void open(ExecutionContext executionContext) {
if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) {
this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY);
}
else {
//
// Fresh run. Disregard old state.
//
this.totalPrice = BigDecimal.ZERO;
}
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Typesafe Getter for the String represented by the provided key with
* default value to return if key is not represented.
*
* @param key The key to get a value for
* @param defaultString Default to return if key is not represented
* @return The <code>String</code> value if key is represented, specified
* default otherwise
*/
public String getString(String key, String defaultString) {
if (!containsKey(key)) {
return defaultString;
}
return getString(key);
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Typesafe Getter for the Long represented by the provided key with default
* value to return if key is not represented.
*
* @param key The key to get a value for
* @param defaultLong Default to return if key is not represented
* @return The <code>long</code> value if key is represented, specified
* default otherwise
*/
public long getLong(String key, long defaultLong) {
if (!containsKey(key)) {
return defaultLong;
}
return getLong(key);
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: keys = {key, key2}. Only {key} exists in the ExecutionContext.
*
* EXPECTED: key is promoted. key2 is not.
*/
@Test
public void promoteEntriesKeyNotFound() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
listener.setKeys(new String[] { key, key2 });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
private void start(String foo) {
StepSynchronizationManager.close();
stepExecution = new StepExecution("foo", new JobExecution(11L), 123L);
ExecutionContext executionContext = new ExecutionContext();
executionContext.put("foo", foo);
executionContext.put("parent", bar);
stepExecution.setExecutionContext(executionContext);
StepSynchronizationManager.register(stepExecution);
beanCount = beanFactory.getBeanDefinitionCount();
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public void execute(StepExecution stepExecution) throws JobInterruptedException {
if (!stepExecution.getJobExecution().getExecutionContext().containsKey("STOPPED")) {
stepExecution.getJobExecution().getExecutionContext().put("STOPPED", true);
stepExecution.setStatus(BatchStatus.STOPPED);
jobRepository.update(stepExecution);
}
else {
fail("The Job should have stopped by now");
}
}
}), "end0"));
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSaveUpdate() throws Exception {
StepExecution stepExecution = new StepExecution("step", new JobExecution(11L));
stepExecution.setId(123L);
stepExecution.getExecutionContext().put("foo", "bar");
dao.saveExecutionContext(stepExecution);
ExecutionContext executionContext = dao.getExecutionContext(stepExecution);
assertEquals("bar", executionContext.get("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSimpleProperty() throws Exception {
StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 123L);
ExecutionContext executionContext = stepExecution.getExecutionContext();
executionContext.put("foo", "bar");
StepSynchronizationManager.register(stepExecution);
assertEquals("bar", simple.getName());
}
代码示例来源:origin: spring-projects/spring-batch
/**
* @return a map containing the items from the job {@link ExecutionContext}
*/
public Map<String, Object> getJobExecutionContext() {
Map<String, Object> result = new HashMap<>();
for (Entry<String, Object> entry : stepExecution.getJobExecution().getExecutionContext().entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
return Collections.unmodifiableMap(result);
}
代码示例来源:origin: spring-projects/spring-batch
@Before
public void start() {
JobSynchronizationManager.close();
jobExecution = new JobExecution(123L);
ExecutionContext executionContext = new ExecutionContext();
executionContext.put("foo", "bar");
jobExecution.setExecutionContext(executionContext);
JobSynchronizationManager.register(jobExecution);
beanCount = beanFactory.getBeanDefinitionCount();
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public void beforeStep(StepExecution stepExecution) {
this.jobName = stepExecution.getJobExecution().getJobInstance().getJobName().trim();
this.stepName = (String) stepExecution.getJobExecution().getExecutionContext().get("stepName");
this.stepExecution = stepExecution;
stepExecution.getJobExecution().getExecutionContext().remove("stepName");
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testNormalUsage() {
context.putString("1", "testString1");
context.putString("2", "testString2");
context.putLong("3", 3);
context.putDouble("4", 4.4);
context.putInt("5", 5);
assertEquals("testString1", context.getString("1"));
assertEquals("testString2", context.getString("2"));
assertEquals("defaultString", context.getString("55", "defaultString"));
assertEquals(4.4, context.getDouble("4"), 0);
assertEquals(5.5, context.getDouble("55", 5.5), 0);
assertEquals(3, context.getLong("3"));
assertEquals(5, context.getLong("55", 5));
assertEquals(5, context.getInt("5"));
assertEquals(6, context.getInt("55", 6));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testExecutionContext() throws Exception {
assertNotNull(execution.getExecutionContext());
ExecutionContext context = new ExecutionContext();
context.putString("foo", "bar");
execution.setExecutionContext(context);
assertEquals("bar", execution.getExecutionContext().getString("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDirectlyInjectedItemStream() throws Exception {
step.setStreams(new ItemStream[] { new ItemStreamSupport() {
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
executionContext.putString("foo", "bar");
}
} });
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
step.execute(stepExecution);
assertEquals("bar", stepExecution.getExecutionContext().getString("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
@Override
protected State nextState(String stateName, FlowExecutionStatus status, StepExecution stepExecution) throws FlowExecutionException {
State nextState = findState(stateName, status, stepExecution);
if(stepExecution != null) {
ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext();
if(executionContext.containsKey("batch.stoppedStep")) {
String stepName = executionContext.getString("batch.stoppedStep");
if(stateName.endsWith(stepName)) {
if(nextState != null && executionContext.containsKey("batch.restartStep") && StringUtils.hasText(executionContext.getString("batch.restartStep"))) {
nextState = findState(stateName, new FlowExecutionStatus(status.getName() + ".RESTART"), stepExecution);
}
}
}
}
return nextState;
}
代码示例来源:origin: spring-projects/spring-batch
private Map<String, ExecutionContext> getContexts(StepExecution stepExecution, int gridSize) {
ExecutionContext context = stepExecution.getExecutionContext();
String key = SimpleStepExecutionSplitter.class.getSimpleName() + ".GRID_SIZE";
int splitSize = (int) context.getLong(key, gridSize);
context.putLong(key, splitSize);
if (context.isDirty()) {
result.put(name, new ExecutionContext());
代码示例来源:origin: spring-projects/spring-batch
protected boolean isFlowContinued(State state, FlowExecutionStatus status, StepExecution stepExecution) {
boolean continued = true;
continued = state != null && status!=FlowExecutionStatus.STOPPED;
if(stepExecution != null) {
Boolean reRun = (Boolean) stepExecution.getExecutionContext().get("batch.restart");
Boolean executed = (Boolean) stepExecution.getExecutionContext().get("batch.executed");
if((executed == null || !executed) && reRun != null && reRun && status == FlowExecutionStatus.STOPPED && !state.getName().endsWith(stepExecution.getStepName()) ) {
continued = true;
}
}
return continued;
}
内容来源于网络,如有侵权,请联系作者删除!