From bdece6640c8102da5afe919cbde3108aacc87ebd Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Mon, 10 Dec 2012 22:56:55 -0500 Subject: [PATCH 1/2] BATCH-1928: Convert deprecated classes from the org.springframework.jdbc.core.simple package in samples --- .../sample/common/ColumnRangePartitioner.java | 6 ++-- .../sample/common/StagingItemListener.java | 6 ++-- .../sample/common/StagingItemProcessor.java | 9 +++-- .../sample/common/StagingItemReader.java | 6 ++-- .../domain/football/internal/JdbcGameDao.java | 4 +-- .../football/internal/JdbcPlayerDao.java | 21 ++++++----- .../internal/JdbcPlayerSummaryDao.java | 15 +++++--- .../trade/internal/JdbcCustomerDebitDao.java | 9 +++-- .../domain/trade/internal/JdbcTradeDao.java | 8 ++--- ...positeItemWriterSampleFunctionalTests.java | 16 ++++----- .../CustomerFilterJobFunctionalTests.java | 22 ++++++------ .../sample/FootballJobFunctionalTests.java | 16 ++++----- .../HibernateFailureJobFunctionalTests.java | 16 ++++----- .../batch/sample/JobStepFunctionalTests.java | 10 +++--- .../batch/sample/MailJobFunctionalTests.java | 6 ++-- .../sample/ParallelJobFunctionalTests.java | 12 +++---- .../batch/sample/RestartFunctionalTests.java | 14 ++++---- .../sample/SkipSampleFunctionalTests.java | 36 +++++++++---------- .../batch/sample/TradeJobFunctionalTests.java | 16 ++++----- .../batch/sample/common/ErrorLogTasklet.java | 8 ++--- .../sample/common/StagingItemReaderTests.java | 26 +++++++------- .../sample/common/StagingItemWriterTests.java | 10 +++--- .../internal/JdbcGameDaoIntegrationTests.java | 8 ++--- .../JdbcPlayerDaoIntegrationTests.java | 12 +++---- .../JdbcPlayerSummaryDaoIntegrationTests.java | 10 +++--- .../internal/ItemTrackingTradeItemWriter.java | 6 ++-- .../internal/JdbcCustomerDebitDaoTests.java | 10 +++--- .../trade/internal/JdbcTradeWriterTests.java | 10 +++--- .../TwoJobInstancesPagingFunctionalTests.java | 6 ++-- 29 files changed, 181 insertions(+), 173 deletions(-) diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java index 283b37071..ea6c67fe6 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java @@ -7,7 +7,7 @@ import javax.sql.DataSource; import org.springframework.batch.core.partition.support.Partitioner; import org.springframework.batch.item.ExecutionContext; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; /** * Simple minded partitioner for a range of values of a column in a database @@ -19,7 +19,7 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; */ public class ColumnRangePartitioner implements Partitioner { - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; private String table; @@ -49,7 +49,7 @@ public class ColumnRangePartitioner implements Partitioner { * @param dataSource a {@link DataSource} */ public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java index c7c6fe96f..cab9ab84c 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java @@ -22,7 +22,7 @@ import org.springframework.batch.core.listener.StepListenerSupport; import org.springframework.batch.item.ItemReader; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -31,10 +31,10 @@ import org.springframework.util.Assert; */ public class StagingItemListener extends StepListenerSupport implements InitializingBean { - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } public final void afterPropertiesSet() throws Exception { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java index ccf23b233..831145335 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java @@ -5,8 +5,7 @@ import javax.sql.DataSource; import org.springframework.batch.item.ItemProcessor; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -23,14 +22,14 @@ import org.springframework.util.Assert; */ public class StagingItemProcessor implements ItemProcessor, T>, InitializingBean { - private SimpleJdbcOperations jdbcTemplate; + private JdbcTemplate jdbcTemplate; - public void setJdbcTemplate(SimpleJdbcOperations jdbcTemplate) { + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } public void setDataSource(DataSource dataSource) { - this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } public void afterPropertiesSet() throws Exception { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java index f40b7c1be..b6532cf32 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java @@ -35,7 +35,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -57,10 +57,10 @@ public class StagingItemReader implements ItemReader keys; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } public void destroy() throws Exception { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDao.java index bcf67aca4..6074bde1f 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDao.java @@ -22,10 +22,10 @@ import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.football.Game; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; +import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.jdbc.core.simple.SimpleJdbcInsert; -public class JdbcGameDao extends SimpleJdbcDaoSupport implements ItemWriter { +public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter { private SimpleJdbcInsert insertGame; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java index fea347d8a..14c5dd895 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java @@ -18,23 +18,28 @@ package org.springframework.batch.sample.domain.football.internal; import org.springframework.batch.sample.domain.football.Player; import org.springframework.batch.sample.domain.football.PlayerDao; -import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +import javax.sql.DataSource; /** * @author Lucas Ward * */ -public class JdbcPlayerDao extends SimpleJdbcDaoSupport implements PlayerDao { +public class JdbcPlayerDao implements PlayerDao { public static final String INSERT_PLAYER = "INSERT into PLAYERS (player_id, last_name, first_name, pos, year_of_birth, year_drafted)" + " values (:id, :lastName, :firstName, :position, :birthYear, :debutYear)"; - - public void savePlayer(Player player) { - - getSimpleJdbcTemplate().update(INSERT_PLAYER, - new BeanPropertySqlParameterSource(player)); - + + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + + public void savePlayer(Player player) { + namedParameterJdbcTemplate.update(INSERT_PLAYER, new BeanPropertySqlParameterSource(player)); } + + public void setDataSource(DataSource dataSource) { + this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java index 1db556c4a..4c6fcfe03 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java @@ -21,15 +21,19 @@ import java.util.List; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.football.PlayerSummary; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWriter { +import javax.sql.DataSource; + +public class JdbcPlayerSummaryDao implements ItemWriter { private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID, YEAR_NO, COMPLETES, ATTEMPTS, PASSING_YARDS, PASSING_TD, " + "INTERCEPTIONS, RUSHES, RUSH_YARDS, RECEPTIONS, RECEPTIONS_YARDS, TOTAL_TD) " + "values(:id, :year, :completes, :attempts, :passingYards, :passingTd, " + ":interceptions, :rushes, :rushYards, :receptions, :receptionYards, :totalTd)"; + private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + public void write(List summaries) { for (PlayerSummary summary : summaries) { @@ -42,10 +46,11 @@ public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWr summary.getReceptions()).addValue("receptionYards", summary.getReceptionYards()).addValue( "totalTd", summary.getTotalTd()); - getSimpleJdbcTemplate().update(INSERT_SUMMARY, args); - + namedParameterJdbcTemplate.update(INSERT_SUMMARY, args); } - } + public void setDataSource(DataSource dataSource) { + this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); + } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java index c3a956b41..a4840da77 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java @@ -21,8 +21,7 @@ import javax.sql.DataSource; import org.springframework.batch.sample.domain.trade.CustomerDebit; import org.springframework.batch.sample.domain.trade.CustomerDebitDao; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcOperations; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; /** @@ -34,15 +33,15 @@ public class JdbcCustomerDebitDao implements CustomerDebitDao { private static final String UPDATE_CREDIT = "UPDATE CUSTOMER SET credit= credit-? WHERE name=?"; - private SimpleJdbcOperations simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; public void write(CustomerDebit customerDebit) { - simpleJdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName()); + jdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName()); } @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java index 7ba7d373a..baed1ce33 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java @@ -22,7 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.domain.trade.TradeDao; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; @@ -41,7 +41,7 @@ public class JdbcTradeDao implements TradeDao { /** * handles the processing of sql query */ - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; /** * database is not expected to be setup for autoincrement @@ -54,13 +54,13 @@ public class JdbcTradeDao implements TradeDao { public void writeTrade(Trade trade) { Long id = incrementer.nextLongValue(); log.debug("Processing: " + trade); - simpleJdbcTemplate.update(INSERT_TRADE_RECORD, + jdbcTemplate.update(INSERT_TRADE_RECORD, id, trade.getIsin(), trade.getQuantity(), trade.getPrice(), trade.getCustomer()); } public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } public void setIncrementer(DataFieldMaxValueIncrementer incrementer) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java index 4b038499f..b4a164c0f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java @@ -19,7 +19,7 @@ import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; 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; @@ -35,21 +35,21 @@ public class CompositeItemWriterSampleFunctionalTests { + "Trade: [isin=UK21341EAH44,quantity=214,price=34.11,customer=customer4]" + "Trade: [isin=UK21341EAH45,quantity=215,price=35.11,customer=customer5]"; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test public void testJobLaunch() throws Exception { - simpleJdbcTemplate.update("DELETE from TRADE"); - int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE"); + jdbcTemplate.update("DELETE from TRADE"); + int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE"); jobLauncherTestUtils.launchJob(); @@ -70,12 +70,12 @@ public class CompositeItemWriterSampleFunctionalTests { } }; - int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE"); + int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE"); assertEquals(before + 5, after); - - simpleJdbcTemplate.getJdbcOperations().query(GET_TRADES, new RowCallbackHandler() { + + jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() { private int activeRow = 0; public void processRow(ResultSet rs) throws SQLException { Trade trade = trades.get(activeRow++); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java index 8eb2910e5..c23d884c9 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java @@ -35,7 +35,7 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.test.JobLauncherTestUtils; 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; @@ -48,7 +48,7 @@ public class CustomerFilterJobFunctionalTests { private List customers; private int activeRow = 0; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -56,15 +56,15 @@ public class CustomerFilterJobFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before public void onSetUp() throws Exception { - simpleJdbcTemplate.update("delete from TRADE"); - simpleJdbcTemplate.update("delete from CUSTOMER where ID > 4"); - simpleJdbcTemplate.update("update CUSTOMER set credit=100000"); - List> list = simpleJdbcTemplate.queryForList("select name, CREDIT from CUSTOMER"); + jdbcTemplate.update("delete from TRADE"); + jdbcTemplate.update("delete from CUSTOMER where ID > 4"); + jdbcTemplate.update("update CUSTOMER set credit=100000"); + List> list = jdbcTemplate.queryForList("select name, CREDIT from CUSTOMER"); for (Map map : list) { credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue()); } @@ -72,8 +72,8 @@ public class CustomerFilterJobFunctionalTests { @After public void tearDown() throws Exception { - simpleJdbcTemplate.update("delete from TRADE"); - simpleJdbcTemplate.update("delete from CUSTOMER where ID > 4"); + jdbcTemplate.update("delete from TRADE"); + jdbcTemplate.update("delete from CUSTOMER where ID > 4"); } @Test @@ -87,7 +87,7 @@ public class CustomerFilterJobFunctionalTests { // check content of the customer table activeRow = 0; - simpleJdbcTemplate.getJdbcOperations().query(GET_CUSTOMERS, new RowCallbackHandler() { + jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Customer customer = customers.get(activeRow++); @@ -105,7 +105,7 @@ public class CustomerFilterJobFunctionalTests { private Map getStepExecution(JobExecution jobExecution, String stepName) { Long jobExecutionId = jobExecution.getId(); - return simpleJdbcTemplate.queryForMap( + return jdbcTemplate.queryForMap( "SELECT * from BATCH_STEP_EXECUTION where JOB_EXECUTION_ID = ? and STEP_NAME = ?", jobExecutionId, stepName); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java index ac023dedb..4b3ade578 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.test.JobLauncherTestUtils; 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; @@ -19,23 +19,23 @@ public class FootballJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - 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 testLaunchJob() throws Exception { - - simpleJdbcTemplate.update("DELETE FROM PLAYERS"); - simpleJdbcTemplate.update("DELETE FROM GAMES"); - simpleJdbcTemplate.update("DELETE FROM PLAYER_SUMMARY"); + + jdbcTemplate.update("DELETE FROM PLAYERS"); + jdbcTemplate.update("DELETE FROM GAMES"); + jdbcTemplate.update("DELETE FROM PLAYER_SUMMARY"); jobLauncherTestUtils.launchJob(); - int count = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from PLAYER_SUMMARY"); + int count = jdbcTemplate.queryForInt("SELECT COUNT(*) from PLAYER_SUMMARY"); assertTrue(count > 0); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java index d3b7312d7..448e3914a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.orm.hibernate3.HibernateJdbcException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -45,7 +45,7 @@ public class HibernateFailureJobFunctionalTests { @Autowired private HibernateCreditDao writer; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; private PlatformTransactionManager transactionManager; @@ -71,7 +71,7 @@ public class HibernateFailureJobFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Autowired @@ -99,7 +99,7 @@ public class HibernateFailureJobFunctionalTests { // assertEquals(1, writer.getErrors().size()); throw e; } - int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER"); + int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER"); assertEquals(4, after); validatePostConditions(); @@ -114,7 +114,7 @@ public class HibernateFailureJobFunctionalTests { ensureState(); creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { - return simpleJdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper() { + return jdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper() { public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getBigDecimal(CREDIT_COLUMN); } @@ -131,9 +131,9 @@ public class HibernateFailureJobFunctionalTests { new TransactionTemplate(transactionManager).execute(new TransactionCallback(){ public Object doInTransaction(TransactionStatus status) { - simpleJdbcTemplate.update(DELETE_CUSTOMERS); + jdbcTemplate.update(DELETE_CUSTOMERS); for (String customer : customers) { - simpleJdbcTemplate.update(customer); + jdbcTemplate.update(customer); } return null; } @@ -150,7 +150,7 @@ public class HibernateFailureJobFunctionalTests { new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { - simpleJdbcTemplate.getJdbcOperations().query(ALL_CUSTOMERS, new RowCallbackHandler() { + jdbcTemplate.query(ALL_CUSTOMERS, new RowCallbackHandler() { private int i = 0; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java index 68e2e07e9..a3e29fb64 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java @@ -26,7 +26,7 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; 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; @@ -43,23 +43,23 @@ public class JobStepFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - 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 { - simpleJdbcTemplate.update("DELETE FROM TRADE"); + jdbcTemplate.update("DELETE FROM TRADE"); jobLauncherTestUtils.launchJob(new DefaultJobParametersConverter() .getJobParameters(PropertiesConverter .stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt"))); - int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); + int after = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); assertEquals(5, after); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java index 53c1465ca..2f9372464 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java @@ -32,7 +32,7 @@ import org.springframework.batch.sample.domain.mail.internal.TestMailErrorHandle import org.springframework.batch.sample.domain.mail.internal.TestMailSender; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mail.MailMessage; import org.springframework.mail.SimpleMailMessage; import org.springframework.test.context.ContextConfiguration; @@ -66,7 +66,7 @@ public class MailJobFunctionalTests { private static final Object[] USER8 = new Object[] { 8, "Martin Van Buren", email }; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -79,7 +79,7 @@ public class MailJobFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Before diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java index 039278aac..1e493f239 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java @@ -26,10 +26,10 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.test.JobLauncherTestUtils; 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 = { "/simple-job-launcher-context.xml", "/jobs/parallelJob.xml", @@ -39,18 +39,18 @@ public class ParallelJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Test public void testLaunchJob() throws Exception { - int before = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); + int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); JobExecution execution = jobLauncherTestUtils.launchJob(); - int after = SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); + int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING"); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(after - before, execution.getStepExecutions().iterator().next().getReadCount()); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java index 637a631fa..bab144228 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java @@ -28,7 +28,7 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; 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.context.transaction.BeforeTransaction; @@ -48,16 +48,16 @@ public class RestartFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @BeforeTransaction public void onTearDown() throws Exception { - simpleJdbcTemplate.update("DELETE FROM TRADE"); + jdbcTemplate.update("DELETE FROM TRADE"); } /** @@ -72,7 +72,7 @@ public class RestartFunctionalTests { @Test public void testLaunchJob() throws Exception { - int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); + int before = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); JobExecution jobExecution = runJobForRestartTest(); assertEquals(BatchStatus.FAILED, jobExecution.getStatus()); @@ -85,14 +85,14 @@ public class RestartFunctionalTests { throw new RuntimeException(ex); } - int medium = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); + int medium = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); // assert based on commit interval = 2 assertEquals(before + 2, medium); jobExecution = runJobForRestartTest(); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); - int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); + int after = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM TRADE"); assertEquals(before + 5, after); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java index f31bf38a5..aa03772c4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java @@ -26,11 +26,11 @@ import org.springframework.batch.sample.common.SkipCheckingListener; import org.springframework.batch.sample.domain.trade.internal.TradeWriter; 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.jdbc.support.incrementer.DataFieldMaxValueIncrementer; 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; /** * Error is encountered during writing - transaction is rolled back and the @@ -43,7 +43,7 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils; @ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" }) public class SkipSampleFunctionalTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JobExplorer jobExplorer; @@ -57,17 +57,17 @@ public class SkipSampleFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before public void setUp() { - simpleJdbcTemplate.update("DELETE from TRADE"); - simpleJdbcTemplate.update("DELETE from CUSTOMER"); + jdbcTemplate.update("DELETE from TRADE"); + jdbcTemplate.update("DELETE from CUSTOMER"); for (int i = 1; i < 10; i++) { - simpleJdbcTemplate.update("INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (" + incrementer.nextIntValue() + ", 0, 'customer" + i + "', 100000)"); + jdbcTemplate.update("INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (" + incrementer.nextIntValue() + ", 0, 'customer" + i + "', 100000)"); } - simpleJdbcTemplate.update("DELETE from ERROR_LOG"); + jdbcTemplate.update("DELETE from ERROR_LOG"); } /** @@ -166,22 +166,22 @@ public class SkipSampleFunctionalTests { private void validateLaunchWithSkips(JobExecution jobExecution) { // Step1: 9 input records, 1 skipped in read, 1 skipped in write => // 7 written to output - assertEquals(7, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "TRADE")); + assertEquals(7, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE")); // Step2: 7 input records, 1 skipped on process, 1 on write => 5 written // to output - // System.err.println(simpleJdbcTemplate.queryForList("SELECT * FROM TRADE")); - assertEquals(5, simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1)); + // System.err.println(jdbcTemplate.queryForList("SELECT * FROM TRADE")); + assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1)); // 1 record skipped in processing second step assertEquals(1, SkipCheckingListener.getProcessSkips()); // Both steps contained skips - assertEquals(2, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG")); + assertEquals(2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG")); - assertEquals("2 records were skipped!", simpleJdbcTemplate.queryForObject( + assertEquals("2 records were skipped!", jdbcTemplate.queryForObject( "SELECT MESSAGE from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", String.class, "skipJob", "step1")); - assertEquals("2 records were skipped!", simpleJdbcTemplate.queryForObject( + assertEquals("2 records were skipped!", jdbcTemplate.queryForObject( "SELECT MESSAGE from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", String.class, "skipJob", "step2")); System.err.println(jobExecution.getExecutionContext()); @@ -196,13 +196,13 @@ public class SkipSampleFunctionalTests { private void validateLaunchWithoutSkips(JobExecution jobExecution) { // Step1: 5 input records => 5 written to output - assertEquals(5, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "TRADE")); + assertEquals(5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE")); // Step2: 5 input records => 5 written to output - assertEquals(5, simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1)); + assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1)); // Neither step contained skips - assertEquals(0, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "ERROR_LOG")); + assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG")); assertEquals(new BigDecimal("270.75"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY)); @@ -210,7 +210,7 @@ public class SkipSampleFunctionalTests { private Map getStepExecutionAsMap(JobExecution jobExecution, String stepName) { long jobExecutionId = jobExecution.getId(); - return simpleJdbcTemplate.queryForMap( + return jdbcTemplate.queryForMap( "SELECT * from BATCH_STEP_EXECUTION where JOB_EXECUTION_ID = ? and STEP_NAME = ?", jobExecutionId, stepName); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java index 682981d40..e44a5d112 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java @@ -37,7 +37,7 @@ import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; 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; @@ -53,7 +53,7 @@ public class TradeJobFunctionalTests { private List trades; private int activeRow = 0; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -61,13 +61,13 @@ public class TradeJobFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before public void onSetUp() throws Exception { - simpleJdbcTemplate.update("delete from TRADE"); - List> list = simpleJdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER"); + jdbcTemplate.update("delete from TRADE"); + List> list = jdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER"); for (Map map : list) { credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue()); } @@ -75,7 +75,7 @@ public class TradeJobFunctionalTests { @After public void tearDown() throws Exception { - simpleJdbcTemplate.update("delete from TRADE"); + jdbcTemplate.update("delete from TRADE"); } @Test @@ -95,7 +95,7 @@ public class TradeJobFunctionalTests { new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4")); // check content of the trade table - simpleJdbcTemplate.getJdbcOperations().query(GET_TRADES, new RowCallbackHandler() { + jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Trade trade = trades.get(activeRow++); @@ -111,7 +111,7 @@ public class TradeJobFunctionalTests { // check content of the customer table activeRow = 0; - simpleJdbcTemplate.getJdbcOperations().query(GET_CUSTOMERS, new RowCallbackHandler() { + jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Customer customer = customers.get(activeRow++); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java index 039555beb..3e3af1550 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java @@ -11,7 +11,7 @@ import org.springframework.batch.core.StepExecutionListener; 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.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -22,7 +22,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener { protected final Log logger = LogFactory.getLog(getClass()); - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; private String jobName; @@ -33,7 +33,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener { public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Assert.notNull(this.stepName, "Step name not set. Either this class was not registered as a listener " + "or the key 'stepName' was not found in the Job's ExecutionContext."); - this.simpleJdbcTemplate.update("insert into ERROR_LOG values (?, ?, '"+getSkipCount()+" records were skipped!')", + this.jdbcTemplate.update("insert into ERROR_LOG values (?, ?, '"+getSkipCount()+" records were skipped!')", jobName, stepName); return RepeatStatus.FINISHED; } @@ -54,7 +54,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener { } public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } public void beforeStep(StepExecution stepExecution) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java index 39d0d0961..17e55c89a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java @@ -14,7 +14,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; 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.context.transaction.AfterTransaction; @@ -30,7 +30,7 @@ import org.springframework.transaction.support.TransactionTemplate; @ContextConfiguration() public class StagingItemReaderTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private PlatformTransactionManager transactionManager; @@ -45,7 +45,7 @@ public class StagingItemReaderTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @BeforeTransaction @@ -60,15 +60,15 @@ public class StagingItemReaderTests { @AfterTransaction public void onTearDownAfterTransaction() throws Exception { reader.destroy(); - simpleJdbcTemplate.update("DELETE FROM BATCH_STAGING"); + jdbcTemplate.update("DELETE FROM BATCH_STAGING"); } @Transactional @Test public void testReaderWithProcessorUpdatesProcessIndicator() throws Exception { - long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); - String before = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", + long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); + String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); assertEquals(StagingItemWriter.NEW, before); @@ -77,10 +77,10 @@ public class StagingItemReaderTests { assertEquals("FOO", item); StagingItemProcessor updater = new StagingItemProcessor(); - updater.setJdbcTemplate(simpleJdbcTemplate); + updater.setJdbcTemplate(jdbcTemplate); updater.process(wrapper); - String after = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", + String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); assertEquals(StagingItemWriter.DONE, after); @@ -102,8 +102,8 @@ public class StagingItemReaderTests { return null; } }); - long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); - String before = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", + long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); + String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); assertEquals(StagingItemWriter.DONE, before); } @@ -118,8 +118,8 @@ public class StagingItemReaderTests { final Long idToUse = (Long) txTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus transactionStatus) { - long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); - String before = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", + long id = jdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?", jobId); + String before = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, id); assertEquals(StagingItemWriter.NEW, before); @@ -132,7 +132,7 @@ public class StagingItemReaderTests { } }); - String after = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", + String after = jdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?", String.class, idToUse); assertEquals(StagingItemWriter.NEW, after); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java index c93369826..7f3dcad2a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java @@ -29,7 +29,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; 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.transaction.annotation.Transactional; @@ -38,14 +38,14 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration public class StagingItemWriterTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private StagingItemWriter writer; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before @@ -58,9 +58,9 @@ public class StagingItemWriterTests { @Transactional @Test public void testProcessInsertsNewItem() throws Exception { - int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING"); + int before = jdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING"); writer.write(Collections.singletonList("FOO")); - int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING"); + int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING"); assertEquals(before + 1, after); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java index 7548c9c40..e048302c8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.Game; 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.transaction.annotation.Transactional; @@ -46,11 +46,11 @@ public class JdbcGameDaoIntegrationTests { private Game game = new Game(); - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); gameDao = new JdbcGameDao(); gameDao.setDataSource(dataSource); gameDao.afterPropertiesSet(); @@ -82,7 +82,7 @@ public class JdbcGameDaoIntegrationTests { gameDao.write(Collections.singletonList(game)); - Game tempGame = simpleJdbcTemplate.queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?", + Game tempGame = jdbcTemplate.queryForObject("SELECT * FROM GAMES where PLAYER_ID=? AND YEAR_NO=?", new GameRowMapper(), "XXXXX00 ", game.getYear()); assertEquals(tempGame, game); } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java index 78547c77a..c2905b620 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.Player; 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; @@ -47,12 +47,12 @@ public class JdbcPlayerDaoIntegrationTests { private static final String GET_PLAYER = "SELECT * from PLAYERS"; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void init(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); playerDao = new JdbcPlayerDao(); playerDao.setDataSource(dataSource); @@ -70,7 +70,7 @@ public class JdbcPlayerDaoIntegrationTests { @Before public void onSetUpInTransaction() throws Exception { - simpleJdbcTemplate.getJdbcOperations().execute("delete from PLAYERS"); + jdbcTemplate.execute("delete from PLAYERS"); } @@ -78,8 +78,8 @@ public class JdbcPlayerDaoIntegrationTests { public void testSavePlayer(){ playerDao.savePlayer(player); - - simpleJdbcTemplate.getJdbcOperations().query(GET_PLAYER, new RowCallbackHandler(){ + + jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler(){ public void processRow(ResultSet rs) throws SQLException { assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00"); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java index 67868ee25..f590d3375 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.PlayerSummary; 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.transaction.annotation.Transactional; @@ -43,12 +43,12 @@ public class JdbcPlayerSummaryDaoIntegrationTests { private PlayerSummary summary; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void init(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); playerSummaryDao = new JdbcPlayerSummaryDao(); playerSummaryDao.setDataSource(dataSource); @@ -71,7 +71,7 @@ public class JdbcPlayerSummaryDaoIntegrationTests { @Before public void onSetUpInTransaction() throws Exception { - simpleJdbcTemplate.getJdbcOperations().execute("delete from PLAYER_SUMMARY"); + jdbcTemplate.execute("delete from PLAYER_SUMMARY"); } @@ -81,7 +81,7 @@ public class JdbcPlayerSummaryDaoIntegrationTests { playerSummaryDao.write(Collections.singletonList(summary)); - PlayerSummary testSummary = simpleJdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY", + PlayerSummary testSummary = jdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY", new PlayerSummaryMapper()); assertEquals(summary, testSummary); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java index 78eb71cf5..9b963ae8b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java @@ -8,7 +8,7 @@ import javax.sql.DataSource; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.trade.Trade; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; public class ItemTrackingTradeItemWriter implements ItemWriter { @@ -16,10 +16,10 @@ public class ItemTrackingTradeItemWriter implements ItemWriter { private String writeFailureISIN; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } public void setWriteFailureISIN(String writeFailureISIN) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java index 289e83414..a7164e2c0 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.trade.CustomerDebit; 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; @@ -37,21 +37,21 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration() public class JdbcCustomerDebitDaoTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired private JdbcCustomerDebitDao writer; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Transactional @Test public void testWrite() { //insert customer credit - simpleJdbcTemplate.getJdbcOperations().execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)"); + jdbcTemplate.execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)"); //create customer debit CustomerDebit customerDebit = new CustomerDebit(); @@ -62,7 +62,7 @@ public class JdbcCustomerDebitDaoTests { writer.write(customerDebit); //verify customer credit - simpleJdbcTemplate.getJdbcOperations().query("SELECT name, credit FROM CUSTOMER WHERE name = 'testName'", + jdbcTemplate.query("SELECT name, credit FROM CUSTOMER WHERE name = 'testName'", new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { assertEquals(95, rs.getLong("credit")); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java index 8f56cb82d..98b7bfeb4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java @@ -29,7 +29,7 @@ import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,13 +39,13 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration(locations = {"/data-source-context.xml"}) public class JdbcTradeWriterTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcTemplate jdbcTemplate; private JdbcTradeDao writer; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); this.writer = new JdbcTradeDao(); this.writer.setDataSource(dataSource); @@ -67,8 +67,8 @@ public class JdbcTradeWriterTests { trade.setQuantity(5); writer.writeTrade(trade); - - simpleJdbcTemplate.getJdbcOperations().query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", new RowCallbackHandler() { + + jdbcTemplate.query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { assertEquals("testCustomer", rs.getString("CUSTOMER")); assertEquals(new BigDecimal(Double.toString(99.69)), rs.getBigDecimal("PRICE")); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java index 2b7f65f99..a6442cc7b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java @@ -32,7 +32,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; @@ -51,11 +51,11 @@ public class TwoJobInstancesPagingFunctionalTests { @Autowired private Job job; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Test From 40975b65486da95a3fd4915fbc449169340abc94 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Mon, 17 Dec 2012 09:16:30 -0600 Subject: [PATCH 2/2] BATCH-1928: Converted to using JdbcOperations over JdbcTemplate --- .../batch/support/JdbcTestUtils.java | 6 +-- .../sample/common/ColumnRangePartitioner.java | 15 ++++--- .../sample/common/StagingItemListener.java | 5 ++- .../sample/common/StagingItemProcessor.java | 11 ++--- .../sample/common/StagingItemReader.java | 9 ++-- .../football/internal/JdbcPlayerDao.java | 9 ++-- .../internal/JdbcPlayerSummaryDao.java | 9 ++-- .../trade/internal/JdbcCustomerDebitDao.java | 11 ++--- .../domain/trade/internal/JdbcTradeDao.java | 5 ++- ...positeItemWriterSampleFunctionalTests.java | 5 ++- .../CustomerFilterJobFunctionalTests.java | 13 +++--- .../sample/FootballJobFunctionalTests.java | 3 +- .../HibernateFailureJobFunctionalTests.java | 27 +++++------ .../batch/sample/JobStepFunctionalTests.java | 9 ++-- .../batch/sample/MailJobFunctionalTests.java | 7 +-- .../sample/ParallelJobFunctionalTests.java | 7 +-- .../batch/sample/RestartFunctionalTests.java | 9 ++-- .../sample/SkipSampleFunctionalTests.java | 11 ++--- .../batch/sample/TradeJobFunctionalTests.java | 45 ++++++++++--------- .../batch/sample/common/ErrorLogTasklet.java | 3 +- .../sample/common/StagingItemReaderTests.java | 7 +-- .../sample/common/StagingItemWriterTests.java | 5 ++- .../internal/JdbcGameDaoIntegrationTests.java | 9 ++-- .../JdbcPlayerDaoIntegrationTests.java | 21 ++++----- .../JdbcPlayerSummaryDaoIntegrationTests.java | 7 +-- .../internal/ItemTrackingTradeItemWriter.java | 3 +- .../internal/JdbcCustomerDebitDaoTests.java | 9 ++-- .../trade/internal/JdbcTradeWriterTests.java | 9 ++-- .../TwoJobInstancesPagingFunctionalTests.java | 9 ++-- 29 files changed, 164 insertions(+), 134 deletions(-) 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 index ecf99bf28..4662f2fec 100644 --- 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 @@ -2,7 +2,7 @@ package org.springframework.batch.support; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.JdbcOperations; /** *

@@ -25,7 +25,7 @@ public final class JdbcTestUtils { * @param tableName table name to count rows in * @return the number of rows in the table */ - public static int countRowsInTable(JdbcTemplate jdbcTemplate, String tableName) { + public static int countRowsInTable(JdbcOperations jdbcTemplate, String tableName) { return jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName); } @@ -35,7 +35,7 @@ public final class JdbcTestUtils { * @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) { + public static int deleteFromTables(JdbcOperations jdbcTemplate, String... tableNames) { int totalRowCount = 0; for (String tableName : tableNames) { int rowCount = jdbcTemplate.update("DELETE FROM " + tableName); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java index ea6c67fe6..dd9c11e6e 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/ColumnRangePartitioner.java @@ -7,19 +7,20 @@ import javax.sql.DataSource; import org.springframework.batch.core.partition.support.Partitioner; import org.springframework.batch.item.ExecutionContext; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; /** * Simple minded partitioner for a range of values of a column in a database * table. Works best if the values are uniformly distributed (e.g. * auto-generated primary key values). - * + * * @author Dave Syer - * + * */ public class ColumnRangePartitioner implements Partitioner { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; private String table; @@ -27,7 +28,7 @@ public class ColumnRangePartitioner implements Partitioner { /** * The name of the SQL table the data are in. - * + * * @param table the name of the table */ public void setTable(String table) { @@ -36,7 +37,7 @@ public class ColumnRangePartitioner implements Partitioner { /** * The name of the column to partition. - * + * * @param column the column name. */ public void setColumn(String column) { @@ -45,7 +46,7 @@ public class ColumnRangePartitioner implements Partitioner { /** * The data source for connecting to the database. - * + * * @param dataSource a {@link DataSource} */ public void setDataSource(DataSource dataSource) { @@ -57,7 +58,7 @@ public class ColumnRangePartitioner implements Partitioner { * are uniformly distributed. The execution context values will have keys * minValue and maxValue specifying the range of * values to consider in each partition. - * + * * @see Partitioner#partition(int) */ public Map partition(int gridSize) { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java index cab9ab84c..e4012611b 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.springframework.batch.core.listener.StepListenerSupport; import org.springframework.batch.item.ItemReader; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; @@ -31,7 +32,7 @@ import org.springframework.util.Assert; */ public class StagingItemListener extends StepListenerSupport implements InitializingBean { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java index 831145335..3bf84b234 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemProcessor.java @@ -5,26 +5,27 @@ import javax.sql.DataSource; import org.springframework.batch.item.ItemProcessor; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** * Marks the input row as 'processed'. (This change will rollback if there is * problem later) - * + * * @param item type - * + * * @see StagingItemReader * @see StagingItemWriter * @see ProcessIndicatorItemWrapper - * + * * @author Robert Kasanicky */ public class StagingItemProcessor implements ItemProcessor, T>, InitializingBean { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; - public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + public void setJdbcTemplate(JdbcOperations jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java index b6532cf32..757033fbc 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,14 +34,15 @@ import org.springframework.batch.support.SerializationUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.util.Assert; /** * Thread-safe database {@link ItemReader} implementing the process indicator * pattern. - * + * * To achieve restartability use together with {@link StagingItemProcessor}. */ public class StagingItemReader implements ItemReader>, StepExecutionListener, @@ -57,7 +58,7 @@ public class StagingItemReader implements ItemReader keys; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java index 14c5dd895..b406ed006 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,14 @@ package org.springframework.batch.sample.domain.football.internal; +import javax.sql.DataSource; + import org.springframework.batch.sample.domain.football.Player; import org.springframework.batch.sample.domain.football.PlayerDao; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import javax.sql.DataSource; - /** * @author Lucas Ward * @@ -33,7 +34,7 @@ public class JdbcPlayerDao implements PlayerDao { "INSERT into PLAYERS (player_id, last_name, first_name, pos, year_of_birth, year_drafted)" + " values (:id, :lastName, :firstName, :position, :birthYear, :debutYear)"; - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + private NamedParameterJdbcOperations namedParameterJdbcTemplate; public void savePlayer(Player player) { namedParameterJdbcTemplate.update(INSERT_PLAYER, new BeanPropertySqlParameterSource(player)); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java index 4c6fcfe03..f3ca7b1ad 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,14 @@ package org.springframework.batch.sample.domain.football.internal; import java.util.List; +import javax.sql.DataSource; + import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.football.PlayerSummary; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import javax.sql.DataSource; - public class JdbcPlayerSummaryDao implements ItemWriter { private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID, YEAR_NO, COMPLETES, ATTEMPTS, PASSING_YARDS, PASSING_TD, " @@ -32,7 +33,7 @@ public class JdbcPlayerSummaryDao implements ItemWriter { + "values(:id, :year, :completes, :attempts, :passingYards, :passingTd, " + ":interceptions, :rushes, :rushYards, :receptions, :receptionYards, :totalTd)"; - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + private NamedParameterJdbcOperations namedParameterJdbcTemplate; public void write(List summaries) { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java index a4840da77..efda0ab1b 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,20 @@ import javax.sql.DataSource; import org.springframework.batch.sample.domain.trade.CustomerDebit; import org.springframework.batch.sample.domain.trade.CustomerDebitDao; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; /** * Reduces customer's credit by the provided amount. - * + * * @author Robert Kasanicky */ public class JdbcCustomerDebitDao implements CustomerDebitDao { - + private static final String UPDATE_CREDIT = "UPDATE CUSTOMER SET credit= credit-? WHERE name=?"; - - private JdbcTemplate jdbcTemplate; + + private JdbcOperations jdbcTemplate; public void write(CustomerDebit customerDebit) { jdbcTemplate.update(UPDATE_CREDIT, customerDebit.getDebit(), customerDebit.getName()); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java index baed1ce33..3b68f97b5 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.sample.domain.trade.TradeDao; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; @@ -41,7 +42,7 @@ public class JdbcTradeDao implements TradeDao { /** * handles the processing of sql query */ - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; /** * database is not expected to be setup for autoincrement diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java index b4a164c0f..37f42a5c7 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java @@ -18,8 +18,9 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -35,7 +36,7 @@ public class CompositeItemWriterSampleFunctionalTests { + "Trade: [isin=UK21341EAH44,quantity=214,price=34.11,customer=customer4]" + "Trade: [isin=UK21341EAH45,quantity=215,price=35.11,customer=customer5]"; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java index c23d884c9..afea2890f 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,9 @@ import org.junit.runner.RunWith; import org.springframework.batch.core.JobExecution; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -48,7 +49,7 @@ public class CustomerFilterJobFunctionalTests { private List customers; private int activeRow = 0; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -135,9 +136,10 @@ public class CustomerFilterJobFunctionalTests { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ + @Override public int hashCode() { final int PRIME = 31; int result = 1; @@ -150,9 +152,10 @@ public class CustomerFilterJobFunctionalTests { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ + @Override public boolean equals(Object obj) { if (this == obj) return true; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java index 4b3ade578..1bdd75935 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FootballJobFunctionalTests.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -19,7 +20,7 @@ public class FootballJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java index 448e3914a..2f1222935 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/HibernateFailureJobFunctionalTests.java @@ -20,9 +20,10 @@ import org.springframework.batch.sample.domain.trade.internal.HibernateCreditDao import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.UncategorizedSQLException; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.orm.hibernate3.HibernateJdbcException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -34,7 +35,7 @@ import org.springframework.transaction.support.TransactionTemplate; /** * Test for HibernateJob - checks that customer credit has been updated to * expected value. - * + * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) @@ -45,17 +46,17 @@ public class HibernateFailureJobFunctionalTests { @Autowired private HibernateCreditDao writer; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; private PlatformTransactionManager transactionManager; private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT; - + private static String[] customers = { "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)", "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)", "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)", "INSERT INTO CUSTOMER (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"}; - + private static String DELETE_CUSTOMERS = "DELETE FROM CUSTOMER"; private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID"; @@ -81,9 +82,9 @@ public class HibernateFailureJobFunctionalTests { @Test public void testLaunchJob() throws Exception { - + validatePreConditions(); - + JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters(); writer.setFailOnFlush(2); @@ -101,9 +102,9 @@ public class HibernateFailureJobFunctionalTests { } int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from CUSTOMER"); assertEquals(4, after); - + validatePostConditions(); - + } /** @@ -113,7 +114,7 @@ public class HibernateFailureJobFunctionalTests { protected void validatePreConditions() throws Exception { ensureState(); creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() { - public Object doInTransaction(TransactionStatus status) { + public Object doInTransaction(TransactionStatus status) { return jdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper() { public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getBigDecimal(CREDIT_COLUMN); @@ -140,7 +141,7 @@ public class HibernateFailureJobFunctionalTests { }); } - + /** * Credit was increased by CREDIT_INCREASE */ @@ -161,13 +162,13 @@ public class HibernateFailureJobFunctionalTests { matches.add(rs.getBigDecimal(ID_COLUMN)); } } - + }); return null; } }); assertEquals((creditsBeforeUpdate.size() - 1), matches.size()); - assertFalse(matches.contains(new BigDecimal(2))); + assertFalse(matches.contains(new BigDecimal(2))); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java index a3e29fb64..d787b9491 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobStepFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,14 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Sample using a step to launch a job. - * + * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) @@ -43,7 +44,7 @@ public class JobStepFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { @@ -54,7 +55,7 @@ public class JobStepFunctionalTests { public void testJobLaunch() throws Exception { jdbcTemplate.update("DELETE FROM TRADE"); - + jobLauncherTestUtils.launchJob(new DefaultJobParametersConverter() .getJobParameters(PropertiesConverter .stringToProperties("run.id(long)=1,parameter=true,run.date=20070122,input.file=classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt"))); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java index 2f9372464..1d0cdfdfd 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MailJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.batch.sample.domain.mail.internal.TestMailErrorHandle import org.springframework.batch.sample.domain.mail.internal.TestMailSender; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mail.MailMessage; import org.springframework.mail.SimpleMailMessage; @@ -41,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dan Garrette * @author Dave Syer - * + * * @Since 2.1 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -66,7 +67,7 @@ public class MailJobFunctionalTests { private static final Object[] USER8 = new Object[] { 8, "Martin Van Buren", email }; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java index 1e493f239..039fea8da 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/ParallelJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,12 +24,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; +import org.springframework.batch.support.JdbcTestUtils; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.batch.support.JdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/parallelJob.xml", @@ -39,7 +40,7 @@ public class ParallelJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java index bab144228..47b4557b2 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RestartFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.support.PropertiesConverter; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -35,7 +36,7 @@ import org.springframework.test.context.transaction.BeforeTransaction; /** * Simple restart scenario. - * + * * @author Robert Kasanicky * @author Dave Syer */ @@ -48,7 +49,7 @@ public class RestartFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { @@ -66,7 +67,7 @@ public class RestartFunctionalTests { * finish successfully, because it continues execution where the previous * run stopped (module throws exception after fixed number of processed * records). - * + * * @throws Exception */ @Test diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java index aa03772c4..dfdc17135 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/SkipSampleFunctionalTests.java @@ -24,18 +24,19 @@ import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep import org.springframework.batch.core.repository.JobRestartException; import org.springframework.batch.sample.common.SkipCheckingListener; import org.springframework.batch.sample.domain.trade.internal.TradeWriter; +import org.springframework.batch.support.JdbcTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.batch.support.JdbcTestUtils; /** * Error is encountered during writing - transaction is rolled back and the * error item is skipped on second attempt to process the chunk. - * + * * @author Robert Kasanicky * @author Dan Garrette */ @@ -43,7 +44,7 @@ import org.springframework.batch.support.JdbcTestUtils; @ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" }) public class SkipSampleFunctionalTests { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JobExplorer jobExplorer; @@ -172,7 +173,7 @@ public class SkipSampleFunctionalTests { // to output // System.err.println(jdbcTemplate.queryForList("SELECT * FROM TRADE")); assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1)); - + // 1 record skipped in processing second step assertEquals(1, SkipCheckingListener.getProcessSkips()); @@ -217,7 +218,7 @@ public class SkipSampleFunctionalTests { /** * Launch the entire job, including all steps, in order. - * + * * @return JobExecution, so that the test may validate the exit status */ public long launchJobWithIncrementer() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java index e44a5d112..354d924c8 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/TradeJobFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,9 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -48,12 +49,12 @@ public class TradeJobFunctionalTests { private static final String GET_TRADES = "select ISIN, QUANTITY, PRICE, CUSTOMER, ID, VERSION from TRADE order by ISIN"; private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME"; - + private List customers; private List trades; private int activeRow = 0; - - private JdbcTemplate jdbcTemplate; + + private JdbcOperations jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -63,7 +64,7 @@ public class TradeJobFunctionalTests { public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } - + @Before public void onSetUp() throws Exception { jdbcTemplate.update("delete from TRADE"); @@ -72,7 +73,7 @@ public class TradeJobFunctionalTests { credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue()); } } - + @After public void tearDown() throws Exception { jdbcTemplate.update("delete from TRADE"); @@ -80,9 +81,9 @@ public class TradeJobFunctionalTests { @Test public void testLaunchJob() throws Exception { - + jobLauncherTestUtils.launchJob(); - + customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)), new Customer("customer2", (credits.get("customer2") - 18.12 - 12.78)), new Customer("customer3", (credits.get("customer3") - 109.25)), @@ -93,48 +94,48 @@ public class TradeJobFunctionalTests { new Trade("UK21341EAH47", 245, new BigDecimal("12.78"), "customer2"), new Trade("UK21341EAH48", 108, new BigDecimal("109.25"), "customer3"), new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4")); - + // check content of the trade table jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Trade trade = trades.get(activeRow++); - + assertTrue(trade.getIsin().equals(rs.getString(1))); assertTrue(trade.getQuantity() == rs.getLong(2)); assertTrue(trade.getPrice().equals(rs.getBigDecimal(3))); assertTrue(trade.getCustomer().equals(rs.getString(4))); } }); - + assertEquals(activeRow, trades.size()); - + // check content of the customer table activeRow = 0; jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Customer customer = customers.get(activeRow++); - + assertEquals(customer.getName(),rs.getString(1)); assertEquals(customer.getCredit(), rs.getDouble(2), .01); } }); - + assertEquals(customers.size(), activeRow); - + // check content of the output file } private static class Customer { private String name; private double credit; - + public Customer(String name, double credit) { this.name = name; this.credit = credit; } - + /** * @return the credit */ @@ -178,9 +179,9 @@ public class TradeJobFunctionalTests { return false; return true; } - - + + } - - + + } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java index 3e3af1550..762014af1 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/ErrorLogTasklet.java @@ -11,6 +11,7 @@ import org.springframework.batch.core.StepExecutionListener; 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.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; @@ -22,7 +23,7 @@ public class ErrorLogTasklet implements Tasklet, StepExecutionListener { protected final Log logger = LogFactory.getLog(getClass()); - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; private String jobName; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java index 17e55c89a..11097c01a 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemReaderTests.java @@ -14,6 +14,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -30,7 +31,7 @@ import org.springframework.transaction.support.TransactionTemplate; @ContextConfiguration() public class StagingItemReaderTests { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private PlatformTransactionManager transactionManager; @@ -73,9 +74,9 @@ public class StagingItemReaderTests { assertEquals(StagingItemWriter.NEW, before); ProcessIndicatorItemWrapper wrapper = reader.read(); - String item = wrapper.getItem(); + String item = wrapper.getItem(); assertEquals("FOO", item); - + StagingItemProcessor updater = new StagingItemProcessor(); updater.setJdbcTemplate(jdbcTemplate); updater.process(wrapper); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java index 7f3dcad2a..f67f2402b 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -38,7 +39,7 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration public class StagingItemWriterTests { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private StagingItemWriter writer; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java index e048302c8..de6a8020d 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcGameDaoIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,15 +28,16 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.Game; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; /** * @author Lucas Ward - * + * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/data-source-context.xml"}) @@ -46,7 +47,7 @@ public class JdbcGameDaoIntegrationTests { private Game game = new Game(); - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java index c2905b620..2730acdee 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerDaoIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.Player; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -40,21 +41,21 @@ import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/data-source-context.xml"}) public class JdbcPlayerDaoIntegrationTests { - + private JdbcPlayerDao playerDao; private Player player; private static final String GET_PLAYER = "SELECT * from PLAYERS"; - - private JdbcTemplate jdbcTemplate; + + private JdbcOperations jdbcTemplate; @Autowired public void init(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); playerDao = new JdbcPlayerDao(); - playerDao.setDataSource(dataSource); + playerDao.setDataSource(dataSource); player = new Player(); player.setId("AKFJDL00"); @@ -63,7 +64,7 @@ public class JdbcPlayerDaoIntegrationTests { player.setPosition("QB"); player.setBirthYear(1975); player.setDebutYear(1998); - + } @@ -76,7 +77,7 @@ public class JdbcPlayerDaoIntegrationTests { @Transactional @Test public void testSavePlayer(){ - + playerDao.savePlayer(player); jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler(){ @@ -88,8 +89,8 @@ public class JdbcPlayerDaoIntegrationTests { assertEquals(rs.getString("POS"), "QB"); assertEquals(rs.getInt("YEAR_OF_BIRTH"), 1975); assertEquals(rs.getInt("YEAR_DRAFTED"), 1998); - } + } }); } - + } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java index f590d3375..04ca13dff 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/football/internal/JdbcPlayerSummaryDaoIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.football.PlayerSummary; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -33,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Lucas Ward - * + * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/data-source-context.xml" }) @@ -43,7 +44,7 @@ public class JdbcPlayerSummaryDaoIntegrationTests { private PlayerSummary summary; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired public void init(DataSource dataSource) { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java index 9b963ae8b..992e2fc36 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/ItemTrackingTradeItemWriter.java @@ -8,6 +8,7 @@ import javax.sql.DataSource; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.sample.domain.trade.Trade; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; public class ItemTrackingTradeItemWriter implements ItemWriter { @@ -16,7 +17,7 @@ public class ItemTrackingTradeItemWriter implements ItemWriter { private String writeFailureISIN; - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java index a7164e2c0..794e496b4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDebitDaoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.trade.CustomerDebit; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -37,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration() public class JdbcCustomerDebitDaoTests { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JdbcCustomerDebitDao writer; @@ -50,7 +51,7 @@ public class JdbcCustomerDebitDaoTests { @Transactional @Test public void testWrite() { - //insert customer credit + //insert customer credit jdbcTemplate.execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)"); //create customer debit diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java index 98b7bfeb4..d1ce736cc 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,9 @@ import org.junit.runner.RunWith; import org.springframework.batch.sample.domain.trade.Trade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,7 +40,7 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration(locations = {"/data-source-context.xml"}) public class JdbcTradeWriterTests { - private JdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; private JdbcTradeDao writer; @@ -65,7 +66,7 @@ public class JdbcTradeWriterTests { trade.setIsin("5647238492"); trade.setPrice(new BigDecimal(Double.toString(99.69))); trade.setQuantity(5); - + writer.writeTrade(trade); jdbcTemplate.query("SELECT * FROM TRADE WHERE ISIN = '5647238492'", new RowCallbackHandler() { diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java index a6442cc7b..8b0d7cef3 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/TwoJobInstancesPagingFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,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.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -50,9 +51,9 @@ public class TwoJobInstancesPagingFunctionalTests { @Autowired private Job job; - - private JdbcTemplate jdbcTemplate; - + + private JdbcOperations jdbcTemplate; + @Autowired public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource);