/** * 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; }
@Transactional @Test public void testCreationAddsVersion() { JobInstance jobInstance = new JobInstance((long) 1, "testVersionAndId"); assertNull(jobInstance.getVersion()); jobInstance = dao.createJobInstance("testVersion", new JobParameters()); assertNotNull(jobInstance.getVersion()); }
@Transactional @Test public void testCreationAddsVersion() { jobInstance = jobInstanceDao.createJobInstance("testCreationAddsVersion", new JobParameters()); assertNotNull(jobInstance.getVersion()); }
/** * Create and retrieve a job instance. */ @Transactional @Test public void testGetLastInstances() throws Exception { testCreateAndRetrieve(); // unrelated job instance that should be ignored by the query dao.createJobInstance("anotherJob", new JobParameters()); // we need two instances of the same job to check ordering dao.createJobInstance(fooJob, new JobParameters()); List<JobInstance> jobInstances = dao.getJobInstances(fooJob, 0, 2); assertEquals(2, jobInstances.size()); assertEquals(fooJob, jobInstances.get(0).getJobName()); assertEquals(fooJob, jobInstances.get(1).getJobName()); assertEquals(Integer.valueOf(0), jobInstances.get(0).getVersion()); assertEquals(Integer.valueOf(0), jobInstances.get(1).getVersion()); assertTrue("Last instance should be first on the list", jobInstances.get(0).getId() > jobInstances.get(1) .getId()); }
/** * Create and retrieve a job instance. */ @Transactional @Test public void testGetLastInstancesPaged() throws Exception { testCreateAndRetrieve(); // unrelated job instance that should be ignored by the query dao.createJobInstance("anotherJob", new JobParameters()); // we need multiple instances of the same job to check ordering String multiInstanceJob = "multiInstanceJob"; String paramKey = "myID"; int instanceCount = 6; for (int i = 1; i <= instanceCount; i++) { JobParameters params = new JobParametersBuilder().addLong(paramKey, Long.valueOf(i)).toJobParameters(); dao.createJobInstance(multiInstanceJob, params); } int startIndex = 3; int queryCount = 2; List<JobInstance> jobInstances = dao.getJobInstances(multiInstanceJob, startIndex, queryCount); assertEquals(queryCount, jobInstances.size()); for (int i = 0; i < queryCount; i++) { JobInstance returnedInstance = jobInstances.get(i); assertEquals(multiInstanceJob, returnedInstance.getJobName()); assertEquals(Integer.valueOf(0), returnedInstance.getVersion()); //checks the correct instances are returned and the order is descending // assertEquals(instanceCount - startIndex - i , returnedInstance.getJobParameters().getLong(paramKey)); } }
public AdaptedJobInstance(JobInstance jobInstance) { this.id = jobInstance.getId(); if (jobInstance.getVersion() == null) { jobInstance.setVersion(0); } else { this.setVersion(jobInstance.getVersion()); } this.jobName = jobInstance.getJobName(); }
public static JobInstance map(final org.springframework.batch.core.JobInstance jobInstance) { final JobInstance response = new JobInstance(); if (jobInstance != null) { response.setVersion(jobInstance.getVersion()); response.setId(jobInstance.getInstanceId()); response.setJobName(jobInstance.getJobName()); } else { log.info("JobInstance was null, nothing to map"); } return response; }
public static JobInstance map(final org.springframework.batch.core.JobInstance jobInstance) { final JobInstance response = new JobInstance(); if (jobInstance != null) { response.setVersion(jobInstance.getVersion()); response.setId(jobInstance.getInstanceId()); response.setJobName(jobInstance.getJobName()); } else { log.info("JobInstance was null, nothing to map"); } return response; }
/** * 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. */ @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. */ @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. */ @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; }