Example usage for org.springframework.batch.core JobParameter JobParameter

List of usage examples for org.springframework.batch.core JobParameter JobParameter

Introduction

In this page you can find the example usage for org.springframework.batch.core JobParameter JobParameter.

Prototype

public JobParameter(Double parameter, boolean identifying) 

Source Link

Document

Construct a new JobParameter as a Double.

Usage

From source file:org.duracloud.snapshot.service.impl.SnapshotJobParameterMarshaller.java

/**
 * @param snapshot/*from  ww w  .j ava 2  s.c  o  m*/
 * @return
 */
public static Map<String, JobParameter> marshal(Snapshot snapshot) {
    Map<String, JobParameter> map = new HashMap<>();
    map.put(SnapshotServiceConstants.SPRING_BATCH_UNIQUE_ID, new JobParameter(snapshot.getName(), true));
    return map;
}

From source file:org.duracloud.snapshot.service.impl.RestoreJobParameterMarshaller.java

/**
 * @param snapshot/*  ww w  .ja  v  a2 s  . co m*/
 * @return
 */
public static Map<String, JobParameter> marshal(Restoration restoration) {
    Map<String, JobParameter> map = new HashMap<>();
    map.put(SnapshotServiceConstants.SPRING_BATCH_UNIQUE_ID,
            new JobParameter(restoration.getRestorationId(), true));
    return map;
}

From source file:org.springframework.cloud.dataflow.rest.client.support.JobParameterJacksonDeserializer.java

@Override
public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    final String value = node.get("value").asText();
    final boolean identifying = node.get("identifying").asBoolean();
    final String type = node.get("type").asText();

    final JobParameter jobParameter;

    if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) {
        if ("DATE".equalsIgnoreCase(type)) {
            // TODO: when upgraded to Java8 use java DateTime
            jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying);
        } else if ("DOUBLE".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Double.valueOf(value), identifying);
        } else if ("LONG".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Long.valueOf(value), identifying);
        } else {/*w ww.  j  av a 2 s  .  c  o  m*/
            throw new IllegalStateException("Unsupported JobParameter type: " + type);
        }
    } else {
        jobParameter = new JobParameter(value, identifying);
    }

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)",
                jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying()));
    }

    return jobParameter;
}

From source file:org.springframework.batch.admin.domain.support.JobParameterJacksonDeserializer.java

@Override
public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    SimpleDateFormat formatter = new SimpleDateFormat();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    final String value = node.get("value").asText();
    final boolean identifying = node.get("identifying").asBoolean();
    final String type = node.get("type").asText();

    final JobParameter jobParameter;

    if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) {
        if ("DATE".equalsIgnoreCase(type)) {
            try {
                jobParameter = new JobParameter(formatter.parse(value), identifying);
            } catch (ParseException e) {
                throw new IOException(e);
            }/*from w w  w . j a  v a  2 s  .c  o  m*/
        } else if ("DOUBLE".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Double.valueOf(value), identifying);
        } else if ("LONG".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Long.valueOf(value), identifying);
        } else {
            throw new IllegalStateException("Unsupported JobParameter type: " + type);
        }
    } else {
        jobParameter = new JobParameter(value, identifying);
    }

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)",
                jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying()));
    }

    return jobParameter;
}

From source file:org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.java

/**
 * @param executionId/*from w  ww .  java 2 s.  c  o  m*/
 * @return job parameters for the requested execution id
 */
protected JobParameters getJobParameters(Long executionId) {
    final Map<String, JobParameter> map = new HashMap<String, JobParameter>();
    RowCallbackHandler handler = new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            ParameterType type = ParameterType.valueOf(rs.getString(3));
            JobParameter value = null;

            if (type == ParameterType.STRING) {
                value = new JobParameter(rs.getString(4), rs.getString(8).equalsIgnoreCase("Y"));
            } else if (type == ParameterType.LONG) {
                value = new JobParameter(rs.getLong(6), rs.getString(8).equalsIgnoreCase("Y"));
            } else if (type == ParameterType.DOUBLE) {
                value = new JobParameter(rs.getDouble(7), rs.getString(8).equalsIgnoreCase("Y"));
            } else if (type == ParameterType.DATE) {
                value = new JobParameter(rs.getTimestamp(5), rs.getString(8).equalsIgnoreCase("Y"));
            }

            // No need to assert that value is not null because it's an enum
            map.put(rs.getString(2), value);
        }
    };

    getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), new Object[] { executionId }, handler);

    return new JobParameters(map);
}

From source file:org.springframework.xd.rest.client.impl.support.JobParameterJacksonDeserializer.java

@Override
public JobParameter deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    final String value = node.get("value").asText();
    final boolean identifying = node.get("identifying").asBoolean();
    final String type = node.get("type").asText();

    final JobParameter jobParameter;

    if (!type.isEmpty() && !type.equalsIgnoreCase("STRING")) {
        if ("DATE".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(DateTime.parse(value).toDate(), identifying);
        } else if ("DOUBLE".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Double.valueOf(value), identifying);
        } else if ("LONG".equalsIgnoreCase(type)) {
            jobParameter = new JobParameter(Long.valueOf(value), identifying);
        } else {/* w w w .j a  va  2 s.c  o m*/
            throw new IllegalStateException("Unsupported JobParameter type: " + type);
        }
    } else {
        jobParameter = new JobParameter(value, identifying);
    }

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("jobParameter - value: %s (type: %s, isIdentifying: %s)",
                jobParameter.getValue(), jobParameter.getType().name(), jobParameter.isIdentifying()));
    }

    return jobParameter;
}