本文整理汇总了Java中org.springframework.batch.core.JobParametersBuilder.addDate方法的典型用法代码示例。如果您正苦于以下问题:Java JobParametersBuilder.addDate方法的具体用法?Java JobParametersBuilder.addDate怎么用?Java JobParametersBuilder.addDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.batch.core.JobParametersBuilder
的用法示例。
在下文中一共展示了JobParametersBuilder.addDate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例6: 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();
}
示例7: 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();
}