From b788ad462cba4e4b356129878a88ee4b24ea46da Mon Sep 17 00:00:00 2001 From: lucasward Date: Wed, 19 Dec 2007 16:56:31 +0000 Subject: [PATCH] BATCH-217:Modified class names to Jdbc* from Sql* --- .../dao/{SqlJobDao.java => JdbcJobDao.java} | 4 +- .../dao/{SqlStepDao.java => JdbcStepDao.java} | 226 ++++++++++-------- ...ryTests.java => JdbcJobDaoQueryTests.java} | 8 +- ...lJobDaoTests.java => JdbcJobDaoTests.java} | 4 +- ...Tests.java => JdbcStepDaoPrefixTests.java} | 41 +--- ...tepDaoTests.java => JdbcStepDaoTests.java} | 10 +- .../execution/repository/dao/sql-dao-test.xml | 4 +- 7 files changed, 143 insertions(+), 154 deletions(-) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/{SqlJobDao.java => JdbcJobDao.java} (99%) rename spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/{SqlStepDao.java => JdbcStepDao.java} (65%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/{SqlJobDaoQueryTests.java => JdbcJobDaoQueryTests.java} (90%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/{SqlJobDaoTests.java => JdbcJobDaoTests.java} (87%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/{SqlStepDaoPrefixTests.java => JdbcStepDaoPrefixTests.java} (81%) rename spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/{SqlStepDaoTests.java => JdbcStepDaoTests.java} (76%) diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobDao.java similarity index 99% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobDao.java index 54d056d58..808a2e536 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobDao.java @@ -50,7 +50,7 @@ import org.springframework.util.StringUtils; * @author Lucas Ward * @author Dave Syer */ -public class SqlJobDao implements JobDao, InitializingBean { +public class JdbcJobDao implements JobDao, InitializingBean { private static final String CHECK_JOB_EXECUTION_EXISTS = "SELECT COUNT(*) FROM %PREFIX%JOB_EXECUTION WHERE ID=?"; @@ -71,7 +71,7 @@ public class SqlJobDao implements JobDao, InitializingBean { private static final String GET_JOB_EXECUTION_COUNT = "SELECT count(ID) from %PREFIX%JOB_EXECUTION " + "where JOB_ID = ?"; - protected static final Log logger = LogFactory.getLog(SqlJobDao.class); + protected static final Log logger = LogFactory.getLog(JdbcJobDao.class); private static final String SAVE_JOB_EXECUTION = "INSERT into %PREFIX%JOB_EXECUTION(ID, JOB_ID, START_TIME, " + "END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE) values (?, ?, ?, ?, ?, ?, ?, ?)"; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java similarity index 65% rename from spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java rename to spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java index 5d7b56f39..1606de65b 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java @@ -20,6 +20,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import java.util.List; +import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,14 +29,13 @@ import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; -import org.springframework.batch.execution.repository.dao.SqlJobDao.JobExecutionRowMapper; +import org.springframework.batch.execution.repository.dao.JdbcJobDao.JobExecutionRowMapper; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.batch.support.PropertiesConverter; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.IncorrectResultSizeDataAccessException; -import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; @@ -46,11 +46,11 @@ import org.springframework.util.StringUtils; * Sql implementation of {@link StepDao}. Uses Sequences (via Spring's * * @link DataFieldMaxValueIncrementer abstraction) to create all Step and - * StepExecution primary keys before inserting a new row. All objects are - * checked to ensure all 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. + * StepExecution primary keys before inserting a new row. All objects are + * checked to ensure all 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. * * TODO: JavaDoc should be geared more towards usability, the comments above are * useful information, and should be there, but needs usability stuff. Depends @@ -60,14 +60,12 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @see StepDao */ -public class SqlStepDao implements StepDao, InitializingBean { +public class JdbcStepDao implements StepDao, InitializingBean { private static final String CREATE_STEP = "INSERT into %PREFIX%STEP(ID, JOB_ID, STEP_NAME) values (?, ?, ?)"; private static final int EXIT_MESSAGE_LENGTH = 250; - private static final int RESTART_DATA_LENGTH = 1000; - private static final String FIND_STEP = "SELECT ID, STATUS, RESTART_DATA from %PREFIX%STEP where JOB_ID = ? " + "and STEP_NAME = ?"; @@ -80,7 +78,7 @@ public class SqlStepDao implements StepDao, InitializingBean { private static final String GET_STEP_EXECUTION_COUNT = "SELECT count(ID) from %PREFIX%STEP_EXECUTION where " + "STEP_ID = ?"; - protected static final Log logger = LogFactory.getLog(SqlStepDao.class); + protected static final Log logger = LogFactory.getLog(JdbcStepDao.class); // StepExecution statements private static final String SAVE_STEP_EXECUTION = "INSERT into %PREFIX%STEP_EXECUTION(ID, VERSION, STEP_ID, JOB_EXECUTION_ID, START_TIME, " @@ -91,7 +89,7 @@ public class SqlStepDao implements StepDao, InitializingBean { private static final String UPDATE_STEP_EXECUTION = "UPDATE %PREFIX%STEP_EXECUTION set START_TIME = ?, END_TIME = ?, " + "STATUS = ?, COMMIT_COUNT = ?, TASK_COUNT = ?, TASK_STATISTICS = ?, CONTINUABLE = ? , EXIT_CODE = ?, " - + "EXIT_MESSAGE = ?, VERSION=? where ID = ? and VERSION = ?"; + + "EXIT_MESSAGE = ? where ID = ?"; private JdbcOperations jdbcTemplate; @@ -101,12 +99,13 @@ public class SqlStepDao implements StepDao, InitializingBean { private DataFieldMaxValueIncrementer stepIncrementer; - private String tablePrefix = SqlJobDao.DEFAULT_TABLE_PREFIX; + private String tablePrefix = JdbcJobDao.DEFAULT_TABLE_PREFIX; public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcTemplate, "JdbcTemplate cannot be null."); Assert.notNull(stepIncrementer, "StepIncrementer cannot be null."); - Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer canot be null."); + Assert.notNull(stepExecutionIncrementer, + "StepExecutionIncrementer canot be null."); } private void cascadeJobExecution(JobExecution jobExecution) { @@ -123,7 +122,8 @@ public class SqlStepDao implements StepDao, InitializingBean { * DataFieldMaxValueIncrementer) * * @see StepDao#createStep(JobInstance, String) - * @throws IllegalArgumentException if job or stepName is null. + * @throws IllegalArgumentException + * if job or stepName is null. */ public StepInstance createStep(JobInstance job, String stepName) { @@ -145,9 +145,10 @@ public class SqlStepDao implements StepDao, InitializingBean { * anymore than one step is found, an exception is thrown. * * @see StepDao#findStep(Long, String) - * @throws IllegalArgumentException if job, stepName, or job.id is null. - * @throws IncorrectResultSizeDataAccessException if more than one step is - * found. + * @throws IllegalArgumentException + * if job, stepName, or job.id is null. + * @throws IncorrectResultSizeDataAccessException + * if more than one step is found. */ public StepInstance findStep(JobInstance job, String stepName) { @@ -163,28 +164,30 @@ public class SqlStepDao implements StepDao, InitializingBean { StepInstance step = new StepInstance(new Long(rs.getLong(1))); step.setStatus(BatchStatus.getStatus(rs.getString(2))); - step.setRestartData(new GenericRestartData(PropertiesConverter.stringToProperties(rs.getString(3)))); + step.setRestartData(new GenericRestartData(PropertiesConverter + .stringToProperties(rs.getString(3)))); return step; } }; - List steps = jdbcTemplate.query(getFindStepQuery(), parameters, rowMapper); + List steps = jdbcTemplate.query(getFindStepQuery(), parameters, + rowMapper); if (steps.size() == 0) { // No step found return null; - } - else if (steps.size() == 1) { + } else if (steps.size() == 1) { StepInstance step = (StepInstance) steps.get(0); return step; - } - else { + } else { // This error will likely never be thrown, because there should // never be two steps with the same name and Job_ID due to database // constraints. - throw new IncorrectResultSizeDataAccessException("Step Invalid, multiple steps found for StepName:" - + stepName + " and JobId:" + job.getId(), 1, steps.size()); + throw new IncorrectResultSizeDataAccessException( + "Step Invalid, multiple steps found for StepName:" + + stepName + " and JobId:" + job.getId(), 1, steps + .size()); } } @@ -194,7 +197,8 @@ public class SqlStepDao implements StepDao, InitializingBean { * they will not be returned with reconstituted object. * * @see StepDao#getStepExecution(Long) - * @throws IllegalArgumentException if id is null. + * @throws IllegalArgumentException + * if id is null. */ public List findStepExecutions(final StepInstance step) { @@ -204,23 +208,28 @@ public class SqlStepDao implements StepDao, InitializingBean { RowMapper rowMapper = new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - JobExecution jobExecution = (JobExecution) jdbcTemplate.queryForObject( - getQuery(JobExecutionRowMapper.GET_JOB_EXECUTION), new Object[] { new Long(rs.getLong(2)) }, - new JobExecutionRowMapper(step.getJob())); - StepExecution stepExecution = new StepExecution(step, jobExecution, new Long(rs.getLong(1))); + JobExecution jobExecution = (JobExecution) jdbcTemplate + .queryForObject( + getQuery(JobExecutionRowMapper.GET_JOB_EXECUTION), + new Object[] { new Long(rs.getLong(2)) }, + new JobExecutionRowMapper(step.getJob())); + StepExecution stepExecution = new StepExecution(step, + jobExecution, new Long(rs.getLong(1))); stepExecution.setStartTime(rs.getTimestamp(3)); stepExecution.setEndTime(rs.getTimestamp(4)); stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5))); stepExecution.setCommitCount(rs.getInt(6)); stepExecution.setTaskCount(rs.getInt(7)); - stepExecution.setStatistics(PropertiesConverter.stringToProperties(rs.getString(8))); - stepExecution.setExitStatus(new ExitStatus("Y".equals(rs.getString(9)), rs.getString(10), rs - .getString(11))); + stepExecution.setStatistics(PropertiesConverter + .stringToProperties(rs.getString(8))); + stepExecution.setExitStatus(new ExitStatus("Y".equals(rs + .getString(9)), rs.getString(10), rs.getString(11))); return stepExecution; } }; - return jdbcTemplate.query(getFindStepExecutionsQuery(), new Object[] { step.getId() }, rowMapper); + return jdbcTemplate.query(getFindStepExecutionsQuery(), + new Object[] { step.getId() }, rowMapper); } @@ -230,7 +239,8 @@ public class SqlStepDao implements StepDao, InitializingBean { * Sql implementation which uses a RowMapper to populate a list of all rows * in the step table with the same JOB_ID. * - * @throws IllegalArgumentException if jobId is null. + * @throws IllegalArgumentException + * if jobId is null. */ public List findSteps(final JobInstance job) { @@ -242,10 +252,12 @@ public class SqlStepDao implements StepDao, InitializingBean { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - StepInstance step = new StepInstance(job, rs.getString(2), new Long(rs.getLong(1))); + StepInstance step = new StepInstance(job, rs.getString(2), + new Long(rs.getLong(1))); String status = rs.getString(3); step.setStatus(BatchStatus.getStatus(status)); - step.setRestartData(new GenericRestartData(PropertiesConverter.stringToProperties(rs.getString(3)))); + step.setRestartData(new GenericRestartData(PropertiesConverter + .stringToProperties(rs.getString(3)))); return step; } }; @@ -281,7 +293,8 @@ public class SqlStepDao implements StepDao, InitializingBean { Object[] parameters = new Object[] { stepId }; - return jdbcTemplate.queryForInt(getStepExecutionCountQuery(), parameters); + return jdbcTemplate.queryForInt(getStepExecutionCountQuery(), + parameters); } private String getStepExecutionCountQuery() { @@ -310,16 +323,26 @@ public class SqlStepDao implements StepDao, InitializingBean { cascadeJobExecution(stepExecution.getJobExecution()); stepExecution.setId(new Long(stepExecutionIncrementer.nextLongValue())); - stepExecution.incrementVersion(); // should be 0 now - Object[] parameters = new Object[] { stepExecution.getId(), new Long(0), stepExecution.getStepId(), - stepExecution.getJobExecutionId(), stepExecution.getStartTime(), stepExecution.getEndTime(), - stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getTaskCount(), - PropertiesConverter.propertiesToString(stepExecution.getStatistics()), - stepExecution.getExitStatus().isContinuable() ? "Y" : "N", stepExecution.getExitStatus().getExitCode(), + Object[] parameters = new Object[] { + stepExecution.getId(), + new Long(0), + stepExecution.getStepId(), + stepExecution.getJobExecutionId(), + stepExecution.getStartTime(), + stepExecution.getEndTime(), + stepExecution.getStatus().toString(), + stepExecution.getCommitCount(), + stepExecution.getTaskCount(), + PropertiesConverter.propertiesToString(stepExecution + .getStatistics()), + stepExecution.getExitStatus().isContinuable() ? "Y" : "N", + stepExecution.getExitStatus().getExitCode(), stepExecution.getExitStatus().getExitDescription() }; - jdbcTemplate.update(getSaveStepExecutionQuery(), parameters, new int[] { Types.INTEGER, Types.INTEGER, - Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, - Types.INTEGER, Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR }); + jdbcTemplate.update(getSaveStepExecutionQuery(), parameters, new int[] { + Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, + Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, + Types.INTEGER, Types.VARCHAR, Types.CHAR, Types.VARCHAR, + Types.VARCHAR }); } @@ -331,7 +354,8 @@ public class SqlStepDao implements StepDao, InitializingBean { * Injection setter for job dao. Used to save {@link JobExecution} * instances. * - * @param jobDao a {@link JobDao} + * @param jobDao + * a {@link JobDao} */ public void setJobDao(JobDao jobDao) { this.jobDao = jobDao; @@ -343,7 +367,8 @@ public class SqlStepDao implements StepDao, InitializingBean { * * @param stepExecutionIncrementer a {@link DataFieldMaxValueIncrementer} */ - public void setStepExecutionIncrementer(DataFieldMaxValueIncrementer stepExecutionIncrementer) { + public void setStepExecutionIncrementer( + DataFieldMaxValueIncrementer stepExecutionIncrementer) { this.stepExecutionIncrementer = stepExecutionIncrementer; } @@ -363,65 +388,65 @@ public class SqlStepDao implements StepDao, InitializingBean { * are overridden with the set*Query methods). Defaults to * {@value #DEFAULT_TABLE_PREFIX}. * - * @param tablePrefix the tablePrefix to set + * @param tablePrefix + * the tablePrefix to set */ public void setTablePrefix(String tablePrefix) { this.tablePrefix = tablePrefix; } /** - * Update the {@link StepExecution}, truncating the exit description. Also - * checks for optimistic locking failure where another agent has updated the - * {@link StepExecution}.
- * - * N.B. locks the {@link StepExecution} to prevent multi-threaded access. - * - * @throws OptimisticLockingFailureException if the {@link StepExecution} - * version does not match the value in the data base. * @see StepDao#update(StepExecution) */ public void update(StepExecution stepExecution) { validateStepExecution(stepExecution); - Assert.notNull(stepExecution.getId(), "StepExecution Id cannot be null. StepExecution must saved" - + " before it can be updated."); + Assert.notNull(stepExecution.getId(), + "StepExecution Id cannot be null. StepExecution must saved" + + " before it can be updated."); - String exitDescription = stepExecution.getExitStatus().getExitDescription(); - if (exitDescription != null && exitDescription.length() > EXIT_MESSAGE_LENGTH) { + // TODO: Not sure if this is a good idea on step execution considering + // it is saved at every commit + // point. + // if (jdbcTemplate.queryForInt(CHECK_STEP_EXECUTION_EXISTS, new + // Object[] { stepExecution.getId() }) != 1) { + // return; // throw exception? + // } + + String exitDescription = stepExecution.getExitStatus() + .getExitDescription(); + if (exitDescription != null + && exitDescription.length() > EXIT_MESSAGE_LENGTH) { exitDescription = exitDescription.substring(0, EXIT_MESSAGE_LENGTH); - logger.debug("Truncating long message before update of StepExecution: " + stepExecution); + logger + .debug("Truncating long message before update of StepExecution: " + + stepExecution); } - // Attempt to prevent concurrent modification errors by blocking here if - // someone is already trying to do it. - synchronized (stepExecution) { + Object[] parameters = new Object[] { + stepExecution.getStartTime(), + stepExecution.getEndTime(), + stepExecution.getStatus().toString(), + stepExecution.getCommitCount(), + stepExecution.getTaskCount(), + PropertiesConverter.propertiesToString(stepExecution + .getStatistics()), + stepExecution.getExitStatus().isContinuable() ? "Y" : "N", + stepExecution.getExitStatus().getExitCode(), exitDescription, + stepExecution.getId() }; + jdbcTemplate + .update(getUpdateStepExecutionQuery(), parameters, + new int[] { Types.TIMESTAMP, Types.TIMESTAMP, + Types.VARCHAR, Types.INTEGER, Types.INTEGER, + Types.VARCHAR, Types.CHAR, Types.VARCHAR, + Types.VARCHAR, Types.INTEGER }); - Integer version = new Integer(stepExecution.getVersion().intValue() + 1); - - Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(), - stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getTaskCount(), - PropertiesConverter.propertiesToString(stepExecution.getStatistics()), - stepExecution.getExitStatus().isContinuable() ? "Y" : "N", - stepExecution.getExitStatus().getExitCode(), exitDescription, version, stepExecution.getId(), - stepExecution.getVersion() }; - int count = jdbcTemplate.update(getUpdateStepExecutionQuery(), parameters, new int[] { Types.TIMESTAMP, - Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.CHAR, - Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER }); - - // Avoid concurrent modifications... - if (count == 0) { - throw new OptimisticLockingFailureException("Attempt to update step execution id=" - + stepExecution.getId() + " with out of date version (" + stepExecution.getVersion() + ")"); - } - - stepExecution.incrementVersion(); - - } } /** * @see StepDao#update(StepInstance) - * @throws IllegalArgumentException if step, or it's status and id is null. + * @throws IllegalArgumentException + * if step, or it's status and id is null. */ public void update(final StepInstance step) { @@ -429,21 +454,17 @@ public class SqlStepDao implements StepDao, InitializingBean { Assert.notNull(step.getStatus(), "Step status cannot be null."); Assert.notNull(step.getId(), "Step Id cannot be null."); - String restartString = ""; + Properties restartProps = null; RestartData restartData = step.getRestartData(); if (restartData != null) { - restartString = PropertiesConverter.propertiesToString(restartData.getProperties()); + restartProps = restartData.getProperties(); } - if (restartString.length() >= RESTART_DATA_LENGTH) { - logger.error("Restart data too long to persist (max length=" + RESTART_DATA_LENGTH + "): " + restartString); - throw new IllegalStateException("Restart exceeded allowed length (" + RESTART_DATA_LENGTH + ")"); - } - - Object[] parameters = new Object[] { step.getStatus().toString(), restartString, step.getId() }; + Object[] parameters = new Object[] { step.getStatus().toString(), + PropertiesConverter.propertiesToString(restartProps), + step.getId() }; jdbcTemplate.update(getUpdateStepQuery(), parameters); - } /* @@ -455,9 +476,12 @@ public class SqlStepDao implements StepDao, InitializingBean { private void validateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution); - Assert.notNull(stepExecution.getStepId(), "StepExecution Step-Id cannot be null."); - Assert.notNull(stepExecution.getStartTime(), "StepExecution start time cannot be null."); - Assert.notNull(stepExecution.getStatus(), "StepExecution status cannot be null."); + Assert.notNull(stepExecution.getStepId(), + "StepExecution Step-Id cannot be null."); + Assert.notNull(stepExecution.getStartTime(), + "StepExecution start time cannot be null."); + Assert.notNull(stepExecution.getStatus(), + "StepExecution status cannot be null."); } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoQueryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoQueryTests.java similarity index 90% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoQueryTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoQueryTests.java index d4d877a1a..93c356cb1 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoQueryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoQueryTests.java @@ -30,16 +30,16 @@ import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer * @author Dave Syer * */ -public class SqlJobDaoQueryTests extends TestCase { +public class JdbcJobDaoQueryTests extends TestCase { - SqlJobDao sqlDao; + JdbcJobDao sqlDao; List list = new ArrayList(); /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { - sqlDao = new SqlJobDao(); + sqlDao = new JdbcJobDao(); sqlDao.setJobExecutionIncrementer(new DataFieldMaxValueIncrementer() { public int nextIntValue() throws DataAccessException { @@ -66,7 +66,7 @@ public class SqlJobDaoQueryTests extends TestCase { return 1; } }); - sqlDao.save(new JobInstance(new SimpleJobIdentifier("foo"), new Long(11)).createJobExecution()); + sqlDao.save(new JobInstance(new SimpleJobIdentifier("foo"), new Long(11)).createNewJobExecution()); assertEquals(1, list.size()); String query = (String) list.get(0); assertTrue("Query did not contain FOO_:"+query, query.indexOf("FOO_")>=0); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoTests.java similarity index 87% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoTests.java index 5c397c025..d11f4d5b5 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlJobDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcJobDaoTests.java @@ -5,12 +5,12 @@ import java.util.Map; import org.springframework.batch.repeat.ExitStatus; -public class SqlJobDaoTests extends AbstractJobDaoTests { +public class JdbcJobDaoTests extends AbstractJobDaoTests { public static final String LONG_STRING = "A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String A very long String "; protected void onSetUpBeforeTransaction() throws Exception { - ((SqlJobDao) jobDao).setTablePrefix(SqlJobDao.DEFAULT_TABLE_PREFIX); + ((JdbcJobDao) jobDao).setTablePrefix(JdbcJobDao.DEFAULT_TABLE_PREFIX); } public void testUpdateJobExecutionWithLongExitCode() { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java similarity index 81% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java index 9e4a6d5a1..51a55541d 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java @@ -1,7 +1,5 @@ package org.springframework.batch.execution.repository.dao; -import java.util.List; - import junit.framework.TestCase; import org.easymock.MockControl; @@ -10,9 +8,6 @@ import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; /** @@ -24,9 +19,9 @@ import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer * @author Lucas Ward * */ -public class SqlStepDaoPrefixTests extends TestCase { +public class JdbcStepDaoPrefixTests extends TestCase { - private SqlStepDao stepDao; + private JdbcStepDao stepDao; MockJdbcTemplate jdbcTemplate = new MockJdbcTemplate(); @@ -42,7 +37,7 @@ public class SqlStepDaoPrefixTests extends TestCase { protected void setUp() throws Exception { super.setUp(); - stepDao = new SqlStepDao(); + stepDao = new JdbcStepDao(); stepDao.setJobDao(new MapJobDao()); stepExecutionIncrementer = (DataFieldMaxValueIncrementer)stepExecutionIncrementerControl.getMock(); stepIncrementer = (DataFieldMaxValueIncrementer)stepIncrementerControl.getMock(); @@ -51,7 +46,6 @@ public class SqlStepDaoPrefixTests extends TestCase { stepDao.setStepExecutionIncrementer(stepExecutionIncrementer); stepDao.setStepIncrementer(stepIncrementer); stepExecution.setId(new Long(1)); - stepExecution.incrementVersion(); step.setStatus(BatchStatus.STARTED); job.addStep(step); @@ -162,33 +156,4 @@ public class SqlStepDaoPrefixTests extends TestCase { assertTrue(jdbcTemplate.getSqlStatement().indexOf("BATCH_STEP_EXECUTION") != -1); } - private class MockJdbcTemplate extends JdbcTemplate { - - private String sqlStatement = ""; - - public String getSqlStatement() { - return sqlStatement; - } - - public List query(String sql, Object[] args, RowMapper rse) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 1; - } - - public int update(String sql, Object[] args) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 1; - } - - } - - } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java similarity index 76% rename from spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoTests.java rename to spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java index 9b2318543..f0e169d62 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java @@ -6,16 +6,16 @@ import java.util.Map; import org.springframework.batch.repeat.ExitStatus; import org.springframework.dao.DataAccessException; -public class SqlStepDaoTests extends AbstractStepDaoTests { +public class JdbcStepDaoTests extends AbstractStepDaoTests { - private static final String LONG_STRING = SqlJobDaoTests.LONG_STRING; + private static final String LONG_STRING = JdbcJobDaoTests.LONG_STRING; protected void onSetUpBeforeTransaction() throws Exception { - ((SqlStepDao) stepDao).setTablePrefix(SqlJobDao.DEFAULT_TABLE_PREFIX); + ((JdbcStepDao) stepDao).setTablePrefix(JdbcJobDao.DEFAULT_TABLE_PREFIX); } public void testTablePrefix() throws Exception { - ((SqlStepDao) stepDao).setTablePrefix("FOO_"); + ((JdbcStepDao) stepDao).setTablePrefix("FOO_"); try { testCreateStep(); fail("Expected DataAccessException"); @@ -37,5 +37,5 @@ public class SqlStepDaoTests extends AbstractStepDaoTests { assertEquals(LONG_STRING.substring(0, 250), ((Map) executions.get(0)) .get("EXIT_MESSAGE")); } - + } diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml index a76654e83..40e669f85 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml @@ -5,13 +5,13 @@ - + - +