Package org.springframework.batch.core

Examples of org.springframework.batch.core.JobParametersIncrementer


  private JobParameters getNextJobParameters(Job job, boolean fail) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
      throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
      jobParameters = incrementer.getNext(new JobParameters());
      if (jobParameters == null) {
        throw new JobParametersNotFoundException("No bootstrap parameters found from incrementer for job="
            + jobIdentifier);
      }
    } else {
      List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
      jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }
    return jobParameters;
  }
View Full Code Here


  public void setUp() throws Exception {

    job = new JobSupport("foo") {
      @Override
      public JobParametersIncrementer getJobParametersIncrementer() {
        return new JobParametersIncrementer() {
          @Override
          public JobParameters getNext(JobParameters parameters) {
            return jobParameters;
          }
        };
View Full Code Here

    if (target instanceof AbstractJob) {

      AbstractJob job = (AbstractJob) target;
      job.setJobRepository(properties.getJobRepository());

      JobParametersIncrementer jobParametersIncrementer = properties.getJobParametersIncrementer();
      if (jobParametersIncrementer != null) {
        job.setJobParametersIncrementer(jobParametersIncrementer);
      }
      JobParametersValidator jobParametersValidator = properties.getJobParametersValidator();
      if (jobParametersValidator != null) {
View Full Code Here

  private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
      throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
      jobParameters = incrementer.getNext(new JobParameters());
      if (jobParameters == null) {
        throw new JobParametersNotFoundException("No bootstrap parameters found from incrementer for job="
            + jobIdentifier);
      }
    }
    else {
      List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
      jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }
    return jobParameters;
  }
View Full Code Here

    logger.info("Locating parameters for next instance of job with name=" + jobName);

    Job job = jobRegistry.getJob(jobName);
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobName, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
      throw new JobParametersNotFoundException("No job parameters incrementer found for job=" + jobName);
    }

    JobParameters parameters;
    if (lastInstances.isEmpty()) {
      parameters = incrementer.getNext(new JobParameters());
      if (parameters == null) {
        throw new JobParametersNotFoundException("No bootstrap parameters found for job=" + jobName);
      }
    }
    else {
      List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
      parameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
    }

    logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters));
    try {
      return jobLauncher.run(job, parameters).getId();
View Full Code Here

  }

  @Test
  public void testCreateJobExecutionsWithIncrementer() throws Exception {
    utils = new JobRepositoryTestUtils(jobRepository, dataSource);
    utils.setJobParametersIncrementer(new JobParametersIncrementer() {
      @Override
      public JobParameters getNext(JobParameters parameters) {
        return new JobParametersBuilder().addString("foo","bar").toJobParameters();
      }
    });
View Full Code Here

    String jobIdentifier = job.getName();
    JobParameters jobParameters = new JobParameters();
    List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(jobIdentifier,
        0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();

    Map<String, JobParameter> additionals = additionalParameters.getParameters();
    if (lastInstances.isEmpty()) {
      // Start from a completely clean sheet
      if (incrementer != null) {
        jobParameters = incrementer.getNext(new JobParameters());
      }
    }
    else {
      List<JobExecution> lastExecutions = this.jobExplorer
          .getJobExecutions(lastInstances.get(0));
      JobExecution previousExecution = lastExecutions.get(0);
      if (previousExecution == null) {
        // Normally this will not happen - an instance exists with no executions
        if (incrementer != null) {
          jobParameters = incrementer.getNext(new JobParameters());
        }
      }
      else if (previousExecution.getStatus() == BatchStatus.STOPPED
          || previousExecution.getStatus() == BatchStatus.FAILED) {
        // Retry a failed or stopped execution
        jobParameters = previousExecution.getJobParameters();
        for (Entry<String, JobParameter> parameter : new HashMap<String, JobParameter>(
            additionals).entrySet()) {
          // Non-identifying additional parameters can be added to a retry
          if (!parameter.getValue().isIdentifying()) {
            additionals.remove(parameter.getKey());
          }
        }
      }
      else if (incrementer != null) {
        // New instance so increment the parameters if we can
        if (incrementer != null) {
          jobParameters = incrementer.getNext(previousExecution
              .getJobParameters());
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.JobParametersIncrementer

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.