本文整理了Java中org.springframework.batch.item.ExecutionContext.get()
方法的一些代码示例,展示了ExecutionContext.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.get()
方法的具体详情如下:
包路径:org.springframework.batch.item.ExecutionContext
类名称:ExecutionContext
方法名:get
[英]Getter for the value represented by the provided key.
[中]由提供的键表示的值的Getter。
代码示例来源:origin: spring-projects/spring-batch
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getValueFromJob(JobExecution jobExecution, String key) {
return (T) jobExecution.getExecutionContext().get(key);
}
代码示例来源: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
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getValueFromStep(StepExecution stepExecution, String key) {
return (T) stepExecution.getExecutionContext().get(key);
}
代码示例来源: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;
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public Serializable getPersistentUserData() {
return (Serializable) stepExecution.getExecutionContext().get(executionContextUserSupport.getKey(PERSISTENT_USER_DATA_KEY));
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public Serializable getPersistentUserData() {
return (Serializable) stepExecution.getExecutionContext().get(executionContextUserSupport.getKey(PERSISTENT_USER_DATA_KEY));
}
代码示例来源:origin: spring-projects/spring-batch
@Override
@SuppressWarnings("unchecked")
public void open(ExecutionContext executionContext) {
if (isSaveState()) {
startAfterValues = (Map<String, Object>) executionContext.get(getExecutionContextKey(START_AFTER_VALUE));
if(startAfterValues == null) {
startAfterValues = new LinkedHashMap<>();
}
}
super.open(executionContext);
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public void open(ExecutionContext executionContext)
throws ItemStreamException {
try {
String executionContextKey = getExecutionContextKey(checkpointKey);
Serializable checkpoint = (Serializable) executionContext.get(executionContextKey);
doOpen(checkpoint);
} catch (Exception e) {
throw new ItemStreamException(e);
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test(expected=ItemStreamException.class)
public void testOpenException() throws Exception {
when(executionContext.get("jsrWriter.writer.checkpoint")).thenReturn("checkpoint");
doThrow(new Exception("expected")).when(delegate).open("checkpoint");
adapter.open(executionContext);
}
代码示例来源:origin: spring-projects/spring-batch
@Test(expected=ItemStreamException.class)
public void testOpenException() throws Exception {
when(executionContext.get("jsrReader.reader.checkpoint")).thenReturn("checkpoint");
doThrow(new Exception("expected")).when(delegate).open("checkpoint");
adapter.open(executionContext);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testOpen() throws Exception {
when(executionContext.get("jsrReader.reader.checkpoint")).thenReturn("checkpoint");
adapter.open(executionContext);
verify(delegate).open("checkpoint");
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testOpen() throws Exception {
when(executionContext.get("jsrWriter.writer.checkpoint")).thenReturn("checkpoint");
adapter.open(executionContext);
verify(delegate).open("checkpoint");
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testGetNull() {
assertNull(context.get("does not exist"));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testBeforeStep() {
listener.beforeStep(stepExecution);
assertEquals("bar", stepExecution.getExecutionContext().get("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
private void validateLaunchWithoutSkips(JobExecution jobExecution) {
// Step1: 5 input records => 5 written to output
assertEquals(5, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
// Step2: 5 input records => 5 written to output
assertEquals(5, jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE where VERSION=?", Integer.class, 1).intValue());
// Neither step contained skips
assertEquals(0, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));
assertEquals(new BigDecimal("270.75"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Putting null value is equivalent to removing the entry for the given key.
*/
@Test
public void testPutNull() {
context.put("1", null);
assertNull(context.get("1"));
assertFalse(context.containsKey("1"));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDefaultHandlerStep() throws Exception {
assertNotNull(job1);
JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParameters());
job1.execute(jobExecution);
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Collections.sort(savedStepNames);
assertEquals("[step1:partition0, step1:partition1]", savedStepNames.toString());
List<String> stepNames = getStepNames(jobExecution);
assertEquals(3, stepNames.size());
assertEquals("[s1, step1:partition0, step1:partition1]", stepNames.toString());
assertEquals("bar", jobExecution.getExecutionContext().get("foo"));
}
代码示例来源: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 testPersistentUserData() {
String data = "saved data";
stepContext.setPersistentUserData(data);
assertEquals(data, stepContext.getPersistentUserData());
assertEquals(data, executionContext.get(executionContextUserSupport.getKey("batch_jsr_persistentUserData")));
}
代码示例来源: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"));
}
内容来源于网络,如有侵权,请联系作者删除!