Search in sources :

Example 1 with JobParametersBuilder

use of org.springframework.batch.core.JobParametersBuilder in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method basicExecution.

@Test
public void basicExecution() throws Exception {
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
    this.runner.execute(this.job, new JobParametersBuilder().addLong("id", 1L).toJobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Test(org.junit.Test)

Example 2 with JobParametersBuilder

use of org.springframework.batch.core.JobParametersBuilder in project head by mifos.

the class MifosBatchJob method createJobParameters.

public static JobParameters createJobParameters(long scheduledLaunchTime) {
    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addLong(JOB_EXECUTION_TIME_KEY, scheduledLaunchTime);
    return builder.toJobParameters();
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder)

Example 3 with JobParametersBuilder

use of org.springframework.batch.core.JobParametersBuilder in project camel by apache.

the class SpringBatchProducer method prepareJobParameters.

/**
     * Helper method converting the Camel message headers into the Spring Batch parameters map. Date, Long and Double
     * header values are converted to the appropriate types. All the other header values are converted to string
     * representation.
     *
     * @param headers Camel message header to be converted
     * @return Camel message headers converted into the Spring Batch parameters map
     */
protected JobParameters prepareJobParameters(Map<String, Object> headers) {
    JobParametersBuilder parametersBuilder = new JobParametersBuilder();
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        String headerKey = headerEntry.getKey();
        Object headerValue = headerEntry.getValue();
        if (headerValue instanceof Date) {
            parametersBuilder.addDate(headerKey, (Date) headerValue);
        } else if (headerValue instanceof Long) {
            parametersBuilder.addLong(headerKey, (Long) headerValue);
        } else if (headerValue instanceof Double) {
            parametersBuilder.addDouble(headerKey, (Double) headerValue);
        } else if (headerValue != null) {
            parametersBuilder.addString(headerKey, headerValue.toString());
        } else {
            // if the value is null we just put String with null value here to avoid the NPE
            parametersBuilder.addString(headerKey, null);
        }
    }
    JobParameters jobParameters = parametersBuilder.toJobParameters();
    log.debug("Prepared parameters for Spring Batch job: {}", jobParameters);
    return jobParameters;
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Map(java.util.Map) Date(java.util.Date)

Example 4 with JobParametersBuilder

use of org.springframework.batch.core.JobParametersBuilder in project pinpoint by naver.

the class BatchJobLauncher method createTimeParameter.

private JobParameters createTimeParameter() {
    JobParametersBuilder builder = new JobParametersBuilder();
    Date now = new Date();
    builder.addDate("schedule.date", now);
    return builder.toJobParameters();
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) Date(java.util.Date)

Example 5 with JobParametersBuilder

use of org.springframework.batch.core.JobParametersBuilder in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method retryFailedExecutionWithNonIdentifyingParameters.

@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
    this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(new Tasklet() {

        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            throw new RuntimeException("Planned");
        }
    }).build()).incrementer(new RunIdIncrementer()).build();
    JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false).toJobParameters();
    this.runner.execute(this.job, jobParameters);
    this.runner.execute(this.job, jobParameters);
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
Also used : StepContribution(org.springframework.batch.core.StepContribution) JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Aggregations

JobParametersBuilder (org.springframework.batch.core.JobParametersBuilder)5 JobParameters (org.springframework.batch.core.JobParameters)3 Date (java.util.Date)2 Test (org.junit.Test)2 Map (java.util.Map)1 StepContribution (org.springframework.batch.core.StepContribution)1 RunIdIncrementer (org.springframework.batch.core.launch.support.RunIdIncrementer)1 ChunkContext (org.springframework.batch.core.scope.context.ChunkContext)1 Tasklet (org.springframework.batch.core.step.tasklet.Tasklet)1