Fix SqlJobDao for DefaultJobIdentifier
This commit is contained in:
@@ -26,6 +26,7 @@ import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobIdentifier;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
|
||||
import org.springframework.batch.execution.runtime.DefaultJobIdentifier;
|
||||
import org.springframework.batch.execution.runtime.ScheduledJobIdentifier;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -372,6 +373,10 @@ public class SqlJobDao implements JobDao, InitializingBean {
|
||||
if (jobIdentifier instanceof ScheduledJobIdentifier) {
|
||||
return (ScheduledJobIdentifier) jobIdentifier;
|
||||
}
|
||||
if (jobIdentifier instanceof DefaultJobIdentifier) {
|
||||
return new ScheduledJobIdentifier(jobIdentifier.getName(),
|
||||
((DefaultJobIdentifier) jobIdentifier).getJobKey());
|
||||
}
|
||||
return new ScheduledJobIdentifier(jobIdentifier.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,14 @@ public class DefaultJobIdentifier extends SimpleJobIdentifier implements
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name for the job
|
||||
*/
|
||||
public DefaultJobIdentifier(String name, String key) {
|
||||
this(name);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getJobKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,19 @@ public class ScheduledJobIdentifier extends DefaultJobIdentifier implements JobI
|
||||
|
||||
public ScheduledJobIdentifier(String name) {
|
||||
super(name);
|
||||
initDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param key
|
||||
*/
|
||||
public ScheduledJobIdentifier(String name, String key) {
|
||||
super(name, key);
|
||||
initDate();
|
||||
}
|
||||
|
||||
private void initDate() {
|
||||
try {
|
||||
scheduleDate = dateFormat.parse("19700101");
|
||||
} catch (ParseException e) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
|
||||
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
|
||||
import org.springframework.batch.execution.runtime.DefaultJobIdentifier;
|
||||
import org.springframework.batch.execution.runtime.ScheduledJobIdentifier;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -224,13 +225,26 @@ public abstract class AbstractJobDaoTests extends
|
||||
// Create job.
|
||||
job = jobDao.createJob(jobIdentifier);
|
||||
|
||||
// sessionFactory.getCurrentSession().flush();
|
||||
List jobs = jdbcTemplate.queryForList(
|
||||
"SELECT * FROM BATCH_JOB where ID=?", new Object[] { job
|
||||
.getId() });
|
||||
assertEquals(1, jobs.size());
|
||||
assertEquals(job.getName(), ((Map) jobs.get(0)).get("JOB_NAME"));
|
||||
|
||||
}
|
||||
|
||||
public void testJobWithDefaultJobIdentifier() throws Exception {
|
||||
DefaultJobIdentifier jobIdentifier = new DefaultJobIdentifier("Job1", "testKey");
|
||||
|
||||
// Create job.
|
||||
job = jobDao.createJob(jobIdentifier);
|
||||
|
||||
List jobs = jdbcTemplate.queryForList(
|
||||
"SELECT * FROM BATCH_JOB where ID=?", new Object[] { job
|
||||
.getId() });
|
||||
assertEquals(1, jobs.size());
|
||||
assertEquals(job.getName(), ((Map) jobs.get(0)).get("JOB_NAME"));
|
||||
assertEquals(jobIdentifier.getJobKey(), ((Map) jobs.get(0)).get("JOB_KEY"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user