From d0e0334674eb6597ac519d6d36949fd6fa499b4a Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Sun, 16 Sep 2012 23:30:12 -0400 Subject: [PATCH] BATCH-1891: Migrate usage of deprecated classes --- .../configuration/support/MapJobRegistry.java | 4 -- .../support/JobExplorerFactoryBean.java | 8 +-- .../dao/AbstractJdbcBatchMetadataDao.java | 8 +-- .../dao/JdbcExecutionContextDao.java | 2 +- .../repository/dao/JdbcJobExecutionDao.java | 7 ++- .../repository/dao/JdbcJobInstanceDao.java | 12 ++--- .../repository/dao/JdbcStepExecutionDao.java | 8 ++- .../repository/dao/MapJobExecutionDao.java | 1 - .../repository/dao/MapJobInstanceDao.java | 1 - .../support/JobRepositoryFactoryBean.java | 8 +-- .../configuration/xml/StepParserTests.java | 10 ++-- .../launch/JobLauncherIntegrationTests.java | 6 +-- .../support/SimpleJobOperatorTests.java | 1 - .../partition/RestartIntegrationTests.java | 6 +-- .../partition/VanillaIntegrationTests.java | 6 +-- .../repository/dao/AbstractJobDaoTests.java | 12 ++--- .../repository/dao/JdbcJobDaoQueryTests.java | 5 +- .../core/repository/dao/JdbcJobDaoTests.java | 2 +- .../dao/JdbcJobExecutionDaoTests.java | 14 +++--- .../dao/JdbcJobInstanceDaoTests.java | 16 +++--- .../dao/MapExecutionContextDaoTests.java | 5 +- .../dao/MapJobExecutionDaoTests.java | 9 +--- .../dao/MapJobInstanceDaoTests.java | 4 +- .../dao/MapStepExecutionDaoTests.java | 4 +- .../core/repository/dao/TablePrefixTests.java | 10 ++-- .../ListPreparedStatementSetterTests.java | 20 ++++---- .../scope/AsyncStepScopeIntegrationTests.java | 2 - .../core/repository/dao/sql-dao-test.xml | 2 +- spring-batch-infrastructure/pom.xml | 2 - .../item/database/JdbcBatchItemWriter.java | 30 +++++------- .../item/database/JdbcPagingItemReader.java | 27 +++++----- .../batch/item/file/transform/Alignment.java | 36 +++++++++++--- .../batch/item/xml/StaxEventItemWriter.java | 1 - .../batch/support/JdbcTestUtils.java | 49 +++++++++++++++++++ ...bstractJdbcItemReaderIntegrationTests.java | 6 +-- ...xtendedConnectionDataSourceProxyTests.java | 4 +- .../HibernateCursorItemReaderCommonTests.java | 4 +- .../IbatisPagingItemReaderAsyncTests.java | 10 ++-- .../IbatisPagingItemReaderCommonTests.java | 4 +- .../JdbcBatchItemWriterClassicTests.java | 13 ++--- ...dbcBatchItemWriterNamedParameterTests.java | 30 ++++++------ .../JdbcCursorItemReaderCommonTests.java | 4 +- .../JdbcCursorItemReaderConfigTests.java | 4 +- .../JdbcPagingItemReaderAsyncTests.java | 10 ++-- .../JdbcPagingItemReaderConfigTests.java | 7 +-- .../JpaPagingItemReaderAsyncTests.java | 10 ++-- .../batch/item/database/SingleKeyFooDao.java | 4 +- .../StoredProcedureItemReaderCommonTests.java | 4 +- .../StoredprocedureItemReaderConfigTests.java | 4 +- .../MultiResourceItemReaderFlatFileTests.java | 4 +- .../file/MultiResourceItemReaderXmlTests.java | 4 +- .../xml/StaxEventItemReaderCommonTests.java | 4 +- .../batch/test/JobRepositoryTestUtils.java | 10 ++-- .../batch/test/AbstractSampleJobTests.java | 6 +-- .../test/JobRepositoryTestUtilsTests.java | 41 ++++++++-------- .../batch/test/SampleStepTests.java | 4 +- .../batch/test/sample/SampleTasklet.java | 4 +- .../resources/simple-job-launcher-context.xml | 2 +- 58 files changed, 282 insertions(+), 253 deletions(-) create mode 100644 spring-batch-infrastructure/src/main/java/org/springframework/batch/support/JdbcTestUtils.java diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/MapJobRegistry.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/MapJobRegistry.java index 3663e6f4d..12d61f573 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/MapJobRegistry.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/MapJobRegistry.java @@ -15,11 +15,7 @@ */ package org.springframework.batch.core.configuration.support; -import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java index 9e7d9cc5f..a62b96aea 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java @@ -30,8 +30,8 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao; import org.springframework.batch.item.ExecutionContext; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.jdbc.support.lob.LobHandler; @@ -50,7 +50,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean private DataSource dataSource; - private SimpleJdbcOperations jdbcTemplate; + private JdbcOperations jdbcTemplate; private String tablePrefix = AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX; @@ -96,7 +96,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean Assert.notNull(dataSource, "DataSource must not be null."); - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java index 15ea5bc4e..1fb8cf3ef 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java @@ -19,7 +19,7 @@ package org.springframework.batch.core.repository.dao; import java.sql.Types; import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -42,7 +42,7 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { private int clobTypeToUse = Types.CLOB; - private SimpleJdbcOperations jdbcTemplate; + private JdbcOperations jdbcTemplate; protected String getQuery(String base) { return StringUtils.replace(base, "%PREFIX%", tablePrefix); @@ -63,11 +63,11 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { this.tablePrefix = tablePrefix; } - public void setJdbcTemplate(SimpleJdbcOperations jdbcTemplate) { + public void setJdbcTemplate(JdbcOperations jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } - protected SimpleJdbcOperations getJdbcTemplate() { + protected JdbcOperations getJdbcTemplate() { return jdbcTemplate; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index d182b6e45..112627342 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -190,7 +190,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem longContext = null; } - getJdbcTemplate().getJdbcOperations().update(getQuery(sql), new PreparedStatementSetter() { + getJdbcTemplate().update(getQuery(sql), new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, shortContext); if (longContext != null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 2cdad87f6..167cbdfb5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -135,7 +135,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated() }; - getJdbcTemplate().getJdbcOperations().update( + getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, @@ -197,7 +197,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements throw new NoSuchObjectException("Invalid JobExecution, ID " + jobExecution.getId() + " not found."); } - int count = getJdbcTemplate().getJdbcOperations().update( + int count = getJdbcTemplate().update( getQuery(UPDATE_JOB_EXECUTION), parameters, new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, @@ -265,8 +265,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements result.add(mapper.mapRow(rs, 0)); } }; - getJdbcTemplate().getJdbcOperations() - .query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); + getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); return result; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index 0051722c3..089bbf053 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -114,7 +114,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobParameters), jobInstance.getVersion() }; - getJdbcTemplate().getJdbcOperations().update( + getJdbcTemplate().update( getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, @@ -195,8 +195,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements args = new Object[] { jobId, key, type, "", value, 0L, 0D }; } - getJdbcTemplate().getJdbcOperations().update( - getQuery(CREATE_JOB_PARAMETERS), args, argTypes); + getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); } /** @@ -277,9 +276,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements map.put(rs.getString(2), value); } }; - getJdbcTemplate().getJdbcOperations().query( - getQuery(FIND_PARAMS_FROM_ID), new Object[] { instanceId }, - handler); + getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), new Object[] { instanceId }, handler); return new JobParameters(map); } @@ -330,8 +327,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements }; @SuppressWarnings("unchecked") - List result = (List) getJdbcTemplate() - .getJdbcOperations().query(getQuery(FIND_LAST_JOBS_BY_NAME), + List result = (List) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_BY_NAME), new Object[] { jobName }, extractor); return result; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index 5dd1a20c9..3f7275e4b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -123,7 +123,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() }; - getJdbcTemplate().getJdbcOperations().update( + getJdbcTemplate().update( getQuery(SAVE_STEP_EXECUTION), parameters, new int[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.TIMESTAMP, @@ -136,7 +136,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement * Validate StepExecution. At a minimum, JobId, StartTime, and Status cannot * be null. EndTime can be null for an unfinished job. * - * @param value * @throws IllegalArgumentException */ private void validateStepExecution(StepExecution stepExecution) { @@ -169,8 +168,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() }; - int count = getJdbcTemplate().getJdbcOperations() - .update( + int count = getJdbcTemplate().update( getQuery(UPDATE_STEP_EXECUTION), parameters, new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, @@ -194,7 +192,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement /** * Truncate the exit description if the length exceeds - * {@link #EXIT_MESSAGE_LENGTH}. + * {@link #DEFAULT_EXIT_MESSAGE_LENGTH}. * @param description the string to truncate * @return truncated description */ diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java index fbb2f5181..ca8da5215 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java index ec62ddae6..68ade2582 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java @@ -17,7 +17,6 @@ package org.springframework.batch.core.repository.dao; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java index c880f67d6..f492961c6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java @@ -38,8 +38,8 @@ import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueI import org.springframework.batch.support.DatabaseType; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.jdbc.support.lob.OracleLobHandler; import org.springframework.util.Assert; @@ -61,7 +61,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i private DataSource dataSource; - private SimpleJdbcOperations jdbcTemplate; + private JdbcOperations jdbcTemplate; private String databaseType; @@ -135,7 +135,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i Assert.notNull(dataSource, "DataSource must not be null."); - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); if (incrementerFactory == null) { incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java index 8cdcebf35..b1a94a40e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java @@ -53,11 +53,9 @@ import org.springframework.batch.retry.RetryListener; import org.springframework.batch.retry.listener.RetryListenerSupport; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; import org.springframework.dao.DeadlockLoserDataAccessException; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.PlatformTransactionManager; @@ -150,14 +148,14 @@ public class StepParserTests { @Test(expected = BeanDefinitionParsingException.class) public void testTaskletStepWithBadStepListener() throws Exception { - String contextLocation = "org/springframework/batch/core/configuration/xml/StepParserBadStepListenerTests-context.xml"; - new XmlBeanFactory(new ClassPathResource(contextLocation)); + new ClassPathXmlApplicationContext( + "org/springframework/batch/core/configuration/xml/StepParserBadStepListenerTests-context.xml"); } @Test(expected = BeanDefinitionParsingException.class) public void testTaskletStepWithBadRetryListener() throws Exception { - String contextLocation = "org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml"; - new XmlBeanFactory(new ClassPathResource(contextLocation)); + new ClassPathXmlApplicationContext( + "org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml"); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/JobLauncherIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/JobLauncherIntegrationTests.java index 4259bad92..4410146aa 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/JobLauncherIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/JobLauncherIntegrationTests.java @@ -14,7 +14,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -22,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) public class JobLauncherIntegrationTests { - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JobLauncher jobLauncher; @@ -32,7 +32,7 @@ public class JobLauncherIntegrationTests { @Autowired public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java index 9de0d88da..157ed9a2e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/RestartIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/RestartIntegrationTests.java index 506c42796..9e6f3b619 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/RestartIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/RestartIntegrationTests.java @@ -31,7 +31,7 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -49,11 +49,11 @@ public class RestartIntegrationTests { @Autowired private Job job; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/VanillaIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/VanillaIntegrationTests.java index b96c8a98b..1f3619f45 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/VanillaIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/VanillaIntegrationTests.java @@ -26,7 +26,7 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,11 +44,11 @@ public class VanillaIntegrationTests { @Autowired private Job job; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java index e8162a5ef..292f2ec9d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java @@ -37,7 +37,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.annotation.Transactional; /** @@ -61,11 +61,11 @@ public abstract class AbstractJobDaoTests { protected Date jobExecutionStartTime = new Date(System.currentTimeMillis()); - protected SimpleJdbcTemplate simpleJdbcTemplate; + protected JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } /* @@ -98,14 +98,14 @@ public abstract class AbstractJobDaoTests { @Transactional @Test public void testVersionIsNotNullForJob() throws Exception { - int version = simpleJdbcTemplate.queryForInt("select version from BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=" + int version = jdbcTemplate.queryForInt("select version from BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=" + jobInstance.getId()); assertEquals(0, version); } @Transactional @Test public void testVersionIsNotNullForJobExecution() throws Exception { - int version = simpleJdbcTemplate.queryForInt("select version from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID=" + int version = jdbcTemplate.queryForInt("select version from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID=" + jobExecution.getId()); assertEquals(0, version); } @@ -221,7 +221,7 @@ public abstract class AbstractJobDaoTests { // Create job. jobInstance = jobInstanceDao.createJobInstance(testJob, jobParameters); - List> jobs = simpleJdbcTemplate.queryForList( + List> jobs = jdbcTemplate.queryForList( "SELECT * FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", jobInstance.getId()); assertEquals(1, jobs.size()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java index 7acf31d4b..6bcf4f23c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java @@ -25,7 +25,6 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; /** @@ -64,12 +63,12 @@ public class JdbcJobDaoQueryTests extends TestCase { public void testTablePrefix() throws Exception { jobExecutionDao.setTablePrefix("FOO_"); - jobExecutionDao.setJdbcTemplate(new SimpleJdbcTemplate(new JdbcTemplate() { + jobExecutionDao.setJdbcTemplate(new JdbcTemplate() { public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { list.add(sql); return 1; } - })); + }); JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "testJob")); jobExecutionDao.saveJobExecution(jobExecution); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java index 16a6c964b..1ad220481 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java @@ -34,7 +34,7 @@ public class JdbcJobDaoTests extends AbstractJobDaoTests { .addExitDescription(LONG_STRING)); jobExecutionDao.updateJobExecution(jobExecution); - List> executions = simpleJdbcTemplate.queryForList( + List> executions = jdbcTemplate.queryForList( "SELECT * FROM BATCH_JOB_EXECUTION where JOB_INSTANCE_ID=?", jobInstance.getId()); assertEquals(1, executions.size()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java index 99cd0499d..8a59eaa69 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java @@ -4,10 +4,10 @@ import javax.sql.DataSource; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "sql-dao-test.xml" }) @@ -22,11 +22,11 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests { @Autowired private JobInstanceDao jobInstanceDao; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Override @@ -36,9 +36,9 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests { @Override protected JobExecutionDao getJobExecutionDao() { - SimpleJdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT", - "BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", - "BATCH_JOB_INSTANCE"); + JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT", + "BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", + "BATCH_JOB_INSTANCE"); return jobExecutionDao; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java index c152bc40c..93076d53e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java @@ -14,21 +14,21 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "sql-dao-test.xml") public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { - - private SimpleJdbcTemplate jdbcTemplate; + + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Autowired @@ -38,9 +38,9 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { private JobExecutionDao jobExecutionDao; protected JobInstanceDao getJobInstanceDao() { - SimpleJdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT", - "BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", - "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE"); + JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT", + "BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", + "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE"); return jobInstanceDao; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java index f941fa8a5..eba9470a5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java @@ -3,8 +3,7 @@ package org.springframework.batch.core.repository.dao; import static org.junit.Assert.*; import org.junit.Test; -import org.junit.Ignore; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; @@ -13,7 +12,7 @@ import org.springframework.batch.item.ExecutionContext; /** * Tests for {@link MapExecutionContextDao}. */ -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MapExecutionContextDaoTests extends AbstractExecutionContextDaoTests { @Override diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java index fc451aadf..7f9e127f0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java @@ -1,29 +1,24 @@ package org.springframework.batch.core.repository.dao; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; import org.junit.runner.RunWith; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import static org.junit.Assert.*; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests { @Override diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java index 8912a5b05..23f9101b1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java @@ -1,9 +1,9 @@ package org.springframework.batch.core.repository.dao; import org.junit.runner.RunWith; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests { protected JobInstanceDao getJobInstanceDao() { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java index c5546e4b9..204808d27 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertNull; import java.util.Date; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; @@ -15,7 +15,7 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.SimpleJobRepository; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests { protected StepExecutionDao getStepExecutionDao() { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/TablePrefixTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/TablePrefixTests.java index 37522fe0d..72f5b476e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/TablePrefixTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/TablePrefixTests.java @@ -31,10 +31,10 @@ import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -46,18 +46,18 @@ public class TablePrefixTests { @Autowired private Job job; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test public void testJobLaunch() throws Exception { JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); - assertEquals(1, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "PREFIX_JOB_INSTANCE")); + assertEquals(1, JdbcTestUtils.countRowsInTable(jdbcTemplate, "PREFIX_JOB_INSTANCE")); } public static class TestTasklet implements Tasklet { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/ListPreparedStatementSetterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/ListPreparedStatementSetterTests.java index 19a36b71f..53ee8cd58 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/ListPreparedStatementSetterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/ListPreparedStatementSetterTests.java @@ -36,7 +36,7 @@ import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.item.ItemWriter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -55,11 +55,11 @@ public class ListPreparedStatementSetterTests { StepExecution stepExecution; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Autowired @@ -86,7 +86,7 @@ public class ListPreparedStatementSetterTests { public void testSetValues() { final List results = new ArrayList(); - simpleJdbcTemplate.getJdbcOperations().query("SELECT NAME from T_FOOS where ID > ? and ID < ?", pss, + jdbcTemplate.query("SELECT NAME from T_FOOS where ID > ? and ID < ?", pss, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { results.add(rs.getString(1)); @@ -107,12 +107,12 @@ public class ListPreparedStatementSetterTests { @Test public void testXmlConfiguration() throws Exception { - this.simpleJdbcTemplate.update("create table FOO (ID integer, NAME varchar(40), VALUE integer)"); + this.jdbcTemplate.update("create table FOO (ID integer, NAME varchar(40), VALUE integer)"); try { - this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0); - this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1); - this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2); - this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3); + this.jdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0); + this.jdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1); + this.jdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2); + this.jdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3); JobParametersBuilder builder = new JobParametersBuilder().addLong("min.id", 1L).addLong("max.id", 2L); JobExecution jobExecution = this.jobLauncher.run(this.job, builder.toJobParameters()); @@ -126,7 +126,7 @@ public class ListPreparedStatementSetterTests { assertEquals(new Foo(2, "two", 2), foos.get(1)); } finally { - this.simpleJdbcTemplate.update("drop table FOO"); + this.jdbcTemplate.update("drop table FOO"); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/AsyncStepScopeIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/AsyncStepScopeIntegrationTests.java index ad2552cc2..3e4cc6abb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/AsyncStepScopeIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/AsyncStepScopeIntegrationTests.java @@ -136,10 +136,8 @@ public class AsyncStepScopeIntegrationTests implements BeanFactoryAware { taskExecutor.execute(task); } - int i = 0; for (FutureTask task : tasks) { assertEquals("foo", task.get()); - i++; } // Don't close the outer scope until all tasks are finished. This should diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml index 205710d7a..1d82f4c44 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml @@ -30,7 +30,7 @@ - + \ No newline at end of file diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index 72b15921d..3370ab903 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -171,8 +171,6 @@ org.springframework spring-core - - org.springframework spring-aop diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java index f4787c84d..90d7205ef 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java @@ -29,16 +29,15 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.PreparedStatementCallback; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.util.Assert; /** *

{@link ItemWriter} that uses the batching features from - * {@link SimpleJdbcTemplate} to execute a batch of statements for all items + * {@link NamedParameterJdbcTemplate} to execute a batch of statements for all items * provided.

* * The user must provide an SQL query and a special callback in the for of either @@ -62,7 +61,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { protected static final Log logger = LogFactory.getLog(JdbcBatchItemWriter.class); - private SimpleJdbcOperations simpleJdbcTemplate; + private NamedParameterJdbcOperations namedParameterJdbcTemplate; private ItemPreparedStatementSetter itemPreparedStatementSetter; @@ -119,17 +118,17 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { * @param dataSource */ public void setDataSource(DataSource dataSource) { - if (simpleJdbcTemplate == null) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + if (namedParameterJdbcTemplate == null) { + this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); } } /** - * Public setter for the {@link JdbcOperations}. - * @param simpleJdbcTemplate the {@link JdbcOperations} to set + * Public setter for the {@link NamedParameterJdbcOperations}. + * @param namedParameterJdbcTemplate the {@link NamedParameterJdbcOperations} to set */ - public void setSimpleJdbcTemplate(SimpleJdbcOperations simpleJdbcTemplate) { - this.simpleJdbcTemplate = simpleJdbcTemplate; + public void setJdbcTemplate(NamedParameterJdbcOperations namedParameterJdbcTemplate) { + this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; } /** @@ -137,7 +136,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { * parameter source. */ public void afterPropertiesSet() { - Assert.notNull(simpleJdbcTemplate, "A DataSource or a SimpleJdbcTemplate is required."); + Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required."); Assert.notNull(sql, "An SQL statement is required."); List namedParameters = new ArrayList(); parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters); @@ -174,10 +173,10 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { for (T item : items) { batchArgs[i++] = itemSqlParameterSourceProvider.createSqlParameterSource(item); } - updateCounts = simpleJdbcTemplate.batchUpdate(sql, batchArgs); + updateCounts = namedParameterJdbcTemplate.batchUpdate(sql, batchArgs); } else { - updateCounts = (int[]) simpleJdbcTemplate.getJdbcOperations().execute(sql, new PreparedStatementCallback() { + updateCounts = (int[]) namedParameterJdbcTemplate.getJdbcOperations().execute(sql, new PreparedStatementCallback() { public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { for (T item : items) { itemPreparedStatementSetter.setValues(item, ps); @@ -197,9 +196,6 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean { } } } - } - } - } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java index 76b28e1fb..d96518f9f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java @@ -34,7 +34,7 @@ import org.springframework.batch.item.ItemStreamException; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -73,10 +73,6 @@ import org.springframework.util.ClassUtils; * @since 2.0 */ public class JdbcPagingItemReader extends AbstractPagingItemReader implements InitializingBean { - - /** - * - */ private static final String START_AFTER_VALUE = "start.after"; public static final int VALUE_NOT_SET = -1; @@ -87,7 +83,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme private Map parameterValues; - private SimpleJdbcTemplate simpleJdbcTemplate; + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private RowMapper rowMapper; @@ -169,7 +165,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme jdbcTemplate.setFetchSize(fetchSize); } jdbcTemplate.setMaxRows(getPageSize()); - this.simpleJdbcTemplate = new SimpleJdbcTemplate(jdbcTemplate); + namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); Assert.notNull(queryProvider); queryProvider.init(dataSource); this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize()); @@ -196,16 +192,16 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme } if (parameterValues != null && parameterValues.size() > 0) { if (this.queryProvider.isUsingNamedParameters()) { - query = simpleJdbcTemplate.getNamedParameterJdbcOperations().query(firstPageSql, + query = namedParameterJdbcTemplate.query(firstPageSql, getParameterMap(parameterValues, null), rowCallback); } else { - query = simpleJdbcTemplate.getJdbcOperations().query(firstPageSql, + query = getJdbcTemplate().query(firstPageSql, getParameterList(parameterValues, null).toArray(), rowCallback); } } else { - query = simpleJdbcTemplate.getJdbcOperations().query(firstPageSql, rowCallback); + query = getJdbcTemplate().query(firstPageSql, rowCallback); } } @@ -214,11 +210,11 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme logger.debug("SQL used for reading remaining pages: [" + remainingPagesSql + "]"); } if (this.queryProvider.isUsingNamedParameters()) { - query = simpleJdbcTemplate.getNamedParameterJdbcOperations().query(remainingPagesSql, + query = namedParameterJdbcTemplate.query(remainingPagesSql, getParameterMap(parameterValues, startAfterValue), rowCallback); } else { - query = simpleJdbcTemplate.getJdbcOperations().query(remainingPagesSql, + query = getJdbcTemplate().query(remainingPagesSql, getParameterList(parameterValues, startAfterValue).toArray(), rowCallback); } } @@ -266,11 +262,11 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme } }; if (this.queryProvider.isUsingNamedParameters()) { - startAfterValue = simpleJdbcTemplate.getNamedParameterJdbcOperations().queryForObject(jumpToItemSql, + startAfterValue = namedParameterJdbcTemplate.queryForObject(jumpToItemSql, getParameterMap(parameterValues, startAfterValue), startMapper); } else { - startAfterValue = simpleJdbcTemplate.getJdbcOperations().queryForObject(jumpToItemSql, + startAfterValue = getJdbcTemplate().queryForObject(jumpToItemSql, getParameterList(parameterValues, startAfterValue).toArray(), startMapper); } @@ -314,4 +310,7 @@ public class JdbcPagingItemReader extends AbstractPagingItemReader impleme } } + private JdbcTemplate getJdbcTemplate() { + return (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations(); + } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java index fb861b841..2230b7bf8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/Alignment.java @@ -15,24 +15,44 @@ */ package org.springframework.batch.item.file.transform; -import org.springframework.core.enums.StringCodedLabeledEnum; +import org.springframework.util.Assert; /** * @author Dave Syer * */ -public class Alignment extends StringCodedLabeledEnum { - - public static final Alignment CENTER = new Alignment("CENTER", "center"); - public static final Alignment RIGHT = new Alignment("RIGHT", "right"); - public static final Alignment LEFT = new Alignment("LEFT", "left"); +public enum Alignment { + CENTER("CENTER", "center"), + RIGHT("RIGHT", "right"), + LEFT("LEFT", "left"); + private String code; + private String label; + /** * @param code * @param label */ - public Alignment(String code, String label) { - super(code, label); + private Alignment(String code, String label) { + Assert.notNull(code, "'code' must not be null"); + + this.code = code; + this.label = label; } + public Comparable getCode() { + return code; + } + + public String getStringCode() { + return (String) getCode(); + } + + public String getLabel() { + if (this.label != null) { + return label; + } + + return getCode().toString(); + } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 6500448b9..bc96c648e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.util.List; import java.util.Map; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/JdbcTestUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/JdbcTestUtils.java new file mode 100644 index 000000000..9fd20a468 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/JdbcTestUtils.java @@ -0,0 +1,49 @@ +package org.springframework.batch.support; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.jdbc.core.JdbcTemplate; + +/** + *

+ * Util class based off {@link org.springframework.test.jdbc.SimpleJdbcTestUtils} but for JdbcTemplate + * rather than the deprecated {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate}. + * + * This class should be removed when Batch uses Spring 3.2 - see: + * https://jira.springsource.org/browse/SPR-9235 + *

+ */ +public final class JdbcTestUtils { + private static final Log LOG = LogFactory.getLog(JdbcTestUtils.class); + + private JdbcTestUtils() { + } + + /** + * Count the rows in the given table. + * @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations + * @param tableName table name to count rows in + * @return the number of rows in the table + */ + public static int countRowsInTable(JdbcTemplate jdbcTemplate, String tableName) { + return jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName); + } + + /** + * Delete all rows from the specified tables. + * @param jdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations + * @param tableNames the names of the tables from which to delete + * @return the total number of rows deleted from all specified tables + */ + public static int deleteFromTables(JdbcTemplate jdbcTemplate, String... tableNames) { + int totalRowCount = 0; + for (String tableName : tableNames) { + int rowCount = jdbcTemplate.update("DELETE FROM " + tableName); + totalRowCount += rowCount; + if (LOG.isInfoEnabled()) { + LOG.info("Deleted " + rowCount + " rows from table " + tableName); + } + } + return totalRowCount; + } +} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java index 9038610fb..3e9847f74 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java @@ -16,7 +16,7 @@ import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.annotation.Transactional; /** @@ -35,12 +35,12 @@ public abstract class AbstractJdbcItemReaderIntegrationTests { protected DataSource dataSource; - protected SimpleJdbcTemplate simpleJdbcTemplate; + protected JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java index 94fc066c7..0114e5ee2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java @@ -21,7 +21,7 @@ import java.util.logging.Logger; import javax.sql.DataSource; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; @@ -33,7 +33,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class ExtendedConnectionDataSourceProxyTests { @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderCommonTests.java index a3fc1f197..04c76a499 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderCommonTests.java @@ -8,9 +8,9 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.orm.hibernate3.LocalSessionFactoryBean; import org.junit.runner.RunWith; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class HibernateCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { protected ItemReader getItemReader() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java index 4e7818ee2..3edd5d80f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderAsyncTests.java @@ -24,13 +24,13 @@ import org.junit.runner.RunWith; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.orm.ibatis.SqlMapClientFactoryBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; import com.ibatis.sqlmap.client.SqlMapClient; +import org.springframework.batch.support.JdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") @@ -55,17 +55,17 @@ public class IbatisPagingItemReaderAsyncTests { @Before public void init() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); for (int i = maxId + 1; i <= ITEM_COUNT; i++) { jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); } - assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } @After public void destroy() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java index 41de3f5a9..d4c34b0c1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java @@ -1,6 +1,6 @@ package org.springframework.batch.item.database; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -10,7 +10,7 @@ import org.springframework.orm.ibatis.SqlMapClientFactoryBean; import com.ibatis.sqlmap.client.SqlMapClient; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { protected ItemReader getItemReader() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java index cb7ef1d46..508f69814 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java @@ -31,7 +31,7 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.PreparedStatementCallback; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; /** * @author Dave Syer @@ -62,7 +62,7 @@ public class JdbcBatchItemWriterClassicTests { } }; writer.setSql("SQL"); - writer.setSimpleJdbcTemplate(new SimpleJdbcTemplate(jdbcTemplate)); + writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate)); writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter() { public void setValues(String item, PreparedStatement ps) throws SQLException { list.add(item); @@ -71,11 +71,6 @@ public class JdbcBatchItemWriterClassicTests { writer.afterPropertiesSet(); } -// @After -// public void tearDown() throws Exception { -// RepeatSynchronizationManager.clear(); -// } - /** * Test method for * {@link org.springframework.batch.item.database.JdbcBatchItemWriter#afterPropertiesSet()} @@ -92,9 +87,9 @@ public class JdbcBatchItemWriterClassicTests { catch (IllegalArgumentException e) { // expected String message = e.getMessage(); - assertTrue("Message does not contain 'SimpleJdbcTemplate'.", message.indexOf("SimpleJdbcTemplate") >= 0); + assertTrue("Message does not contain ' NamedParameterJdbcTemplate'.", message.indexOf("NamedParameterJdbcTemplate") >= 0); } - writer.setSimpleJdbcTemplate(new SimpleJdbcTemplate(jdbcTemplate)); + writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate)); try { writer.afterPropertiesSet(); fail("Expected IllegalArgumentException"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java index c43430b34..f3f2f758d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; /** * @author Thomas Risberg @@ -36,7 +36,7 @@ public class JdbcBatchItemWriterNamedParameterTests { private JdbcBatchItemWriter writer = new JdbcBatchItemWriter(); - private SimpleJdbcOperations sjt; + private NamedParameterJdbcOperations namedParameterJdbcOperations; private String sql = "update foo set bar = :bar where id = :id"; @@ -70,9 +70,9 @@ public class JdbcBatchItemWriterNamedParameterTests { @Before public void setUp() throws Exception { - sjt = createMock(SimpleJdbcOperations.class); + namedParameterJdbcOperations = createMock(NamedParameterJdbcOperations.class); writer.setSql(sql); - writer.setSimpleJdbcTemplate(sjt); + writer.setJdbcTemplate(namedParameterJdbcOperations); writer.setItemSqlParameterSourceProvider( new BeanPropertyItemSqlParameterSourceProvider()); writer.afterPropertiesSet(); @@ -94,9 +94,9 @@ public class JdbcBatchItemWriterNamedParameterTests { catch (IllegalArgumentException e) { // expected String message = e.getMessage(); - assertTrue("Message does not contain 'SimpleJdbcTemplate'.", message.indexOf("SimpleJdbcTemplate") >= 0); + assertTrue("Message does not contain 'NamedParameterJdbcTemplate'.", message.indexOf("NamedParameterJdbcTemplate") >= 0); } - writer.setSimpleJdbcTemplate(sjt); + writer.setJdbcTemplate(namedParameterJdbcOperations); try { writer.afterPropertiesSet(); fail("Expected IllegalArgumentException"); @@ -123,20 +123,20 @@ public class JdbcBatchItemWriterNamedParameterTests { @Test public void testWriteAndFlush() throws Exception { - expect(sjt.batchUpdate(eq(sql), + expect(namedParameterJdbcOperations.batchUpdate(eq(sql), eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))}))) .andReturn(new int[] {1}); - replay(sjt); + replay(namedParameterJdbcOperations); writer.write(Collections.singletonList(new Foo("bar"))); - verify(sjt); + verify(namedParameterJdbcOperations); } @Test public void testWriteAndFlushWithEmptyUpdate() throws Exception { - expect(sjt.batchUpdate(eq(sql), + expect(namedParameterJdbcOperations.batchUpdate(eq(sql), eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))}))) .andReturn(new int[] {0}); - replay(sjt); + replay(namedParameterJdbcOperations); try { writer.write(Collections.singletonList(new Foo("bar"))); fail("Expected EmptyResultDataAccessException"); @@ -146,16 +146,16 @@ public class JdbcBatchItemWriterNamedParameterTests { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.indexOf("did not update") >= 0); } - verify(sjt); + verify(namedParameterJdbcOperations); } @Test public void testWriteAndFlushWithFailure() throws Exception { final RuntimeException ex = new RuntimeException("ERROR"); - expect(sjt.batchUpdate(eq(sql), + expect(namedParameterJdbcOperations.batchUpdate(eq(sql), eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))}))) .andThrow(ex); - replay(sjt); + replay(namedParameterJdbcOperations); try { writer.write(Collections.singletonList(new Foo("bar"))); fail("Expected RuntimeException"); @@ -163,7 +163,7 @@ public class JdbcBatchItemWriterNamedParameterTests { catch (RuntimeException e) { assertEquals("ERROR", e.getMessage()); } - verify(sjt); + verify(namedParameterJdbcOperations); } public static SqlParameterSource[] eqSqlParameterSourceArray(SqlParameterSource[] in) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java index f0d97782c..c33443f3c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java @@ -1,14 +1,14 @@ package org.springframework.batch.item.database; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ReaderNotOpenException; import org.springframework.batch.item.sample.Foo; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { protected ItemReader getItemReader() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java index 5c77387eb..d5e898710 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java @@ -13,7 +13,7 @@ import java.sql.ResultSet; import javax.sql.DataSource; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.jdbc.datasource.DataSourceTransactionManager; @@ -22,7 +22,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class JdbcCursorItemReaderConfigTests { /* diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java index e2481464b..f39a3f01a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java @@ -28,10 +28,10 @@ import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") @@ -61,17 +61,17 @@ public class JdbcPagingItemReaderAsyncTests { @Before public void init() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); for (int i = maxId + 1; i <= ITEM_COUNT; i++) { jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); } - assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } @After public void destroy() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java index 20346bb12..432cac21d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java @@ -9,7 +9,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.util.ReflectionTestUtils; @@ -23,8 +23,9 @@ public class JdbcPagingItemReaderConfigTests { @Test public void testConfig() { assertNotNull(jdbcPagingItemReder); - SimpleJdbcTemplate simpleJdbcTemplate = (SimpleJdbcTemplate) ReflectionTestUtils.getField(jdbcPagingItemReder, "simpleJdbcTemplate"); - JdbcTemplate jdbcTemplate = (JdbcTemplate) simpleJdbcTemplate.getJdbcOperations(); + NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) + ReflectionTestUtils.getField(jdbcPagingItemReder, "namedParameterJdbcTemplate"); + JdbcTemplate jdbcTemplate = (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations(); assertEquals(1000, jdbcTemplate.getMaxRows()); assertEquals(100, jdbcTemplate.getFetchSize()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java index 1f4055990..ca09e3893 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java @@ -25,10 +25,10 @@ import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml") @@ -56,17 +56,17 @@ public class JpaPagingItemReaderAsyncTests { @Before public void init() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS"); for (int i = maxId + 1; i <= ITEM_COUNT; i++) { jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i); } - assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); + assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } @After public void destroy() { - SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java index dd7b375e7..2cc2f2ec9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/SingleKeyFooDao.java @@ -5,9 +5,9 @@ import java.sql.SQLException; import org.springframework.batch.item.sample.Foo; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; +import org.springframework.jdbc.core.support.JdbcDaoSupport; -public class SingleKeyFooDao extends SimpleJdbcDaoSupport implements FooDao { +public class SingleKeyFooDao extends JdbcDaoSupport implements FooDao { public Foo getFoo(Object key){ diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java index fc2805dba..f23009730 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java @@ -5,7 +5,7 @@ import java.sql.SQLException; import org.hsqldb.Types; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -15,7 +15,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.SqlParameter; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { protected ItemReader getItemReader() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java index 3432a0bdd..da4b89fc5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java @@ -17,7 +17,7 @@ import javax.sql.DataSource; import org.hsqldb.Types; import org.junit.Test; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.jdbc.core.PreparedStatementSetter; @@ -28,7 +28,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class StoredprocedureItemReaderConfigTests { /* diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java index 247c74d30..d9179e59e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java @@ -2,7 +2,7 @@ package org.springframework.batch.item.file; import java.util.Comparator; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; @@ -11,7 +11,7 @@ import org.springframework.batch.item.sample.Foo; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MultiResourceItemReaderFlatFileTests extends AbstractItemStreamItemReaderTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java index 0e31b121d..38d76ac40 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java @@ -10,7 +10,7 @@ import javax.xml.transform.Source; import junit.framework.Assert; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; @@ -23,7 +23,7 @@ import org.springframework.core.io.Resource; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class MultiResourceItemReaderXmlTests extends AbstractItemStreamItemReaderTests { protected ItemReader getItemReader() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java index 73467f501..c4e828f9a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java @@ -9,7 +9,7 @@ import javax.xml.stream.events.Attribute; import javax.xml.stream.events.StartElement; import javax.xml.transform.Source; -import org.junit.internal.runners.JUnit4ClassRunner; +import org.junit.runners.JUnit4; import org.junit.runner.RunWith; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; @@ -19,7 +19,7 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; -@RunWith(JUnit4ClassRunner.class) +@RunWith(JUnit4.class) public class StaxEventItemReaderCommonTests extends AbstractItemStreamItemReaderTests { private final static String FOOS = " "; diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java index 750f303e3..0a50af87b 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java @@ -38,8 +38,8 @@ import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDa import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -64,7 +64,7 @@ public class JobRepositoryTestUtils extends AbstractJdbcBatchMetadataDao impleme }; - private SimpleJdbcOperations jdbcTemplate; + private JdbcOperations jdbcTemplate; /** * @see InitializingBean#afterPropertiesSet() @@ -94,7 +94,7 @@ public class JobRepositoryTestUtils extends AbstractJdbcBatchMetadataDao impleme } public final void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } /** @@ -193,11 +193,9 @@ public class JobRepositoryTestUtils extends AbstractJdbcBatchMetadataDao impleme * {@link JobInstance} and {@link StepExecution} instances from the standard * RDBMS locations used by Spring Batch. * - * @param list a list of {@link JobExecution} * @throws DataAccessException if there is a problem */ public void removeJobExecutions() throws DataAccessException { - jdbcTemplate.update(getQuery("delete from %PREFIX%STEP_EXECUTION_CONTEXT")); jdbcTemplate.update(getQuery("delete from %PREFIX%STEP_EXECUTION")); jdbcTemplate.update(getQuery("delete from %PREFIX%JOB_EXECUTION_CONTEXT")); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/AbstractSampleJobTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/AbstractSampleJobTests.java index ee143529d..64e08e864 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/AbstractSampleJobTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/AbstractSampleJobTests.java @@ -11,7 +11,7 @@ import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.test.sample.SampleTasklet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.Repeat; import org.springframework.test.context.ContextConfiguration; @@ -25,7 +25,7 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml" }) public abstract class AbstractSampleJobTests { - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -35,7 +35,7 @@ public abstract class AbstractSampleJobTests { private SampleTasklet tasklet2; @Autowired - public void setJdbcTemplate(SimpleJdbcTemplate jdbcTemplate) { + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java index ef3e09dd1..42b403373 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java @@ -32,10 +32,10 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.JobParametersIncrementer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; +import org.springframework.batch.support.JdbcTestUtils; /** * @author Dave Syer @@ -53,7 +53,7 @@ public class JobRepositoryTestUtilsTests { @Autowired private DataSource dataSource; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; private int beforeJobs; @@ -61,9 +61,9 @@ public class JobRepositoryTestUtilsTests { @Before public void init() { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); - beforeJobs = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION"); - beforeSteps = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION"); + jdbcTemplate = new JdbcTemplate(dataSource); + beforeJobs = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION"); + beforeSteps = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION"); } @Test(expected=IllegalArgumentException.class) @@ -84,11 +84,11 @@ public class JobRepositoryTestUtilsTests { utils = new JobRepositoryTestUtils(jobRepository, dataSource); List list = utils.createJobExecutions(3); assertEquals(3, list.size()); - assertEquals(beforeJobs + 3, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - assertEquals(beforeSteps + 3, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); + assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeSteps + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); utils.removeJobExecutions(list); - assertEquals(beforeJobs, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - assertEquals(beforeSteps, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); + assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeSteps, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); } @Test @@ -101,9 +101,9 @@ public class JobRepositoryTestUtilsTests { jobRepository.update(jobExecution); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); list.add(jobExecution); - assertEquals(beforeJobs + 2, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs + 2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); utils.removeJobExecutions(list); - assertEquals(beforeJobs, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } @Test @@ -111,11 +111,11 @@ public class JobRepositoryTestUtilsTests { utils = new JobRepositoryTestUtils(jobRepository, dataSource); List list = utils.createJobExecutions("foo",new String[] {"bar", "spam"}, 3); assertEquals(3, list.size()); - assertEquals(beforeJobs + 3, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - assertEquals(beforeSteps + 6, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); + assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeSteps + 6, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); utils.removeJobExecutions(list); - assertEquals(beforeJobs, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - assertEquals(beforeSteps, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); + assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeSteps, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); } @Test @@ -123,11 +123,11 @@ public class JobRepositoryTestUtilsTests { utils = new JobRepositoryTestUtils(jobRepository, dataSource); List list1 = utils.createJobExecutions(3); List list2 = utils.createJobExecutions(2); - assertEquals(beforeJobs + 5, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs + 5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); utils.removeJobExecutions(list2); - assertEquals(beforeJobs + 3, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); utils.removeJobExecutions(list1); - assertEquals(beforeJobs, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } @Test @@ -142,7 +142,6 @@ public class JobRepositoryTestUtilsTests { assertEquals(1, list.size()); assertEquals("bar", list.get(0).getJobInstance().getJobParameters().getString("foo")); utils.removeJobExecutions(list); - assertEquals(beforeJobs, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); + assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } - } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SampleStepTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SampleStepTests.java index 440147a22..171788e85 100755 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SampleStepTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SampleStepTests.java @@ -14,7 +14,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -23,7 +23,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class SampleStepTests implements ApplicationContextAware { @Autowired - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; private StepRunner stepRunner; diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java b/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java index b973d566f..9acd41268 100755 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java @@ -9,12 +9,12 @@ import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; public class SampleTasklet implements Tasklet { @Autowired - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; private JobExecution jobExecution; diff --git a/spring-batch-test/src/test/resources/simple-job-launcher-context.xml b/spring-batch-test/src/test/resources/simple-job-launcher-context.xml index 2d7294712..73720e8bd 100755 --- a/spring-batch-test/src/test/resources/simple-job-launcher-context.xml +++ b/spring-batch-test/src/test/resources/simple-job-launcher-context.xml @@ -9,7 +9,7 @@ - +