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);
}
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();
}
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;
}
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();
}
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);
}
Aggregations