@Override public Set<JobExecution> findRunningJobExecutions(String jobName) { final Set<JobExecution> result = new HashSet<>(); RowCallbackHandler handler = new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { JobExecutionRowMapper mapper = new JobExecutionRowMapper(); result.add(mapper.mapRow(rs, 0)); } }; getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); return result; }
/** * Convenience method that inserts an individual records into the * JobParameters table. */ private void insertParameter(Long executionId, ParameterType type, String key, Object value, boolean identifying) { Object[] args = new Object[0]; int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.BIGINT, Types.DOUBLE, Types.CHAR }; String identifyingFlag = identifying? "Y":"N"; if (type == ParameterType.STRING) { args = new Object[] { executionId, key, type, value, new Timestamp(0L), 0L, 0D, identifyingFlag}; } else if (type == ParameterType.LONG) { args = new Object[] { executionId, key, type, "", new Timestamp(0L), value, new Double(0), identifyingFlag}; } else if (type == ParameterType.DOUBLE) { args = new Object[] { executionId, key, type, "", new Timestamp(0L), 0L, value, identifyingFlag}; } else if (type == ParameterType.DATE) { args = new Object[] { executionId, key, type, "", value, 0L, 0D, identifyingFlag}; } getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); }
@Override public JobExecution getLastJobExecution(JobInstance jobInstance) { Long id = jobInstance.getId(); List<JobExecution> executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), new JobExecutionRowMapper(jobInstance), id, id); Assert.state(executions.size() <= 1, "There must be at most one latest job execution"); if (executions.isEmpty()) { return null; } else { return executions.get(0); } }
@Override @Nullable public JobExecution getJobExecution(Long executionId) { try { JobExecution jobExecution = getJdbcTemplate().queryForObject(getQuery(GET_EXECUTION_BY_ID), new JobExecutionRowMapper(), executionId); return jobExecution; } catch (EmptyResultDataAccessException e) { return null; } }
@Override public List<JobExecution> findJobExecutions(final JobInstance job) { Assert.notNull(job, "Job cannot be null."); Assert.notNull(job.getId(), "Job Id cannot be null."); return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), new JobExecutionRowMapper(job), job.getId()); }
/** * @param executionId {@link Long} containing the id for the execution. * @return job parameters for the requested execution id */ protected JobParameters getJobParameters(Long executionId) { final Map<String, JobParameter> map = new HashMap<>(); 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); }
@Override public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class, jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }
if (getJdbcTemplate().queryForObject(getQuery(CHECK_JOB_EXECUTION_EXISTS), Integer.class, new Object[] { jobExecution.getId() }) != 1) { throw new NoSuchObjectException("Invalid JobExecution, ID " + jobExecution.getId() + " not found."); int count = getJdbcTemplate().update( getQuery(UPDATE_JOB_EXECUTION), parameters, int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class, new Object[] { jobExecution.getId() }); throw new OptimisticLockingFailureException("Attempt to update job execution id="
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getJobConfigurationName() }; getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); }
@Override public Set<JobExecution> findRunningJobExecutions(String jobName) { final Set<JobExecution> result = new HashSet<JobExecution>(); RowCallbackHandler handler = new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { JobExecutionRowMapper mapper = new JobExecutionRowMapper(); result.add(mapper.mapRow(rs, 0)); } }; getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); return result; }
public JobExecution getLastJobExecution(JobInstance jobInstance) { Long id = jobInstance.getId(); List<JobExecution> executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), new JobExecutionRowMapper(jobInstance), id, id); Assert.state(executions.size() <= 1, "There must be at most one latest job execution"); if (executions.isEmpty()) { return null; } else { return executions.get(0); } }
@Override @Nullable public JobExecution getJobExecution(Long executionId) { try { JobExecution jobExecution = getJdbcTemplate().queryForObject(getQuery(GET_EXECUTION_BY_ID), new JobExecutionRowMapper(), executionId); return jobExecution; } catch (EmptyResultDataAccessException e) { return null; } }
public Set<JobExecution> findRunningJobExecutions(String jobName) { final Set<JobExecution> result = new HashSet<JobExecution>(); RowCallbackHandler handler = new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { JobExecutionRowMapper mapper = new JobExecutionRowMapper(); result.add(mapper.mapRow(rs, 0)); } }; getJdbcTemplate().getJdbcOperations() .query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); return result; }
@Override public List<JobExecution> findJobExecutions(final JobInstance job) { Assert.notNull(job, "Job cannot be null."); Assert.notNull(job.getId(), "Job Id cannot be null."); return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), new JobExecutionRowMapper(job), job.getId()); }
@Override public List<JobExecution> findJobExecutions(final JobInstance job) { Assert.notNull(job, "Job cannot be null."); Assert.notNull(job.getId(), "Job Id cannot be null."); return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), new JobExecutionRowMapper(job), job.getId()); }
public JobExecution getJobExecution(Long executionId) { try { JobExecution jobExecution = getJdbcTemplate().queryForObject(getQuery(GET_EXECUTION_BY_ID), new JobExecutionRowMapper(), executionId); return jobExecution; } catch (EmptyResultDataAccessException e) { return null; } }
public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_JOB_EXECUTION), jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }
@Override public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class, jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }
@Override public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class, jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }
@Override public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), Integer.class, jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }