/** * @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 : jobExecution.getExecutionContext().entrySet()) { result.put(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(result); }
/** * @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); }
@Override public void beforeJob(JobExecution jobExecution) { ExecutionContext jobContext = jobExecution.getExecutionContext(); for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) { jobContext.put(entry.getKey(), entry.getValue()); } } } });
@Override public void saveExecutionContext(JobExecution jobExecution) { Long executionId = jobExecution.getId(); ExecutionContext executionContext = jobExecution.getExecutionContext(); Assert.notNull(executionId, "ExecutionId must not be null."); Assert.notNull(executionContext, "The ExecutionContext must not be null."); String serializedContext = serializeContext(executionContext); persistSerializedContext(executionId, serializedContext, INSERT_JOB_EXECUTION_CONTEXT); }
@Override public void updateExecutionContext(final JobExecution jobExecution) { Long executionId = jobExecution.getId(); ExecutionContext executionContext = jobExecution.getExecutionContext(); Assert.notNull(executionId, "ExecutionId must not be null."); Assert.notNull(executionContext, "The ExecutionContext must not be null."); String serializedContext = serializeContext(executionContext); persistSerializedContext(executionId, serializedContext, UPDATE_JOB_EXECUTION_CONTEXT); }
@Override public void updateExecutionContext(JobExecution jobExecution) { ExecutionContext executionContext = jobExecution.getExecutionContext(); if (executionContext != null) { contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext)); } }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { this.jdbcTemplate.update("insert into TESTS(ID, NAME) values (?, 'SampleTasklet" + id + "')", id); if (jobExecution != null) { ExecutionContext jobContext = jobExecution.getExecutionContext(); if (jobContext.containsKey("key1")) { jobContextEntryFound = true; } } return RepeatStatus.FINISHED; }
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { FlowExecutionStatus result = super.handle(executor); executor.getJobExecution().getExecutionContext().put("batch.lastSteps", Collections.singletonList(getStep().getName())); return result; } }
public JobExecution getJobExecution() { JobExecution execution = MetaDataInstanceFactory.createJobExecution(); execution.getExecutionContext().putString("input.data", "foo,bar"); return execution; }
@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"); }
@Test public void testJobExecutionContext() throws Exception { ExecutionContext executionContext = jobExecution.getExecutionContext(); executionContext.put("foo", "bar"); assertEquals("bar", context.getJobExecutionContext().get("foo")); }
public JobExecution getJobExecution() { // Assert that dependencies are already injected... assertNotNull(reader); // Then create the execution for the job scope... JobExecution execution = MetaDataInstanceFactory.createJobExecution(); execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); return execution; }
@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"));
@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"));
@Test public void testJobExecutionContext() throws Exception { ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext(); executionContext.put("foo", "bar"); assertEquals("bar", context.getJobExecutionContext().get("foo")); }
@Override public void execute(JobExecution stepExecution) { context = JobSynchronizationManager.getContext(); setContextFromCollaborator(); stepExecution.getExecutionContext().put("foo", "changed but it shouldn't affect the collaborator"); setContextFromCollaborator(); }
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)); }
public JobExecution getJobExecution() { JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("job", 11L, 123L, new JobParametersBuilder().addString("foo", "spam").toJobParameters()); jobExecution.getExecutionContext().putString("foo", "bar"); return jobExecution; } }
@Test public void testSimpleProperty() throws Exception { assertEquals("bar", simple.getName()); // Once the job context is set up it should be baked into the proxies // so changing it now should have no effect jobExecution.getExecutionContext().put("foo", "wrong!"); assertEquals("bar", simple.getName()); }
@Test public void testSimpleProperty() throws Exception { assertEquals("bar", simple.getName()); // Once the job context is set up it should be baked into the proxies // so changing it now should have no effect jobExecution.getExecutionContext().put("foo", "wrong!"); assertEquals("bar", simple.getName()); }