diff --git a/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/JvmSystemExiter.java b/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/JvmSystemExiter.java index ab1505052..1993b2a91 100644 --- a/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/JvmSystemExiter.java +++ b/execution/src/main/java/org/springframework/batch/execution/bootstrap/support/JvmSystemExiter.java @@ -15,20 +15,22 @@ */ package org.springframework.batch.execution.bootstrap.support; - /** - * Implementation of the {@link SystemExiter} interface - * that calls the standards System.exit method. It should - * be noted that there will be no unit tests for this class, - * since there is only one line of actual code, that would only - * be testable by mocking System or Runtime. + * Implementation of the {@link SystemExiter} interface that calls the standards + * System.exit method. It should be noted that there will be no unit tests for + * this class, since there is only one line of actual code, that would only be + * testable by mocking System or Runtime. * * @author Lucas Ward - * + * @author Dave Syer + * */ public class JvmSystemExiter implements SystemExiter { - /* (non-Javadoc) + /** + * Delegate call to System.exit() with the argument provided. Do not use + * this at home children! + * * @see org.springframework.batch.execution.bootstrap.SystemExiter#exit(int) */ public void exit(int status) { diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptor.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptor.java index 6fd89e2c0..e597c3a1b 100644 --- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptor.java +++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptor.java @@ -1,12 +1,16 @@ package org.springframework.batch.execution.repository.dao; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import org.hibernate.EmptyInterceptor; import org.springframework.batch.core.domain.JobIdentifier; import org.springframework.batch.core.domain.JobInstance; +import org.springframework.batch.execution.runtime.DefaultJobIdentifier; import org.springframework.batch.execution.runtime.ScheduledJobIdentifier; import org.springframework.util.ClassUtils; @@ -25,11 +29,15 @@ import org.springframework.util.ClassUtils; public class EntityNameInterceptor extends EmptyInterceptor { private static final String SIMPLE_JOB_INSTANCE = "SimpleJobInstance"; - private Map identifierTypes = new HashMap(); + private Map identifierTypes; + private Set entrySet; - { - identifierTypes.put(ScheduledJobIdentifier.class, + public EntityNameInterceptor() { + Map types = new HashMap(); + types.put(ScheduledJobIdentifier.class, "ScheduledJobInstance"); + types.put(DefaultJobIdentifier.class, "DefaultJobInstance"); + setIdentifierTypes(types); }; /** @@ -45,6 +53,7 @@ public class EntityNameInterceptor extends EmptyInterceptor { * the identifierTypes to set */ public void setIdentifierTypes(Map types) { + this.identifierTypes = new HashMap(); for (Iterator iterator = types.entrySet().iterator(); iterator .hasNext();) { @@ -63,6 +72,10 @@ public class EntityNameInterceptor extends EmptyInterceptor { } } } + + this.entrySet = new TreeSet(new ClassComparator()); + entrySet.addAll(identifierTypes.keySet()); + } /** @@ -75,16 +88,38 @@ public class EntityNameInterceptor extends EmptyInterceptor { public String getEntityName(Object object) { if (object instanceof JobInstance) { JobInstance instance = (JobInstance) object; - for (Iterator iterator = identifierTypes.entrySet().iterator(); iterator - .hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); - Class key = (Class) entry.getKey(); + + for (Iterator iterator = entrySet.iterator(); iterator.hasNext();) { + Class key = (Class) iterator.next(); if (key.isAssignableFrom(instance.getIdentifier().getClass())) { - return (String) entry.getValue(); + return (String) identifierTypes.get(key); } } return SIMPLE_JOB_INSTANCE; } return super.getEntityName(object); } + + /** + * Comparator for classes to order by inheritance. + * + * @author Dave Syer + * + */ + private class ClassComparator implements Comparator { + /** + * @return 1 if arg0 is assignable from arg1 + * @return -1 otherwise + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(Object arg0, Object arg1) { + Class cls0 = (Class) arg0; + Class cls1 = (Class) arg1; + if (cls0.isAssignableFrom(cls1)) { + return 1; + } + return -1; + } + } + } diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java index 1a534d177..f14dd1a8b 100644 --- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java +++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java @@ -37,13 +37,12 @@ import org.springframework.util.StringUtils; /** * SQL implementation of {@link JobDao}. Uses sequences (via Spring's - * - * @link DataFieldMaxValueIncrementer abstraction) to create all primary keys - * before inserting a new row. Objects are checked to ensure all mandatory - * fields to be stored are not null. If any are found to be null, an - * IllegalArgumentException will be thrown. This could be left to - * JdbcTemplate, however, the exception will be fairly vague, and fails to - * highlight which field caused the exception. + * {@link DataFieldMaxValueIncrementer} abstraction) to create all primary keys + * before inserting a new row. Objects are checked to ensure all mandatory + * fields to be stored are not null. If any are found to be null, an + * IllegalArgumentException will be thrown. This could be left to JdbcTemplate, + * however, the exception will be fairly vague, and fails to highlight which + * field caused the exception. * * @author Lucas Ward * @author Dave Syer @@ -58,11 +57,11 @@ public class SqlJobDao implements JobDao, InitializingBean { private String tablePrefix = DEFAULT_TABLE_PREFIX; // Job SQL statements - private static final String CREATE_JOB = "INSERT into %PREFIX%JOB(ID, JOB_NAME, JOB_STREAM, SCHEDULE_DATE, JOB_RUN)" - + " values (?, ?, ?, ?, ?)"; + private static final String CREATE_JOB = "INSERT into %PREFIX%JOB(ID, JOB_NAME, JOB_KEY, SCHEDULE_DATE)" + + " values (?, ?, ?, ?)"; private static final String FIND_JOBS = "SELECT ID, STATUS from %PREFIX%JOB where JOB_NAME = ? and " - + "JOB_STREAM = ? and SCHEDULE_DATE = ? and JOB_RUN = ?"; + + "JOB_KEY = ? and SCHEDULE_DATE = ?"; private static final String UPDATE_JOB = "UPDATE %PREFIX%JOB set STATUS = ? where ID = ?"; @@ -99,12 +98,12 @@ public class SqlJobDao implements JobDao, InitializingBean { /** * In this sql implementation a job id is obtained by asking the * jobIncrementer (which is likely a sequence) for the nextLong, and then - * passing the Id and identifier values (job name, stream, run, schedule - * date) into an INSERT statement. + * passing the Id and identifier values (job name, jobKey, schedule date) + * into an INSERT statement. * * @see JobDao#createJob(JobIdentifier) * @throws IllegalArgumentException - * if any JobRuntimeInformation fields are null. + * if any {@link JobIdentifier} fields are null. */ public JobInstance createJob(JobIdentifier jobIdentifier) { @@ -114,8 +113,7 @@ public class SqlJobDao implements JobDao, InitializingBean { Long jobId = new Long(jobIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobId, defaultJobId.getName(), - defaultJobId.getJobStream(), defaultJobId.getScheduleDate(), - new Long(defaultJobId.getJobRun()) }; + defaultJobId.getJobKey(), defaultJobId.getScheduleDate() }; jdbcTemplate.update(getCreateJobQuery(), parameters); JobInstance job = new JobInstance(jobIdentifier, jobId); @@ -128,7 +126,7 @@ public class SqlJobDao implements JobDao, InitializingBean { * * @see JobDao#findJobs(JobIdentifier) * @throws IllegalArgumentException - * if any JobRuntimeInformation fields are null. + * if any {@link JobIdentifier} fields are null. */ public List findJobs(final JobIdentifier jobIdentifier) { @@ -137,8 +135,7 @@ public class SqlJobDao implements JobDao, InitializingBean { ScheduledJobIdentifier defaultJobId = getScheduledJobIdentifier(jobIdentifier); Object[] parameters = new Object[] { defaultJobId.getName(), - defaultJobId.getJobStream(), defaultJobId.getScheduleDate(), - new Integer(defaultJobId.getJobRun()) }; + defaultJobId.getJobKey(), defaultJobId.getScheduleDate() }; RowMapper rowMapper = new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { @@ -232,10 +229,11 @@ public class SqlJobDao implements JobDao, InitializingBean { + " not found."); } - jdbcTemplate.update(getUpdateJobExecutionQuery(), parameters, - new int[] { Types.TIMESTAMP, - Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, - Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); + jdbcTemplate + .update(getUpdateJobExecutionQuery(), parameters, + new int[] { Types.TIMESTAMP, Types.TIMESTAMP, + Types.VARCHAR, Types.CHAR, Types.VARCHAR, + Types.VARCHAR, Types.INTEGER }); } /** @@ -340,24 +338,24 @@ public class SqlJobDao implements JobDao, InitializingBean { "JobExecution status cannot be null."); } - /* - * Validate JobRuntimeInformation. Due to differing requirements, it is + /** + * Validate {@link JobIdentifier}. Due to differing requirements, it is * acceptable for any field to be blank, however null fields may cause odd * and vague exception reports from the database driver. */ private void validateJobIdentifier(JobIdentifier jobIdentifier) { - Assert.notNull(jobIdentifier, "JobRuntimeInformation cannot be null."); + Assert.notNull(jobIdentifier, "JobIdentifier cannot be null."); Assert.notNull(jobIdentifier.getName(), - "JobRuntimeInformation name cannot be null."); + "JobIdentifier name cannot be null."); if (jobIdentifier instanceof ScheduledJobIdentifier) { - ScheduledJobIdentifier jobRuntimeInformation = (ScheduledJobIdentifier) jobIdentifier; + ScheduledJobIdentifier identifier = (ScheduledJobIdentifier) jobIdentifier; - Assert.notNull(jobRuntimeInformation.getJobStream(), - "JobRuntimeInformation JobStream cannot be null."); - Assert.notNull(jobRuntimeInformation.getScheduleDate(), - "JobRuntimeInformation ScheduleDate cannot be null."); + Assert.notNull(identifier.getJobKey(), + "JobIdentifier JobKey cannot be null."); + Assert.notNull(identifier.getScheduleDate(), + "JobIdentifier ScheduleDate cannot be null."); } } diff --git a/execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGenerator.java b/execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGenerator.java index ed5d34960..cc3a5f311 100644 --- a/execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGenerator.java +++ b/execution/src/main/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGenerator.java @@ -51,8 +51,7 @@ public class DefaultJobIdentifierLabelGenerator implements } if (jobIdentifier instanceof ScheduledJobIdentifier) { ScheduledJobIdentifier id = (ScheduledJobIdentifier) jobIdentifier; - return jobIdentifier.getName() + "-" + id.getJobStream() + "-" - + id.getJobRun() + "-" + return jobIdentifier.getName() + "-" + id.getJobKey() + "-" + dateFormat.format(id.getScheduleDate()); } return jobIdentifier.getName(); diff --git a/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifier.java b/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifier.java new file mode 100644 index 000000000..8a430be55 --- /dev/null +++ b/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifier.java @@ -0,0 +1,77 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.execution.runtime; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.springframework.batch.core.domain.JobIdentifier; +import org.springframework.batch.core.runtime.SimpleJobIdentifier; + +/** + * @author Dave Syer + * + */ +public class DefaultJobIdentifier extends SimpleJobIdentifier implements + JobIdentifier { + + private String key = ""; + + /** + * Default constructor package access only. + */ + DefaultJobIdentifier() { + this(null); + } + + /** + * @param name the name for the job + */ + public DefaultJobIdentifier(String name) { + super(name); + } + + public String getJobKey() { + return key; + } + + public void setJobKey(String key) { + this.key = key; + } + + + /** + * Adds the key data to the base class. + * + * @see org.springframework.batch.core.runtime.SimpleJobIdentifier#toString() + */ + public String toString() { + return super.toString() + ",key=" + key; + } + + /** + * Returns true if the provided JobIdentifier equals this JobIdentifier. Two + * Identifiers are considered to be equal if they have the same name, + * stream, run, and schedule date. + */ + public boolean equals(Object other) { + return EqualsBuilder.reflectionEquals(this, other) || EqualsBuilder.reflectionEquals(other, this); + } + + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + +} diff --git a/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactory.java b/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactory.java new file mode 100644 index 000000000..97c939080 --- /dev/null +++ b/execution/src/main/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactory.java @@ -0,0 +1,44 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.execution.runtime; + +import org.springframework.batch.core.domain.JobIdentifier; +import org.springframework.batch.core.runtime.JobIdentifierFactory; + +/** + * {@link JobIdentifierFactory} for creating {@link DefaultJobIdentifierFactory} + * instances. + * + * @author Dave Syer + * + */ +public class DefaultJobIdentifierFactory implements JobIdentifierFactory { + + protected String key = "key"; + + public JobIdentifier getJobIdentifier(String name) { + + DefaultJobIdentifier runtimeInformation = new DefaultJobIdentifier(name); + runtimeInformation.setJobKey(key); + return runtimeInformation; + } + + public void setJobKey(String key) { + this.key = key; + } + +} diff --git a/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifier.java b/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifier.java index 6f24fadd5..72faf7e53 100644 --- a/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifier.java +++ b/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifier.java @@ -24,18 +24,13 @@ import java.util.Date; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.springframework.batch.core.domain.JobIdentifier; -import org.springframework.batch.core.runtime.SimpleJobIdentifier; -public class ScheduledJobIdentifier extends SimpleJobIdentifier implements JobIdentifier { +public class ScheduledJobIdentifier extends DefaultJobIdentifier implements JobIdentifier { private static final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); private Date scheduleDate; - private int jobRun = 0; - - private String jobStream = ""; - ScheduledJobIdentifier() { this(null); } @@ -49,22 +44,6 @@ public class ScheduledJobIdentifier extends SimpleJobIdentifier implements JobId } } - public int getJobRun() { - return jobRun; - } - - public void setJobRun(int jobRun) { - this.jobRun = jobRun; - } - - public String getJobStream() { - return jobStream; - } - - public void setJobStream(String jobStream) { - this.jobStream = jobStream; - } - public Date getScheduleDate() { return scheduleDate; } @@ -74,7 +53,7 @@ public class ScheduledJobIdentifier extends SimpleJobIdentifier implements JobId } public String toString() { - return super.toString() + ",stream=" + jobStream + ",run=" + jobRun + ",scheduleDate=" + return super.toString() + ",scheduleDate=" + scheduleDate; } diff --git a/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactory.java b/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactory.java index 413289f99..dfa49acad 100644 --- a/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactory.java +++ b/execution/src/main/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactory.java @@ -28,29 +28,16 @@ import org.springframework.batch.core.runtime.JobIdentifierFactory; * @author Dave Syer * */ -public class ScheduledJobIdentifierFactory implements JobIdentifierFactory { - - private String jobStream = "stream"; - - private int jobRun = 0; +public class ScheduledJobIdentifierFactory extends DefaultJobIdentifierFactory implements JobIdentifierFactory { private Date scheduleDate = new Date(); public JobIdentifier getJobIdentifier(String name) { - ScheduledJobIdentifier runtimeInformation = new ScheduledJobIdentifier(name); - runtimeInformation.setJobStream(jobStream); - runtimeInformation.setJobRun(jobRun); - runtimeInformation.setScheduleDate(scheduleDate); - return runtimeInformation; - } - - public void setJobRun(int jobRun) { - this.jobRun = jobRun; - } - - public void setJobStream(String jobStream) { - this.jobStream = jobStream; + ScheduledJobIdentifier identifier = new ScheduledJobIdentifier(name); + identifier.setJobKey(key); + identifier.setScheduleDate(scheduleDate); + return identifier; } public void setScheduleDate(Date scheduleDate) { diff --git a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/JobInstance.hbm.xml b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/JobInstance.hbm.xml index 08e40599c..d9b6e2491 100644 --- a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/JobInstance.hbm.xml +++ b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/JobInstance.hbm.xml @@ -28,11 +28,20 @@ - + - + + + + + + + diff --git a/execution/src/main/resources/schema-db2.sql b/execution/src/main/resources/schema-db2.sql index 4a819ad9c..91e403b03 100644 --- a/execution/src/main/resources/schema-db2.sql +++ b/execution/src/main/resources/schema-db2.sql @@ -14,9 +14,8 @@ CREATE TABLE BATCH_JOB ( ID BIGINT PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/main/resources/schema-derby.sql b/execution/src/main/resources/schema-derby.sql index 90f6a7000..e51484528 100644 --- a/execution/src/main/resources/schema-derby.sql +++ b/execution/src/main/resources/schema-derby.sql @@ -14,9 +14,8 @@ CREATE TABLE BATCH_JOB ( ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/main/resources/schema-hsqldb.sql b/execution/src/main/resources/schema-hsqldb.sql index 039b235b1..9015aa9fc 100644 --- a/execution/src/main/resources/schema-hsqldb.sql +++ b/execution/src/main/resources/schema-hsqldb.sql @@ -14,9 +14,8 @@ CREATE TABLE BATCH_JOB ( ID BIGINT IDENTITY PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/main/resources/schema-oracle10g.sql b/execution/src/main/resources/schema-oracle10g.sql index 1d9c6ef11..6d0669770 100644 --- a/execution/src/main/resources/schema-oracle10g.sql +++ b/execution/src/main/resources/schema-oracle10g.sql @@ -14,9 +14,8 @@ CREATE TABLE BATCH_JOB ( ID NUMBER(38) PRIMARY KEY , VERSION NUMBER(38), JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/main/resources/schema-postgresql.sql b/execution/src/main/resources/schema-postgresql.sql index 4a819ad9c..91e403b03 100644 --- a/execution/src/main/resources/schema-postgresql.sql +++ b/execution/src/main/resources/schema-postgresql.sql @@ -14,9 +14,8 @@ CREATE TABLE BATCH_JOB ( ID BIGINT PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/main/sql/init.sql.vpp b/execution/src/main/sql/init.sql.vpp index 31e5ce40f..6f0e7ac3d 100644 --- a/execution/src/main/sql/init.sql.vpp +++ b/execution/src/main/sql/init.sql.vpp @@ -3,9 +3,8 @@ CREATE TABLE BATCH_JOB ( ID ${BIGINT} $!{IDENTITY} PRIMARY KEY $!{GENERATED}, VERSION ${BIGINT}, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java index 6f4ca5c62..a58e7d201 100644 --- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java @@ -65,8 +65,7 @@ public abstract class AbstractJobDaoTests extends protected void onSetUpInTransaction() throws Exception { jobRuntimeInformation = new ScheduledJobIdentifier("Job1"); jobRuntimeInformation.setName("Job1"); - jobRuntimeInformation.setJobStream("TestStream"); - jobRuntimeInformation.setJobRun(1); + jobRuntimeInformation.setJobKey("TestStream"); jobRuntimeInformation.setScheduleDate(new SimpleDateFormat("yyyyMMdd") .parse("20070505")); diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptorTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptorTests.java index 9be98c1e6..739826815 100644 --- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/EntityNameInterceptorTests.java @@ -2,12 +2,13 @@ package org.springframework.batch.execution.repository.dao; import java.util.Collections; +import junit.framework.TestCase; + import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.runtime.SimpleJobIdentifier; +import org.springframework.batch.execution.runtime.DefaultJobIdentifier; import org.springframework.batch.execution.runtime.ScheduledJobIdentifier; -import junit.framework.TestCase; - public class EntityNameInterceptorTests extends TestCase { private EntityNameInterceptor interceptor = new EntityNameInterceptor(); @@ -17,6 +18,11 @@ public class EntityNameInterceptorTests extends TestCase { assertEquals("ScheduledJobInstance", interceptor.getEntityName(job)); } + public void testGetEntityNameForDefaultJobIdentifier() { + JobInstance job = new JobInstance(new DefaultJobIdentifier("foo")); + assertEquals("DefaultJobInstance", interceptor.getEntityName(job)); + } + public void testGetEntityNameForSimpleJobIdentifier() { JobInstance job = new JobInstance(new SimpleJobIdentifier("foo")); assertEquals("SimpleJobInstance", interceptor.getEntityName(job)); diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateJobDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateJobDaoTests.java index 1c9c4e636..4a10764a8 100644 --- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateJobDaoTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateJobDaoTests.java @@ -94,8 +94,7 @@ public class HibernateJobDaoTests extends AbstractJobDaoTests { public void testNullScheduleDate(){ ScheduledJobIdentifier scheduledIdentifier = new ScheduledJobIdentifier("ScheduledJob"); - scheduledIdentifier.setJobRun(0); - scheduledIdentifier.setJobStream(null); + scheduledIdentifier.setJobKey(null); try{ jobDao.createJob(scheduledIdentifier); diff --git a/execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java b/execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java index 6f139dcf8..01ed9cdef 100644 --- a/execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java @@ -69,8 +69,7 @@ public class BatchResourceFactoryBeanTests extends TestCase { // define mock behaviour identifier.setScheduleDate(new SimpleDateFormat("yyyyMMdd") .parse("20070730")); - identifier.setJobStream("testStream"); - identifier.setJobRun(11); + identifier.setJobKey("testStream"); SimpleStepContext context = new SimpleStepContext(); JobInstance job = new JobInstance(identifier); @@ -97,7 +96,7 @@ public class BatchResourceFactoryBeanTests extends TestCase { * regular use with valid context and pattern provided */ public void testCreateFileName() throws Exception { - doTestPathName("testJob-testStream-11-20070730-bar.txt", path); + doTestPathName("testJob-testStream-20070730-bar.txt", path); } /** @@ -130,7 +129,7 @@ public class BatchResourceFactoryBeanTests extends TestCase { public void testNonStandardFilePattern() throws Exception { resourceFactory.setFilePattern("/%BATCH_ROOT%/data/%JOB_NAME%/" + "%STEP_NAME%+%JOB_IDENTIFIER%"); - doTestPathName("bar+testJob-testStream-11-20070730", path); + doTestPathName("bar+testJob-testStream-20070730", path); } public void testResoureLoaderAware() throws Exception { @@ -150,14 +149,14 @@ public class BatchResourceFactoryBeanTests extends TestCase { String rootDir = getRootDir(); rootDir = StringUtils.replace(rootDir, File.separator, "/") + "/"; resourceFactory.setRootDirectory(rootDir); - doTestPathName("testJob-testStream-11-20070730-bar.txt", path); + doTestPathName("testJob-testStream-20070730-bar.txt", path); } public void testRootDirectoryEndsWithBackSlash() throws Exception { String rootDir = getRootDir(); rootDir = "/"+StringUtils.replace(rootDir, File.separator, "\\") + "\\"; resourceFactory.setRootDirectory(rootDir); - doTestPathName("testJob-testStream-11-20070730-bar.txt", path); + doTestPathName("testJob-testStream-20070730-bar.txt", path); } private void doTestPathName(String filename, String path) throws Exception, IOException { diff --git a/execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGeneratorTests.java b/execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGeneratorTests.java index 46bac6bbb..259b32019 100644 --- a/execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGeneratorTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/resource/DefaultJobIdentifierLabelGeneratorTests.java @@ -30,7 +30,7 @@ public class DefaultJobIdentifierLabelGeneratorTests extends TestCase { * Test method for {@link org.springframework.batch.execution.resource.DefaultJobIdentifierLabelGenerator#getLabel()}. */ public void testDefaultGetLabel() throws Exception { - assertEquals("null--0-19700101", instance.getLabel(new ScheduledJobIdentifier(null))); + assertEquals("null--19700101", instance.getLabel(new ScheduledJobIdentifier(null))); } /** @@ -39,10 +39,9 @@ public class DefaultJobIdentifierLabelGeneratorTests extends TestCase { public void testGetLabelWithAllProperties() throws Exception { ScheduledJobIdentifier identifier = new ScheduledJobIdentifier(null); identifier.setName("foo"); - identifier.setJobStream("bar"); - identifier.setJobRun(11); + identifier.setJobKey("bar"); identifier.setScheduleDate(new SimpleDateFormat("yyyyMMdd").parse("20070730")); - assertEquals("foo-bar-11-20070730", instance.getLabel(identifier)); + assertEquals("foo-bar-20070730", instance.getLabel(identifier)); } } diff --git a/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactoryTests.java b/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactoryTests.java new file mode 100644 index 000000000..07dd5ed6b --- /dev/null +++ b/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierFactoryTests.java @@ -0,0 +1,14 @@ +package org.springframework.batch.execution.runtime; + +import junit.framework.TestCase; + +import org.springframework.batch.core.domain.JobIdentifier; + +public class DefaultJobIdentifierFactoryTests extends TestCase { + + public void testGetJobIdentifier() { + JobIdentifier jobIdentifier = new ScheduledJobIdentifierFactory().getJobIdentifier("foo"); + assertEquals("foo", jobIdentifier.getName()); + } + +} diff --git a/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierTests.java b/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierTests.java new file mode 100644 index 000000000..260df3d60 --- /dev/null +++ b/execution/src/test/java/org/springframework/batch/execution/runtime/DefaultJobIdentifierTests.java @@ -0,0 +1,83 @@ +/* + * Copyright 2006-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.execution.runtime; + +import junit.framework.TestCase; + +/** + * @author Dave Syer + * + */ +public class DefaultJobIdentifierTests extends TestCase { + + private DefaultJobIdentifier instance = new DefaultJobIdentifier(null); + + /** + * Test method for {@link org.springframework.batch.core.domain.JobInstance#getName()}. + */ + public void testDefaultConstructor() { + instance = new DefaultJobIdentifier(); + assertEquals(null, instance.getName()); + instance.setName("foo"); + assertEquals("foo", instance.getName()); + } + + /** + * Test method for {@link org.springframework.batch.core.domain.JobInstance#getName()}. + */ + public void testGetName() { + assertEquals(null, instance.getName()); + instance.setName("foo"); + assertEquals("foo", instance.getName()); + } + + /** + * Test method for {@link org.springframework.batch.core.domain.JobInstance#getJobKey()}. + */ + public void testGetJobStream() { + assertEquals("", instance.getJobKey()); + instance.setJobKey("foo"); + assertEquals("foo", instance.getJobKey()); + } + + + public void testEqualsSelf() throws Exception { + assertEquals(instance, instance); + } + + public void testEqualsInstanceWithSameProperties() throws Exception { + DefaultJobIdentifier other = new DefaultJobIdentifier(instance.getName()); + other.setJobKey(instance.getJobKey()); + assertEquals(instance, other); + assertEquals(instance.hashCode(), other.hashCode()); + } + + public void testEqualsInstanceWithTimestamp() throws Exception { + DefaultJobIdentifier other = new DefaultJobIdentifier(instance.getName()); + other.setJobKey(instance.getJobKey()); + assertEquals(instance, other); + assertEquals(other, instance); + assertEquals(instance.hashCode(), other.hashCode()); + } + + public void testEqualsNull() throws Exception { + assertNotSame(null, instance); + } + + public void testToString() throws Exception { + assertTrue("String does not contain key: "+instance, instance.toString().indexOf("key=")>=0); + } +} diff --git a/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactoryTests.java b/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactoryTests.java new file mode 100644 index 000000000..dddb04595 --- /dev/null +++ b/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierFactoryTests.java @@ -0,0 +1,14 @@ +package org.springframework.batch.execution.runtime; + +import junit.framework.TestCase; + +import org.springframework.batch.core.domain.JobIdentifier; + +public class ScheduledJobIdentifierFactoryTests extends TestCase { + + public void testGetJobIdentifier() { + JobIdentifier jobIdentifier = new DefaultJobIdentifierFactory().getJobIdentifier("foo"); + assertEquals("foo", jobIdentifier.getName()); + } + +} diff --git a/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java b/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java index e54843366..9171b8126 100644 --- a/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/runtime/ScheduledJobIdentifierTests.java @@ -28,6 +28,16 @@ public class ScheduledJobIdentifierTests extends TestCase { private ScheduledJobIdentifier instance = new ScheduledJobIdentifier(null); + /** + * Test method for {@link org.springframework.batch.core.domain.JobInstance#getName()}. + */ + public void testDefaultConstructor() { + instance = new ScheduledJobIdentifier(); + assertEquals(null, instance.getName()); + instance.setName("foo"); + assertEquals("foo", instance.getName()); + } + /** * Test method for {@link org.springframework.batch.core.domain.JobInstance#getName()}. */ @@ -38,12 +48,12 @@ public class ScheduledJobIdentifierTests extends TestCase { } /** - * Test method for {@link org.springframework.batch.core.domain.JobInstance#getJobStream()}. + * Test method for {@link org.springframework.batch.core.domain.JobInstance#getJobKey()}. */ public void testGetJobStream() { - assertEquals("", instance.getJobStream()); - instance.setJobStream("foo"); - assertEquals("foo", instance.getJobStream()); + assertEquals("", instance.getJobKey()); + instance.setJobKey("foo"); + assertEquals("foo", instance.getJobKey()); } /** @@ -54,15 +64,6 @@ public class ScheduledJobIdentifierTests extends TestCase { instance.setScheduleDate(new Date(100L)); assertEquals(100L, instance.getScheduleDate().getTime()); } - - /** - * Test method for {@link org.springframework.batch.core.domain.JobInstance#getJobRun()}. - */ - public void testGetJobRun() { - assertEquals(0, instance.getJobRun()); - instance.setJobRun(1); - assertEquals(1, instance.getJobRun()); - } public void testEqualsSelf() throws Exception { assertEquals(instance, instance); @@ -70,8 +71,7 @@ public class ScheduledJobIdentifierTests extends TestCase { public void testEqualsInstanceWithSameProperties() throws Exception { ScheduledJobIdentifier other = new ScheduledJobIdentifier(instance.getName()); - other.setJobRun(instance.getJobRun()); - other.setJobStream(instance.getJobStream()); + other.setJobKey(instance.getJobKey()); other.setScheduleDate(instance.getScheduleDate()); assertEquals(instance, other); assertEquals(instance.hashCode(), other.hashCode()); @@ -79,8 +79,7 @@ public class ScheduledJobIdentifierTests extends TestCase { public void testEqualsInstanceWithTimestamp() throws Exception { ScheduledJobIdentifier other = new ScheduledJobIdentifier(instance.getName()); - other.setJobRun(instance.getJobRun()); - other.setJobStream(instance.getJobStream()); + other.setJobKey(instance.getJobKey()); other.setScheduleDate(new Timestamp(instance.getScheduleDate().getTime())); assertEquals(instance, other); assertEquals(other, instance); @@ -90,4 +89,9 @@ public class ScheduledJobIdentifierTests extends TestCase { public void testEqualsNull() throws Exception { assertNotSame(null, instance); } + + public void testToString() throws Exception { + assertTrue("String does not contain key: "+instance, instance.toString().indexOf("key=")>=0); + assertTrue("String does not contain date: "+instance, instance.toString().indexOf("scheduleDate=")>=0); + } } diff --git a/execution/src/test/java/org/springframework/batch/execution/scope/StepScopeTests.java b/execution/src/test/java/org/springframework/batch/execution/scope/StepScopeTests.java index 405e032b2..9f533dd66 100644 --- a/execution/src/test/java/org/springframework/batch/execution/scope/StepScopeTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/scope/StepScopeTests.java @@ -20,12 +20,10 @@ import java.util.List; import junit.framework.TestCase; -import org.springframework.batch.execution.scope.StepScope; -import org.springframework.batch.execution.scope.SimpleStepContext; -import org.springframework.batch.execution.scope.StepSynchronizationManager; import org.springframework.batch.repeat.synch.RepeatSynchronizationManager; import org.springframework.beans.BeansException; import org.springframework.beans.factory.ObjectFactory; +import org.springframework.context.support.StaticApplicationContext; /** * @author Dave Syer @@ -188,5 +186,20 @@ public class StepScopeTests extends TestCase { scope.remove("foo"); assertFalse(context.hasAttribute("foo")); } + + public void testOrder() throws Exception { + assertEquals(Integer.MAX_VALUE, scope.getOrder()); + scope.setOrder(11); + assertEquals(11, scope.getOrder()); + } + + public void testName() throws Exception { + scope.setName("foo"); + StaticApplicationContext beanFactory = new StaticApplicationContext(); + scope.postProcessBeanFactory(beanFactory.getDefaultListableBeanFactory()); + String[] scopes = beanFactory.getDefaultListableBeanFactory().getRegisteredScopeNames(); + assertEquals(1, scopes.length); + assertEquals("foo", scopes[0]); + } } diff --git a/execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql b/execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql index 90d3debc4..1112442ef 100644 --- a/execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql +++ b/execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql @@ -3,9 +3,8 @@ CREATE TABLE BATCH_JOB ( ID BIGINT IDENTITY PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_STREAM VARCHAR(20) , + JOB_KEY VARCHAR(20) , SCHEDULE_DATE DATE , - JOB_RUN CHAR(2), STATUS VARCHAR(10) ); CREATE TABLE BATCH_JOB_EXECUTION ( diff --git a/execution/src/test/resources/simple-container-definition.xml b/execution/src/test/resources/simple-container-definition.xml index cabde13e3..de31bda04 100644 --- a/execution/src/test/resources/simple-container-definition.xml +++ b/execution/src/test/resources/simple-container-definition.xml @@ -79,9 +79,8 @@ - + - - + -