/** * @return the current step execution if there is one */ private StepExecution getStepExecution() { StepContext context = StepSynchronizationManager.getContext(); if (context==null) { return null; } StepExecution stepExecution = context.getStepExecution(); return stepExecution; }
public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore) { this.chunkContext = chunkContext; this.stepExecution = chunkContext.getStepContext().getStepExecution(); this.semaphore = semaphore; }
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { StepContext context = StepSynchronizationManager.getContext(); if (context == null) { return message; } return MessageBuilder.fromMessage(message).setHeader(STEP_EXECUTION, context.getStepExecution()).build(); }
@Override public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext chunkContext) throws Exception { StepExecution stepExecution = chunkContext.getStepContext().getStepExecution(); // Before starting a new transaction, check for // interruption. interruptionPolicy.checkInterrupted(stepExecution); RepeatStatus result; try { result = new TransactionTemplate(transactionManager, transactionAttribute) .execute(new ChunkTransactionCallback(chunkContext, semaphore)); } catch (UncheckedTransactionException e) { // Allow checked exceptions to be thrown inside callback throw (Exception) e.getCause(); } chunkListener.afterChunk(chunkContext); // Check for interruption after transaction as well, so that // the interrupted exception is correctly propagated up to // caller interruptionPolicy.checkInterrupted(stepExecution); return result == null ? RepeatStatus.FINISHED : result; }
private javax.batch.runtime.context.StepContext getCurrent() { org.springframework.batch.core.StepExecution curStepExecution = null; if(StepSynchronizationManager.getContext() != null) { curStepExecution = StepSynchronizationManager.getContext().getStepExecution(); } if(curStepExecution == null) { throw new FactoryBeanNotInitializedException("A StepExecution is required"); } StepContext context = contextHolder.get(); // If the current context applies to the current step, use it if(context != null && context.getStepExecutionId() == curStepExecution.getId()) { return context; } Properties stepProperties = batchPropertyContext.getStepProperties(curStepExecution.getStepName()); if(stepProperties != null) { context = new JsrStepContext(curStepExecution, stepProperties); } else { context = new JsrStepContext(curStepExecution, new Properties()); } contextHolder.set(context); return context; }
curJobExecution = StepSynchronizationManager.getContext().getStepExecution().getJobExecution();
public String process(String item) throws Exception { StepContext context = StepSynchronizationManager.getContext(); assertTrue(context != null && context.getStepExecution() != null); return item + item; }; };
@Override public RepeatStatus doInChunkContext(RepeatContext context, ChunkContext chunkContext) throws Exception { assertEquals(Long.valueOf(123), chunkContext.getStepContext().getStepExecution().getId()); return RepeatStatus.FINISHED; } };
jobExplorer.getJobExecution(chunkContext.getStepContext().getStepExecution().getJobExecutionId());
@Test public void testGetStepExecution() { context = new StepContext(stepExecution); assertNotNull(context.getStepExecution()); }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext attributes) throws Exception { attributes.getStepContext().getStepExecution().getExecutionContext().putString("foo", "bar"); return RepeatStatus.FINISHED; }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext attributes) throws Exception { attributes.getStepContext().getStepExecution().getExecutionContext().putString("foo", "bar"); return RepeatStatus.FINISHED; }
public boolean doWork(ChunkContext chunkContext) { chunkContext. getStepContext(). getStepExecution(). getJobExecution(). getExecutionContext().put("done", "yes"); return true; }
@Test public void testGetContextWithBatchProperties() { StepContext context = StepSynchronizationManager.getContext(); assertNull(context); StepSynchronizationManager.register(stepExecution, propertyContext); context = StepSynchronizationManager.getContext(); assertNotNull(context); assertEquals(stepExecution, context.getStepExecution()); }
public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore) { this.chunkContext = chunkContext; this.stepExecution = chunkContext.getStepContext().getStepExecution(); this.semaphore = semaphore; }
private StepExecution getStepExecution() { if (StepSynchronizationManager.getContext() != null) { return StepSynchronizationManager.getContext().getStepExecution(); } return null; }
private StepExecution getStepExecution() { if (StepSynchronizationManager.getContext() != null) { return StepSynchronizationManager.getContext().getStepExecution(); } return null; }
protected void bindContext(ChunkContext context) { MDC.put(MDCBatchPropertyKeys.JOB_FLOW_ID, (String) context.getStepContext().getJobParameters().get(JobParameterConstants.KEY_FLOW_ID)); MDC.put(MDCBatchPropertyKeys.JOB_FLOW_NAME, (String) context.getStepContext().getJobParameters().get(JobParameterConstants.KEY_FLOW_NAME)); MDC.put(MDCBatchPropertyKeys.JOB_EXECUTION_ID, String.valueOf(context.getStepContext().getStepExecution().getJobExecutionId())); MDC.put(MDCBatchPropertyKeys.JOB_EXECUTION_DISCRIMINATOR, buildExecutionDiscriminator(MDC.get(MDCBatchPropertyKeys.JOB_EXECUTION_ID), MDC.get(MDCBatchPropertyKeys.JOB_FLOW_NAME))); }
private String getStepIdentifier() { StepContext stepContext = StepSynchronizationManager.getContext(); StepExecution stepExecution = StepSynchronizationManager.getContext().getStepExecution(); return stepContext.getJobName() + "." + stepExecution.getStepName(); }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { JobExecution jobExecution = chunkContext.getStepContext().getStepExecution().getJobExecution(); jobExecution.getExecutionContext().put(RepositoryStoreConstants.BUILD_STRUCTURE_CURRENT_LEVEL, null); jobExecution.getExecutionContext().put("hierarchyLevelsMap", null); return RepeatStatus.FINISHED; }