Package org.springframework.batch.item

Examples of org.springframework.batch.item.ExecutionContext


    return copy(contexts.get(ContextKey.step(stepExecution.getId())));
  }

  @Override
  public void updateExecutionContext(StepExecution stepExecution) {
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    if (executionContext != null) {
      contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext));
    }
  }
View Full Code Here


    return copy(contexts.get(ContextKey.job(jobExecution.getId())));
  }

  @Override
  public void updateExecutionContext(JobExecution jobExecution) {
    ExecutionContext executionContext = jobExecution.getExecutionContext();
    if (executionContext != null) {
      contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext));
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testOpenWithNoState() throws Exception {
    writer.open(new ExecutionContext());
  }
View Full Code Here

    writer.open(new ExecutionContext());
  }

  @Test
  public void testUpdateAndOpenWithState() throws Exception {
    ExecutionContext executionContext = new ExecutionContext();
    writer.update(executionContext);
    writer.open(executionContext);
    assertEquals(0, executionContext.getInt(ChunkMessageChannelItemWriter.EXPECTED));
    assertEquals(0, executionContext.getInt(ChunkMessageChannelItemWriter.ACTUAL));
  }
View Full Code Here

    itemReader.setPreparedStatementSetter(pss);
  }
 
  @Transactional @Test
  public void testRead() throws Exception{
    itemReader.open(new ExecutionContext());
    Foo foo = itemReader.read();
    assertEquals(2, foo.getId());
    foo = itemReader.read();
    assertEquals(3, foo.getId());
    assertNull(itemReader.read());
View Full Code Here

  }

  private Map<String, ExecutionContext> getContexts(StepExecution stepExecution, int gridSize) {

    ExecutionContext context = stepExecution.getExecutionContext();
    String key = SimpleStepExecutionSplitter.class.getSimpleName() + ".GRID_SIZE";

    // If this is a restart we must retain the same grid size, ignoring the
    // one passed in...
    int splitSize = (int) context.getLong(key, gridSize);
    context.putLong(key, splitSize);

    Map<String, ExecutionContext> result;
    if (context.isDirty()) {
      // The context changed so we didn't already know the partitions
      jobRepository.updateExecutionContext(stepExecution);
      result = partitioner.partition(splitSize);
    }
    else {
      if (partitioner instanceof PartitionNameProvider) {
        result = new HashMap<String, ExecutionContext>();
        Collection<String> names = ((PartitionNameProvider) partitioner).getPartitionNames(splitSize);
        for (String name : names) {
          /*
           * We need to return the same keys as the original (failed)
           * execution, but the execution contexts will be discarded
           * so they can be empty.
           */
          result.put(name, new ExecutionContext());
        }
      }
      else {
        // If no names are provided, grab the partition again.
        result = partitioner.partition(splitSize);
View Full Code Here

  @Override
  public Map<String, ExecutionContext> partition(int gridSize) {
    Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
    for (int i = 0; i < gridSize; i++) {
      map.put(PARTITION_KEY + i, new ExecutionContext());
    }
    return map;
  }
View Full Code Here

    assertEquals("step", stepExecution.getExecutionContext().get("type"));

    tested.saveExecutionContext(jobExecution);
    tested.saveExecutionContext(stepExecution);
 
    ExecutionContext jobCtx = tested.getExecutionContext(jobExecution);
    ExecutionContext stepCtx = tested.getExecutionContext(stepExecution);

    assertEquals("job", jobCtx.get("type"));
    assertEquals("step", stepCtx.get("type"));
  }
View Full Code Here

    assertTrue(stepExecution.getExecutionContext().isEmpty());
   
    tested.updateExecutionContext(stepExecution);
    stepExecution.getExecutionContext().put("key","value");
   
    ExecutionContext retrieved = tested.getExecutionContext(stepExecution);
    assertTrue(retrieved.isEmpty());
   
    tested.updateExecutionContext(jobExecution);
    jobExecution.getExecutionContext().put("key", "value");
    retrieved = tested.getExecutionContext(jobExecution);
    assertTrue(retrieved.isEmpty());
  }
View Full Code Here

  @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);
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.springframework.batch.item.ExecutionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.