本文整理汇总了Java中org.springframework.batch.core.JobParametersBuilder.toJobParameters方法的典型用法代码示例。如果您正苦于以下问题:Java JobParametersBuilder.toJobParameters方法的具体用法?Java JobParametersBuilder.toJobParameters怎么用?Java JobParametersBuilder.toJobParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.core.JobParametersBuilder
的用法示例。
在下文中一共展示了JobParametersBuilder.toJobParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareJobParameters
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* 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;
}
示例2: unmarshal
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters unmarshal(AdaptedJobParameters params) throws Exception {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
for (AdaptedJobParameters.AdaptedJobParameter param : params.getParameters()) {
switch (param.type) {
case "STRING":
jobParametersBuilder.addString(param.key, param.value, param.identifier);
break;
case "DATE":
jobParametersBuilder.addDate(param.key, df.parse(param.value), param.identifier);
break;
case "DOUBLE":
jobParametersBuilder.addDouble(param.key, Double.valueOf(param.value), param.identifier);
break;
case "LONG":
jobParametersBuilder.addLong(param.key, Long.valueOf(param.value), param.identifier);
break;
}
}
return jobParametersBuilder.toJobParameters();
}
示例3: getJobParameters
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
public static JobParameters getJobParameters() {
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
if (jobParameters.isEmpty()) {
jobParametersBuilder.addLong("id", 1L, true);
jobParametersBuilder.addString("stringTest", "Joe Cool", true);
jobParametersBuilder.addDate("start", new Date(), false);
jobParametersBuilder.addLong("longTest", 1239L, false);
jobParametersBuilder.addDouble("doubleTest", 1.35D, false);
jobParameters = jobParametersBuilder.toJobParameters();
} else {
JobParametersTestUtils utils = new JobParametersTestUtils();
jobParameters = utils.getNext(jobParameters);
}
return jobParameters;
}
示例4: getJobParametersFromJobMap
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Copy parameters that are of the correct type over to
* {@link org.springframework.batch.core.launch.JobLauncher JobParameters},
* ignoring jobName.
*
* @return a JobParameters instance
*/
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap, JobParameters sPreviousJobParameters) {
JobParametersBuilder builder = (sPreviousJobParameters != null) ? new JobParametersBuilder(sPreviousJobParameters) : new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
LOGGER.debug("JobDataMap contains values which are not job parameters (ignoring).");
}
}
return builder.toJobParameters();
}
示例5: generateFeatures
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@GET
@Path("/generate/{sourceKey}/{id}")
@Produces(MediaType.APPLICATION_JSON)
public JobExecutionResource generateFeatures(@PathParam("id") final int id, @PathParam("sourceKey") final String sourceKey) {
Source source = getSourceRepository().findBySourceKey(sourceKey);
String cdmTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.CDM);
String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
DefaultTransactionDefinition requresNewTx = new DefaultTransactionDefinition();
requresNewTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus initStatus = this.getTransactionTemplate().getTransactionManager().getTransaction(requresNewTx);
this.getTransactionTemplate().getTransactionManager().commit(initStatus);
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("jobName", "generating features for cohort " + id + " : " + source.getSourceName()
+ " (" + source.getSourceKey() + ")");
builder.addString("cdm_database_schema", cdmTableQualifier);
builder.addString("results_database_schema", resultsTableQualifier);
builder.addString("target_dialect", source.getSourceDialect());
builder.addString("cohort_definition_id", ("" + id));
builder.addString("source_id", ("" + source.getSourceId()));
final JobParameters jobParameters = builder.toJobParameters();
log.info(String.format("Beginning generate cohort features for cohort definition id: \n %s", "" + id));
GenerateCohortFeaturesTasklet generateCohortFeaturesTasklet
= new GenerateCohortFeaturesTasklet(getSourceJdbcTemplate(source), getTransactionTemplate());
Step generateCohortFeaturesStep = stepBuilders.get("cohortFeatures.generateFeatures")
.tasklet(generateCohortFeaturesTasklet)
.build();
Job generateCohortFeaturesJob = jobBuilders.get("generateFeatures")
.start(generateCohortFeaturesStep)
.build();
JobExecutionResource jobExec = this.jobTemplate.launch(generateCohortFeaturesJob, jobParameters);
return jobExec;
}
示例6: convert
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters convert(final JsonNode root) {
final JobParametersBuilder builder = new JobParametersBuilder();
final Iterator<String> it = root.fieldNames();
while (it.hasNext()) {
final String paramName = it.next();
final JsonNode param = root.get(paramName);
final ParameterType type = ParameterType.valueOf(param.get("type").textValue());
final JsonNode value = param.get("value");
final boolean identifying = param.get("identifying").booleanValue();
switch (type) {
case STRING:
builder.addString(paramName, value.textValue(), identifying);
break;
case DATE:
builder.addDate(paramName, new Date(value.longValue()), identifying);
break;
case DOUBLE:
builder.addDouble(paramName, value.doubleValue(), identifying);
break;
case LONG:
builder.addLong(paramName, value.longValue(), identifying);
break;
default:
throw new IllegalArgumentException("Unknown job parameter type: " + type);
}
}
return builder.toJobParameters();
}
示例7: toRequest
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
public JobLaunchRequest toRequest(Message<File> message) {
JobParametersBuilder jobParametersBuilder =
new JobParametersBuilder();
jobParametersBuilder
.addString(fileName, message.getPayload().getAbsolutePath())
.addDate("run.date", new Date());
return new JobLaunchRequest(job, jobParametersBuilder.toJobParameters());
}
开发者ID:SpringOne2GX-2014,项目名称:spring-batch-performance-tuning,代码行数:11,代码来源:FileMessageToJobRequest.java
示例8: getJobParametersFromJobMap
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {
JobParametersBuilder builder = new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(Constants.JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
// JobDataMap contains values which are not job parameters
// (ignoring)
}
}
// Needs a unique job parameter to rerun the completed job
builder.addDate(Constants.JOB_RUN_DATE, new Date());
return builder.toJobParameters();
}
示例9: getNext
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters getNext(JobParameters parameters) {
final JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(parameters);
jobParametersBuilder.addLong("time", LocalTime.now().toNanoOfDay());
return jobParametersBuilder.toJobParameters();
}
开发者ID:przodownikR1,项目名称:springBatchBootJavaConfigkata,代码行数:7,代码来源:SimpleJobParametersIncrementer.java
示例10: getNext
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Override
public JobParameters getNext(JobParameters parameters) {
JobParametersBuilder builder = new JobParametersBuilder(parameters);
builder.addLong("id", parameters.getLong("id") + 1);
return builder.toJobParameters();
}
示例11: queueCohortAnalysisJob
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Queues up a cohort analysis task, that generates and translates SQL for the
* given cohort definitions, analysis ids and concept ids
*
* @param task - the Cohort Analysis task to be ran
* @return information about the Cohort Analysis Job
* @throws Exception
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JobExecutionResource queueCohortAnalysisJob(CohortAnalysisTask task) throws Exception {
if (task == null) {
return null;
}
JobParametersBuilder builder = new JobParametersBuilder();
// source key comes from the client, we look it up here and hand it off to the tasklet
Source source = getSourceRepository().findBySourceKey(task.getSourceKey());
task.setSource(source);
builder.addString("cohortDefinitionIds", limitJobParams(Joiner.on(",").join(task.getCohortDefinitionIds())));
builder.addString("analysisIds", limitJobParams(Joiner.on(",").join(task.getAnalysisIds())));
if (task.getConditionConceptIds() != null && task.getConditionConceptIds().size() > 0) {
builder.addString("conditionIds", limitJobParams(Joiner.on(",").join(task.getConditionConceptIds())));
}
if (task.getDrugConceptIds() != null && task.getDrugConceptIds().size() > 0) {
builder.addString("drugIds", limitJobParams(Joiner.on(",").join(task.getDrugConceptIds())));
}
if (task.getMeasurementConceptIds() != null && task.getMeasurementConceptIds().size() > 0) {
builder.addString("measurementIds", limitJobParams(Joiner.on(",").join(task.getMeasurementConceptIds())));
}
if (task.getObservationConceptIds() != null && task.getObservationConceptIds().size() > 0) {
builder.addString("observationIds", limitJobParams(Joiner.on(",").join(task.getObservationConceptIds())));
}
if (task.getProcedureConceptIds() != null && task.getProcedureConceptIds().size() > 0) {
builder.addString("procedureIds", limitJobParams(Joiner.on(",").join(task.getProcedureConceptIds())));
}
if (task.isRunHeraclesHeel()) {
builder.addString("heraclesHeel", "true");
}
if (task.isCohortPeriodOnly()) {
builder.addString("cohortPeriodOnly", "true");
}
if (!StringUtils.isEmpty(task.getJobName())) {
builder.addString("jobName", limitJobParams(task.getJobName()));
}
//TODO consider analysisId
final String taskString = task.toString();
final JobParameters jobParameters = builder.toJobParameters();
log.info(String.format("Beginning run for cohort analysis task: \n %s", taskString));
CohortAnalysisTasklet tasklet = new CohortAnalysisTasklet(task, getSourceJdbcTemplate(task.getSource()),
getTransactionTemplate(), this.getSourceDialect(), this.visualizationDataRepository);
return this.jobTemplate.launchTasklet("cohortAnalysisJob", "cohortAnalysisStep", tasklet, jobParameters);
}
示例12: queueNegativeControlsJob
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Queues up a negative control task, that generates and translates SQL for the
* given concept ids
*
* @param task - the negative control task to run
* @return information about the negative control job
* @throws Exception
*/
@POST
@Path("{sourceKey}/negativecontrols")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JobExecutionResource queueNegativeControlsJob(@PathParam("sourceKey") String sourceKey, NegativeControl task) throws Exception {
if (task == null) {
return null;
}
JobParametersBuilder builder = new JobParametersBuilder();
// Get a JDBC template for the OHDSI source repository
// and the source dialect for use when we write the results
// back to the OHDSI repository
JdbcTemplate jdbcTemplate = getJdbcTemplate();
task.setJdbcTemplate(jdbcTemplate);
String ohdsiDatasourceSourceDialect = getSourceDialect();
task.setSourceDialect(ohdsiDatasourceSourceDialect);
task.setOhdsiSchema(this.getOhdsiSchema());
// source key comes from the client, we look it up here and hand it off to the tasklet
Source source = getSourceRepository().findBySourceKey(sourceKey);
task.setSource(source);
if (!StringUtils.isEmpty(task.getJobName())) {
builder.addString("jobName", limitJobParams(task.getJobName()));
}
builder.addString("concept_set_id", ("" + task.getConceptSetId()));
builder.addString("concept_set_name", task.getConceptSetName());
builder.addString("concept_domain_id", task.getConceptDomainId());
builder.addString("source_id", ("" + source.getSourceId()));
final String taskString = task.toString();
final JobParameters jobParameters = builder.toJobParameters();
log.info(String.format("Beginning run for negative controls analysis task: \n %s", taskString));
NegativeControlTasklet tasklet = new NegativeControlTasklet(task, getSourceJdbcTemplate(task.getSource()), task.getJdbcTemplate(),
getTransactionTemplate(), this.conceptSetGenerationInfoRepository, this.getSourceDialect());
return this.jobTemplate.launchTasklet("negativeControlsAnalysisJob", "negativeControlsAnalysisStep", tasklet, jobParameters);
}
示例13: generateCohort
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
/**
* Queues up a generate cohort task for the specified cohort definition id.
*
* @param id - the Cohort Definition ID to generate
* @return information about the Cohort Analysis Job
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/generate/{sourceKey}")
public JobExecutionResource generateCohort(@PathParam("id") final int id, @PathParam("sourceKey") final String sourceKey, @QueryParam("includeFeatures") final String includeFeatures) {
Source source = getSourceRepository().findBySourceKey(sourceKey);
String cdmTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.CDM);
String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
DefaultTransactionDefinition requresNewTx = new DefaultTransactionDefinition();
requresNewTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus initStatus = this.getTransactionTemplate().getTransactionManager().getTransaction(requresNewTx);
CohortDefinition currentDefinition = this.cohortDefinitionRepository.findOne(id);
CohortGenerationInfo info = findBySourceId(currentDefinition.getGenerationInfoList(), source.getSourceId());
if (info == null) {
info = new CohortGenerationInfo(currentDefinition, source.getSourceId());
currentDefinition.getGenerationInfoList().add(info);
}
info.setStatus(GenerationStatus.PENDING)
.setStartTime(Calendar.getInstance().getTime());
info.setIncludeFeatures(includeFeatures != null);
this.cohortDefinitionRepository.save(currentDefinition);
this.getTransactionTemplate().getTransactionManager().commit(initStatus);
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("jobName", "generating cohort " + currentDefinition.getId() + " : " + source.getSourceName() + " (" + source.getSourceKey() + ")");
builder.addString("cdm_database_schema", cdmTableQualifier);
builder.addString("results_database_schema", resultsTableQualifier);
builder.addString("target_database_schema", resultsTableQualifier);
builder.addString("target_dialect", source.getSourceDialect());
builder.addString("target_table", "cohort");
builder.addString("cohort_definition_id", ("" + id));
builder.addString("source_id", ("" + source.getSourceId()));
builder.addString("generate_stats", Boolean.TRUE.toString());
final JobParameters jobParameters = builder.toJobParameters();
log.info(String.format("Beginning generate cohort for cohort definition id: \n %s", "" + id));
GenerateCohortTasklet generateTasklet = new GenerateCohortTasklet(getSourceJdbcTemplate(source), getTransactionTemplate(), cohortDefinitionRepository);
Step generateCohortStep = stepBuilders.get("cohortDefinition.generateCohort")
.tasklet(generateTasklet)
.build();
SimpleJobBuilder generateJobBuilder = jobBuilders.get("generateCohort")
.listener(new GenerationJobExecutionListener(cohortDefinitionRepository, this.getTransactionTemplateRequiresNew(), this.getSourceJdbcTemplate(source)))
.start(generateCohortStep);
if (includeFeatures != null) {
GenerateCohortFeaturesTasklet generateCohortFeaturesTasklet =
new GenerateCohortFeaturesTasklet(getSourceJdbcTemplate(source), getTransactionTemplate());
Step generateCohortFeaturesStep = stepBuilders.get("cohortFeatures.generateFeatures")
.tasklet(generateCohortFeaturesTasklet)
.build();
generateJobBuilder.next(generateCohortFeaturesStep);
}
Job generateCohortJob = generateJobBuilder.build();
JobExecutionResource jobExec = this.jobTemplate.launch(generateCohortJob, jobParameters);
return jobExec;
}
示例14: performAnalysis
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@GET
@Path("/{analysis_id}/execute/{sourceKey}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JobExecutionResource performAnalysis(@PathParam("analysis_id") final int analysisId, @PathParam("sourceKey") final String sourceKey) {
Date startTime = Calendar.getInstance().getTime();
Source source = this.getSourceRepository().findBySourceKey(sourceKey);
String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
String cdmTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.CDM);
DefaultTransactionDefinition requresNewTx = new DefaultTransactionDefinition();
requresNewTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus initStatus = this.getTransactionTemplate().getTransactionManager().getTransaction(requresNewTx);
IncidenceRateAnalysis analysis = this.irAnalysisRepository.findOne(analysisId);
ExecutionInfo analysisInfo = findExecutionInfoBySourceId(analysis.getExecutionInfoList(), source.getSourceId());
if (analysisInfo != null) {
if (analysisInfo.getStatus() != GenerationStatus.COMPLETE)
return null; // Exit execution, another process has started it.
}
else {
analysisInfo = new ExecutionInfo(analysis, source);
analysis.getExecutionInfoList().add(analysisInfo);
}
analysisInfo.setStatus(GenerationStatus.PENDING)
.setStartTime(startTime)
.setExecutionDuration(null);
this.irAnalysisRepository.save(analysis);
this.getTransactionTemplate().getTransactionManager().commit(initStatus);
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("jobName", "IR Analysis: " + analysis.getId() + " : " + source.getSourceName() + " (" + source.getSourceKey() + ")");
builder.addString("cdm_database_schema", cdmTableQualifier);
builder.addString("results_database_schema", resultsTableQualifier);
builder.addString("target_dialect", source.getSourceDialect());
builder.addString("analysis_id", ("" + analysisId));
builder.addString("source_id", ("" + source.getSourceId()));
final JobParameters jobParameters = builder.toJobParameters();
PerformAnalysisTasklet analysisTasklet = new PerformAnalysisTasklet(getSourceJdbcTemplate(source), getTransactionTemplate(), irAnalysisRepository);
Step irAnalysisStep = stepBuilders.get("irAnalysis.execute")
.tasklet(analysisTasklet)
.build();
Job executeAnalysis = jobBuilders.get("irAnalysis")
.start(irAnalysisStep)
.build();
JobExecutionResource jobExec = this.jobTemplate.launch(executeAnalysis, jobParameters);
return jobExec; }
示例15: createTimeParameter
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
private JobParameters createTimeParameter() {
JobParametersBuilder builder = new JobParametersBuilder();
Date now = new Date();
builder.addDate("schedule.date", now);
return builder.toJobParameters();
}