本文整理汇总了Java中org.springframework.batch.core.JobParametersBuilder.addString方法的典型用法代码示例。如果您正苦于以下问题:Java JobParametersBuilder.addString方法的具体用法?Java JobParametersBuilder.addString怎么用?Java JobParametersBuilder.addString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.core.JobParametersBuilder
的用法示例。
在下文中一共展示了JobParametersBuilder.addString方法的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: warmCache
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@GET
@Path("{sourceKey}/warmCache")
@Produces(MediaType.APPLICATION_JSON)
public JobExecutionResource warmCache(@PathParam("sourceKey") final String sourceKey) {
ResultsCache resultsCache = new ResultsCache();
CDMResultsCache cache = resultsCache.getCache(sourceKey);
if (cache != null) {
return new JobExecutionResource();
}
Source source = getSourceRepository().findBySourceKey(sourceKey);
CDMResultsCacheTasklet tasklet = new CDMResultsCacheTasklet(this.getSourceJdbcTemplate(source), source);
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("jobName", "warming " + sourceKey + " cache ");
return this.jobTemplate.launchTasklet("warmCache", "warmCacheStep", tasklet, builder.toJobParameters());
}
示例5: 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();
}
示例6: requestJob3
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@RequestMapping("/job3/{input_file_name}")
@ResponseBody
String requestJob3(@PathVariable("input_file_name") String inputFileName) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException{
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("INPUT_FILE_PATH", inputFileName);
jobParametersBuilder.addLong("TIMESTAMP",new Date().getTime());
jobLauncher.run(job3, jobParametersBuilder.toJobParameters());
return "Job3!";
}
开发者ID:pauldeng,项目名称:aws-elastic-beanstalk-worker-spring-boot-spring-batch-template,代码行数:11,代码来源:RESTController.java
示例7: test
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
JobParametersBuilder jpb = new JobParametersBuilder();
jpb.addString("input_file_path", "src/test/resources/triple/test1.ttl");
jpb.addString("graph_name", "myTestGraph");
getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
String xml = getClient().newServerEval().xquery("collection('myTestGraph')").evalAs(String.class);
Fragment f = parse(xml);
f.assertElementExists("/sem:triples/sem:triple[sem:subject = 'http://example.org/kennedy/person1']");
}
示例8: runJobTest
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void runJobTest() throws Exception {
JobParametersBuilder jpb = new JobParametersBuilder();
jpb.addString("output_collections", "monster");
JobExecution jobExecution = jobLauncherTestUtils.launchJob(jpb.toJobParameters());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}
示例9: findOneMonsterInDatabaseTest
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void findOneMonsterInDatabaseTest() throws Exception {
JobParametersBuilder jpb = new JobParametersBuilder();
jpb.addString("output_collections", "monster");
JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
getClientTestHelper().assertCollectionSize("Expecting 100 items in monster collection", "monster", 100);
}
示例10: runJobTwiceTest
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void runJobTwiceTest() throws Exception {
JobParametersBuilder jpb = new JobParametersBuilder();
jpb.addString("output_collections", "monster", false);
jpb.addLong("run_id", 1L, true);
JobExecution jobExecution = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
jpb.addLong("run_id", 2L);
JobExecution jobExecution2 = getJobLauncherTestUtils().launchJob(jpb.toJobParameters());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution2.getStatus());
}
示例11: testLaunchJob
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void testLaunchJob() throws Exception {
JobParametersBuilder pb = new JobParametersBuilder();
pb.addString("xml.input", "classpath:sample-exchange-schema.xml");
pb.addString("tab.output", "file:out/sample.tab");
jobLauncher.run(job, pb.toJobParameters());
}
示例12: testJob
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void testJob() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, InterruptedException{
// should be zero
Assert.assertEquals(0, getHits());
JobParametersBuilder pb = new JobParametersBuilder();
pb.addString("contactInfo", DIRECTORY + "contactInfo.txt");
pb.addString("biobank", DIRECTORY + "biobank.txt");
pb.addString("sampleCollection", DIRECTORY + "sampleCollection.txt");
pb.addString("study", DIRECTORY + "study.txt");
pb.addString("sample", DIRECTORY + "sample.txt");
pb.addString("map","example.mapping.properties");
//Elasticsearch config
pb.addString("cluster.nodes", "localhost:9300");
pb.addString("cluster.name", "elasticsearch");
pb.addString("index.name", "sample");
JobExecution launch = jobLauncher.run(job, pb.toJobParameters());
while(launch.isRunning()){
Thread.sleep(5000);
}
Thread.sleep(5000);
Assert.assertEquals(3, getHits());
}
示例13: testLaunchJob
import org.springframework.batch.core.JobParametersBuilder; //导入方法依赖的package包/类
@Test
public void testLaunchJob() throws Exception {
JobParametersBuilder pb = new JobParametersBuilder();
pb.addString("contactInfo", DIRECTORY + "contactInfo.txt");
pb.addString("biobank", DIRECTORY + "biobank.txt");
pb.addString("sampleCollection", DIRECTORY + "sampleCollection.txt");
pb.addString("study", DIRECTORY + "study.txt");
pb.addString("sample", DIRECTORY + "sample.txt");
pb.addString("map","example.mapping.properties");
pb.addString("tab.output",DIRECTORY_OUT + "db.out.tab");
jobLauncher.run(job, pb.toJobParameters());
}
示例14: 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;
}
示例15: 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();
}