BATCH-1891: Migrate usage of deprecated classes

This commit is contained in:
Chris Schaefer
2012-09-16 23:30:12 -04:00
committed by Dave Syer
parent b1246f99b1
commit d0e0334674
58 changed files with 282 additions and 253 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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<JobInstance> result = (List<JobInstance>) getJdbcTemplate()
.getJdbcOperations().query(getQuery(FIND_LAST_JOBS_BY_NAME),
List<JobInstance> result = (List<JobInstance>) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_BY_NAME),
new Object[] { jobName }, extractor);
return result;

View File

@@ -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
*/

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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<Map<String, Object>> jobs = simpleJdbcTemplate.queryForList(
List<Map<String, Object>> jobs = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?",
jobInstance.getId());
assertEquals(1, jobs.size());

View File

@@ -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);

View File

@@ -34,7 +34,7 @@ public class JdbcJobDaoTests extends AbstractJobDaoTests {
.addExitDescription(LONG_STRING));
jobExecutionDao.updateJobExecution(jobExecution);
List<Map<String, Object>> executions = simpleJdbcTemplate.queryForList(
List<Map<String, Object>> executions = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_JOB_EXECUTION where JOB_INSTANCE_ID=?",
jobInstance.getId());
assertEquals(1, executions.size());

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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<String> results = new ArrayList<String>();
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");
}
}

View File

@@ -136,10 +136,8 @@ public class AsyncStepScopeIntegrationTests implements BeanFactoryAware {
taskExecutor.execute(task);
}
int i = 0;
for (FutureTask<String> task : tasks) {
assertEquals("foo", task.get());
i++;
}
// Don't close the outer scope until all tasks are finished. This should

View File

@@ -30,7 +30,7 @@
<property name="stepExecutionIncrementer" ref="stepExecutionIncrementer" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
</beans>

View File

@@ -171,8 +171,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>

View File

@@ -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;
/**
* <p>{@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.</p>
*
* The user must provide an SQL query and a special callback in the for of either
@@ -62,7 +61,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
protected static final Log logger = LogFactory.getLog(JdbcBatchItemWriter.class);
private SimpleJdbcOperations simpleJdbcTemplate;
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
private ItemPreparedStatementSetter<T> itemPreparedStatementSetter;
@@ -119,17 +118,17 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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<String> namedParameters = new ArrayList<String>();
parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters);
@@ -174,10 +173,10 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, InitializingBean {
}
}
}
}
}
}

View File

@@ -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<T> extends AbstractPagingItemReader<T> 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<T> extends AbstractPagingItemReader<T> impleme
private Map<String, Object> parameterValues;
private SimpleJdbcTemplate simpleJdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private RowMapper rowMapper;
@@ -169,7 +165,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> 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<T> extends AbstractPagingItemReader<T> 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<T> extends AbstractPagingItemReader<T> 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<T> extends AbstractPagingItemReader<T> 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<T> extends AbstractPagingItemReader<T> impleme
}
}
private JdbcTemplate getJdbcTemplate() {
return (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations();
}
}

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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;
/**
* <p>
* 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
* </p>
*/
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;
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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<Foo> getItemReader() throws Exception {

View File

@@ -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);
}

View File

@@ -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<Foo> getItemReader() throws Exception {

View File

@@ -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<String>() {
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");

View File

@@ -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<Foo> writer = new JdbcBatchItemWriter<Foo>();
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<Foo>());
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) {

View File

@@ -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<Foo> getItemReader() throws Exception {

View File

@@ -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 {
/*

View File

@@ -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);
}

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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){

View File

@@ -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<Foo> getItemReader() throws Exception {

View File

@@ -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 {
/*

View File

@@ -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 {

View File

@@ -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<Foo> getItemReader() throws Exception {

View File

@@ -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 = "<foos> <foo value=\"1\"/> <foo value=\"2\"/> <foo value=\"3\"/> <foo value=\"4\"/> <foo value=\"5\"/> </foos>";

View File

@@ -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"));

View File

@@ -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;
}

View File

@@ -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<JobExecution> 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<JobExecution> 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<JobExecution> list1 = utils.createJobExecutions(3);
List<JobExecution> 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"));
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -9,7 +9,7 @@
<import resource="classpath:/data-source-context.xml" />
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>