@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementer); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Override public List<String> getJobNames() { return getJdbcTemplate().query(getQuery(FIND_JOB_NAMES), new RowMapper<String>() { @Override public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(1); } }); }
/** * In this JDBC implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the next long value, and * then passing the Id and parameter values into an INSERT statement. * * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException * if any {@link JobParameters} fields are null. */ @Override public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = jobIncrementer.nextLongValue(); JobInstance jobInstance = new JobInstance(jobId, jobName); jobInstance.incrementVersion(); Object[] parameters = new Object[] { jobId, jobName, jobKeyGenerator.generateKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); return jobInstance; }
/** * In this jdbc implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the next long value, and * then passing the Id and parameter values into an INSERT statement. * * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException * if any {@link JobParameters} fields are null. */ public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = jobIncrementer.nextLongValue(); JobInstance jobInstance = new JobInstance(jobId, jobParameters, jobName); jobInstance.incrementVersion(); Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().getJdbcOperations().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); insertJobParameters(jobId, jobParameters); return jobInstance; }
/** * @see JdbcJobExecutionDao#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { setJobIncrementer(new AbstractDataFieldMaxValueIncrementer() { @Override protected long getNextKey() { return 0; } }); super.afterPropertiesSet(); }
Assert.notNull(jobParameters, "JobParameters must not be null."); String jobKey = createJobKey(jobParameters); instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_KEY), rowMapper, jobName, jobKey); } else { instances = getJdbcTemplate().query( getQuery(FIND_JOBS_WITH_EMPTY_KEY), rowMapper, jobName, jobKey);
@Before public void onSetUpBeforeTransaction() throws Exception { ((JdbcJobInstanceDao) jobInstanceDao).setTablePrefix(AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX); ((JdbcJobExecutionDao) jobExecutionDao).setTablePrefix(AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX); }
/** * @see JdbcJobExecutionDao#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { setJobIncrementer(new AbstractDataFieldMaxValueIncrementer() { @Override protected long getNextKey() { return 0; } }); super.afterPropertiesSet(); }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Override @Nullable public JobInstance getJobInstance(@Nullable Long instanceId) { try { return getJdbcTemplate().queryForObject(getQuery(GET_JOB_FROM_ID), new JobInstanceRowMapper(), instanceId); } catch (EmptyResultDataAccessException e) { return null; } }
/** * In this JDBC implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the next long value, and * then passing the Id and parameter values into an INSERT statement. * * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException * if any {@link JobParameters} fields are null. */ @Override public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = jobIncrementer.nextLongValue(); JobInstance jobInstance = new JobInstance(jobId, jobName); jobInstance.incrementVersion(); Object[] parameters = new Object[] { jobId, jobName, jobKeyGenerator.generateKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); return jobInstance; }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementer); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Override public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { try { return getJdbcTemplate().queryForObject( getQuery(COUNT_JOBS_WITH_NAME), Integer.class, jobName); } catch (EmptyResultDataAccessException e) { throw new NoSuchJobException("No job instances were found for job name " + jobName); } }
/** * In this JDBC implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the next long value, and * then passing the Id and parameter values into an INSERT statement. * * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException * if any {@link JobParameters} fields are null. */ @Override public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = jobIncrementer.nextLongValue(); JobInstance jobInstance = new JobInstance(jobId, jobName); jobInstance.incrementVersion(); Object[] parameters = new Object[] { jobId, jobName, jobKeyGenerator.generateKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); return jobInstance; }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcTemplate); dao.setJobIncrementer(incrementer); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Override public List<JobInstance> getJobInstances(String jobName, final int start, final int count) { ResultSetExtractor<List<JobInstance>> extractor = new ResultSetExtractor<List<JobInstance>>() { private List<JobInstance> list = new ArrayList<>(); @Override public List<JobInstance> extractData(ResultSet rs) throws SQLException, DataAccessException { int rowNum = 0; while (rowNum < start && rs.next()) { rowNum++; } while (rowNum < start + count && rs.next()) { RowMapper<JobInstance> rowMapper = new JobInstanceRowMapper(); list.add(rowMapper.mapRow(rs, rowNum)); rowNum++; } return list; } }; List<JobInstance> result = getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_BY_NAME), new Object[] { jobName }, extractor); return result; }
/** * In this JDBC implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the next long value, and * then passing the Id and parameter values into an INSERT statement. * * @see JobInstanceDao#createJobInstance(String, JobParameters) * @throws IllegalArgumentException * if any {@link JobParameters} fields are null. */ @Override public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); Long jobId = jobIncrementer.nextLongValue(); JobInstance jobInstance = new JobInstance(jobId, jobName); jobInstance.incrementVersion(); Object[] parameters = new Object[] { jobId, jobName, jobKeyGenerator.generateKey(jobParameters), jobInstance.getVersion() }; getJdbcTemplate().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); return jobInstance; }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementer); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }
@Override @Nullable public JobInstance getJobInstance(JobExecution jobExecution) { try { return getJdbcTemplate().queryForObject( getQuery(GET_JOB_FROM_EXECUTION_ID), new JobInstanceRowMapper(), jobExecution.getId()); } catch (EmptyResultDataAccessException e) { return null; } }
@Override protected JobInstanceDao createJobInstanceDao() throws Exception { JdbcJobInstanceDao dao = new JdbcJobInstanceDao(); dao.setJdbcTemplate(jdbcOperations); dao.setJobIncrementer(incrementer); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; }