/** * Convenient accessor for current job identifier. * * @return the job identifier of the enclosing {@link JobInstance} * associated with the current {@link StepExecution} */ public Long getJobId() { Assert.state(stepExecution.getJobExecution() != null, "StepExecution does not have a JobExecution"); Assert.state(stepExecution.getJobExecution().getJobInstance() != null, "StepExecution does not have a JobInstance"); return stepExecution.getJobExecution().getJobInstance().getId(); }
/** * Convenient accessor for current job name identifier. * * @return the job name identifier of the enclosing {@link JobInstance} * associated with the current {@link StepExecution} */ public String getJobName() { Assert.state(stepExecution.getJobExecution() != null, "StepExecution does not have a JobExecution"); Assert.state(stepExecution.getJobExecution().getJobInstance() != null, "StepExecution does not have a JobInstance"); return stepExecution.getJobExecution().getJobInstance().getJobName(); }
/** * @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 setValues(PreparedStatement ps, int i) throws SQLException { Assert.state(itemIterator.nextIndex() == i, "Item ordering must be preserved in batch sql update"); ps.setLong(1, incrementer.nextLongValue()); ps.setLong(2, stepExecution.getJobExecution().getJobId()); ps.setBytes(3, SerializationUtils.serialize(itemIterator.next())); ps.setString(4, NEW); } });
@Override public void saveExecutionContexts(Collection<StepExecution> stepExecutions) { Assert.notNull(stepExecutions,"Attempt to save a null collection of step executions"); for (StepExecution stepExecution: stepExecutions) { saveExecutionContext(stepExecution); saveExecutionContext(stepExecution.getJobExecution()); } }
private List<Long> retrieveKeys() { synchronized (lock) { return jdbcTemplate.query( "SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID", new RowMapper<Long>() { @Override public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getLong(1); } }, stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW); } }
@Override public Set<StepExecution> split(StepExecution stepExecution, int gridSize) throws JobExecutionException { HashSet<StepExecution> result = new HashSet<>(); for (int i = gridSize; i-- > 0;) { result.add(stepExecution.getJobExecution().createStepExecution("foo" + i)); } return result; } };
@BeforeStep public void storeJobExecution(StepExecution stepExecution) { this.jobExecution = stepExecution.getJobExecution(); } }
@Override protected void setExitStatus(FlowExecutor executor, String code) { StepExecution stepExecution = executor.getStepExecution(); ExitStatus status = new ExitStatus(code); if(!ExitStatus.isNonDefaultExitStatus(status)) { stepExecution.getJobExecution().setExitStatus(status); } } }
@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"); }
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException { stepExecution.getJobExecution().stop(); super.execute(stepExecution); }
@Test public void testGetJobExecution() throws Exception { assertNotNull(execution.getJobExecution()); }
@Override public void aggregate(StepExecution result, Collection<StepExecution> executions) { result.getJobExecution().getExecutionContext().put("foo", "bar"); }
/** * @return */ private int getSkipCount() { if (stepExecution == null || stepName == null) { return 0; } for (StepExecution execution : stepExecution.getJobExecution().getStepExecutions()) { if (execution.getStepName().equals(stepName)) { return execution.getSkipCount(); } } return 0; }
@Test public void testGetStepExecution() throws Exception { when(jobExecutionDao.getJobExecution(jobExecution.getId())).thenReturn(jobExecution); when(jobInstanceDao.getJobInstance(jobExecution)).thenReturn(jobInstance); StepExecution stepExecution = jobExecution.createStepExecution("foo"); when(stepExecutionDao.getStepExecution(jobExecution, 123L)) .thenReturn(stepExecution); when(ecDao.getExecutionContext(stepExecution)).thenReturn(null); stepExecution = jobExplorer.getStepExecution(jobExecution.getId(), 123L); assertEquals(jobInstance, stepExecution.getJobExecution().getJobInstance()); verify(jobInstanceDao).getJobInstance(jobExecution); }
@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")); }
public boolean doWork(ChunkContext chunkContext) { chunkContext. getStepContext(). getStepExecution(). getJobExecution(). getExecutionContext().put("done", "yes"); return true; }
@Test public void testJobParameters() throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters(); JobInstance instance = stepExecution.getJobExecution().getJobInstance(); stepExecution = new StepExecution("step", new JobExecution(instance, jobParameters)); context = new StepContext(stepExecution); assertEquals("bar", context.getJobParameters().get("foo")); }