Package org.springframework.batch.item

Examples of org.springframework.batch.item.ExecutionContext


    TransactionTemplate tt = new TransactionTemplate(tm);
    final JdbcCursorItemReader<String> reader = new JdbcCursorItemReader<String>();
    reader.setDataSource(new ExtendedConnectionDataSourceProxy(ds));
    reader.setUseSharedExtendedConnection(true);
    reader.setSql("select foo from bar");
    final ExecutionContext ec = new ExecutionContext();
    tt.execute(
        new TransactionCallback<Void>() {
                    @Override
          public Void doInTransaction(TransactionStatus status) {
            reader.open(ec);
View Full Code Here


    PlatformTransactionManager tm = new DataSourceTransactionManager(ds);
    TransactionTemplate tt = new TransactionTemplate(tm);
    final JdbcCursorItemReader<String> reader = new JdbcCursorItemReader<String>();
    reader.setDataSource(ds);
    reader.setSql("select foo from bar");
    final ExecutionContext ec = new ExecutionContext();
    tt.execute(
        new TransactionCallback<Void>() {
                    @Override
          public Void doInTransaction(TransactionStatus status) {
            reader.open(ec);
View Full Code Here

          }
        });
    reader.setRowMapper(new FooRowMapper());
    reader.setVerifyCursorPosition(false);
    reader.afterPropertiesSet();
    reader.open(new ExecutionContext());   
  }
View Full Code Here

  /**
   * @param jobRepository a {@link org.springframework.batch.core.repository.JobRepository}
   */
  public SimpleStepHandler(JobRepository jobRepository) {
    this(jobRepository, new ExecutionContext());
  }
View Full Code Here

        if(lastStepExecution.getExecutionContext().containsKey("batch.executed")) {
          currentStepExecution.getExecutionContext().remove("batch.executed");
        }
      }
      else {
        currentStepExecution.setExecutionContext(new ExecutionContext(executionContext));
      }

      jobRepository.add(currentStepExecution);

      logger.info("Executing step: [" + step.getName() + "]");
View Full Code Here

   * @see AbstractStep#doExecute(StepExecution)
   */
  @Override
  protected void doExecute(StepExecution stepExecution) throws Exception {

    ExecutionContext executionContext = stepExecution.getExecutionContext();

    executionContext.put(STEP_TYPE_KEY, this.getClass().getName());

    JobParameters jobParameters;
    if (executionContext.containsKey(JOB_PARAMETERS_KEY)) {
      jobParameters = (JobParameters) executionContext.get(JOB_PARAMETERS_KEY);
    }
    else {
      jobParameters = jobParametersExtractor.getJobParameters(job, stepExecution);
      executionContext.put(JOB_PARAMETERS_KEY, jobParameters);
    }

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);
    if (jobExecution.getStatus().isUnsuccessful()) {
      // AbstractStep will take care of the step execution status
View Full Code Here

    private void copy(final StepExecution source, final StepExecution target) {
      target.setVersion(source.getVersion());
      target.setWriteCount(source.getWriteCount());
      target.setFilterCount(source.getFilterCount());
      target.setCommitCount(source.getCommitCount());
      target.setExecutionContext(new ExecutionContext(source.getExecutionContext()));
    }
View Full Code Here

   */
  @Override
  public JobParameters getJobParameters(Job job, StepExecution stepExecution) {
    JobParametersBuilder builder = new JobParametersBuilder();
    Map<String, JobParameter> jobParameters = stepExecution.getJobParameters().getParameters();
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    if (useAllParentParameters) {
      for (String key : jobParameters.keySet()) {
        builder.addParameter(key, jobParameters.get(key));
      }
    }
    for (String key : keys) {
      if (key.endsWith("(long)")) {
        key = key.replace("(long)", "");
        if (executionContext.containsKey(key)) {
          builder.addLong(key, executionContext.getLong(key));
        }
        else if (jobParameters.containsKey(key)) {
          builder.addLong(key, (Long) jobParameters.get(key).getValue());
        }
      }
      else if (key.endsWith("(int)")) {
        key = key.replace("(int)", "");
        if (executionContext.containsKey(key)) {
          builder.addLong(key, (long) executionContext.getInt(key));
        }
        else if (jobParameters.containsKey(key)) {
          builder.addLong(key, (Long) jobParameters.get(key).getValue());
        }
      }
      else if (key.endsWith("(double)")) {
        key = key.replace("(double)", "");
        if (executionContext.containsKey(key)) {
          builder.addDouble(key, executionContext.getDouble(key));
        }
        else if (jobParameters.containsKey(key)) {
          builder.addDouble(key, (Double) jobParameters.get(key).getValue());
        }
      }
      else if (key.endsWith("(string)")) {
        key = key.replace("(string)", "");
        if (executionContext.containsKey(key)) {
          builder.addString(key, executionContext.getString(key));
        }
        else if (jobParameters.containsKey(key)) {
          builder.addString(key, (String) jobParameters.get(key).getValue());
        }
      }
      else if (key.endsWith("(date)")) {
        key = key.replace("(date)", "");
        if (executionContext.containsKey(key)) {
          builder.addDate(key, (Date) executionContext.get(key));
        }
        else if (jobParameters.containsKey(key)) {
          builder.addDate(key, (Date) jobParameters.get(key).getValue());
        }
      }
      else {
        if (executionContext.containsKey(key)) {
          builder.addString(key, executionContext.get(key).toString());
        }
        else if (jobParameters.containsKey(key)) {
          builder.addString(key, jobParameters.get(key).getValue().toString());
        }
      }
View Full Code Here

  private boolean strict = false;

  @Override
  public ExitStatus afterStep(StepExecution stepExecution) {
    ExecutionContext stepContext = stepExecution.getExecutionContext();
    ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
    String exitCode = stepExecution.getExitStatus().getExitCode();
    for (String statusPattern : statuses) {
      if (PatternMatcher.match(statusPattern, exitCode)) {
        for (String key : keys) {
          if (stepContext.containsKey(key)) {
            jobContext.put(key, stepContext.get(key));
          } else {
            if (strict) {
              throw new IllegalArgumentException("The key [" + key
                  + "] was not found in the Step's ExecutionContext.");
            }
View Full Code Here

  /**
   * Open the reader if applicable.
   */
  private void open(ItemReader<?> reader) {
    if (reader instanceof ItemStream) {
      ((ItemStream) reader).open(new ExecutionContext());
    }
  }
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.