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 283b37071..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.simple.SimpleJdbcTemplate; +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 SimpleJdbcTemplate 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,11 +46,11 @@ public class ColumnRangePartitioner implements Partitioner { /** * The data source for connecting to the database. - * + * * @param dataSource a {@link DataSource} */ public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(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 c7c6fe96f..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,7 +22,8 @@ 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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; /** @@ -31,10 +32,10 @@ import org.springframework.util.Assert; */ public class StagingItemListener extends StepListenerSupport implements InitializingBean { - private SimpleJdbcTemplate jdbcTemplate; + private JdbcOperations 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..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,32 +5,32 @@ 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.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 SimpleJdbcOperations jdbcTemplate; + private JdbcOperations jdbcTemplate; - public void setJdbcTemplate(SimpleJdbcOperations jdbcTemplate) { + public void setJdbcTemplate(JdbcOperations 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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 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,10 +58,10 @@ public class StagingItemReader implements ItemReader keys; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcOperations 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..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,25 +16,31 @@ 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.simple.SimpleJdbcDaoSupport; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; /** * @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 NamedParameterJdbcOperations 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..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,18 +18,23 @@ 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.simple.SimpleJdbcDaoSupport; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWriter { +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 NamedParameterJdbcOperations namedParameterJdbcTemplate; + public void write(List summaries) { for (PlayerSummary summary : summaries) { @@ -42,10 +47,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..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,28 +21,28 @@ 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.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 SimpleJdbcOperations simpleJdbcTemplate; + + private JdbcOperations 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..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,7 +22,8 @@ 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.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 SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; /** * database is not expected to be setup for autoincrement @@ -54,13 +55,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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -35,21 +36,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 JdbcOperations 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 +71,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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 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 SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -56,15 +57,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 +73,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 +88,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 +106,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); } @@ -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 ac023dedb..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,7 +8,8 @@ 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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -19,23 +20,23 @@ public class FootballJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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..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.simple.SimpleJdbcTemplate; 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 SimpleJdbcTemplate simpleJdbcTemplate; + 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"; @@ -71,7 +72,7 @@ public class HibernateFailureJobFunctionalTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Autowired @@ -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); @@ -99,11 +100,11 @@ 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(); - + } /** @@ -113,8 +114,8 @@ public class HibernateFailureJobFunctionalTests { protected void validatePreConditions() throws Exception { ensureState(); creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() { - public Object doInTransaction(TransactionStatus status) { - return simpleJdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper() { + 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); } @@ -131,16 +132,16 @@ 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; } }); } - + /** * Credit was increased by CREDIT_INCREASE */ @@ -150,7 +151,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; @@ -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 68e2e07e9..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.simple.SimpleJdbcTemplate; +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,23 +44,23 @@ public class JobStepFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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..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,7 +32,8 @@ 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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mail.MailMessage; import org.springframework.mail.SimpleMailMessage; import org.springframework.test.context.ContextConfiguration; @@ -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 SimpleJdbcTemplate jdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@ -79,7 +80,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..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.simple.SimpleJdbcTemplate; +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.test.jdbc.SimpleJdbcTestUtils; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/parallelJob.xml", @@ -39,18 +40,18 @@ public class ParallelJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcOperations 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..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,14 +28,15 @@ 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.JdbcOperations; +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; /** * Simple restart scenario. - * + * * @author Robert Kasanicky * @author Dave Syer */ @@ -48,16 +49,16 @@ public class RestartFunctionalTests { private JobLauncherTestUtils jobLauncherTestUtils; // auto-injected attributes - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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"); } /** @@ -66,13 +67,13 @@ 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 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 +86,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..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.simple.SimpleJdbcTemplate; +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.test.jdbc.SimpleJdbcTestUtils; /** * 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.test.jdbc.SimpleJdbcTestUtils; @ContextConfiguration(locations = { "/skipSample-job-launcher-context.xml" }) public class SkipSampleFunctionalTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private JobExplorer jobExplorer; @@ -57,17 +58,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 +167,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 +197,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,14 +211,14 @@ 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); } /** * 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 682981d40..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 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 SimpleJdbcTemplate simpleJdbcTemplate; + + private JdbcOperations jdbcTemplate; private Map credits = new HashMap(); @Autowired @@ -61,28 +62,28 @@ 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()); } } - + @After public void tearDown() throws Exception { - simpleJdbcTemplate.update("delete from TRADE"); + jdbcTemplate.update("delete from TRADE"); } @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 - 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++); - + 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; - 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++); - + 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 039555beb..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,7 +11,8 @@ 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.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 SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; private String jobName; @@ -33,7 +34,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 +55,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..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,7 +14,8 @@ 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.JdbcOperations; +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 +31,7 @@ import org.springframework.transaction.support.TransactionTemplate; @ContextConfiguration() public class StagingItemReaderTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private PlatformTransactionManager transactionManager; @@ -45,7 +46,7 @@ public class StagingItemReaderTests { @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @BeforeTransaction @@ -60,27 +61,27 @@ 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); ProcessIndicatorItemWrapper wrapper = reader.read(); - String item = wrapper.getItem(); + String item = wrapper.getItem(); 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 +103,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 +119,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 +133,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..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,7 +29,8 @@ 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.JdbcOperations; +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 +39,14 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration public class StagingItemWriterTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations jdbcTemplate; @Autowired private StagingItemWriter writer; @Autowired public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); } @Before @@ -58,9 +59,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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 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,11 +47,11 @@ public class JdbcGameDaoIntegrationTests { private Game game = new Game(); - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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 +83,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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 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 SimpleJdbcTemplate simpleJdbcTemplate; + + private JdbcOperations jdbcTemplate; @Autowired public void init(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + this.jdbcTemplate = new JdbcTemplate(dataSource); playerDao = new JdbcPlayerDao(); - playerDao.setDataSource(dataSource); + playerDao.setDataSource(dataSource); player = new Player(); player.setId("AKFJDL00"); @@ -63,23 +64,23 @@ public class JdbcPlayerDaoIntegrationTests { player.setPosition("QB"); player.setBirthYear(1975); player.setDebutYear(1998); - + } @Before public void onSetUpInTransaction() throws Exception { - simpleJdbcTemplate.getJdbcOperations().execute("delete from PLAYERS"); + jdbcTemplate.execute("delete from PLAYERS"); } @Transactional @Test 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"); @@ -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 67868ee25..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,14 +26,15 @@ 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.JdbcOperations; +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; /** * @author Lucas Ward - * + * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/data-source-context.xml" }) @@ -43,12 +44,12 @@ public class JdbcPlayerSummaryDaoIntegrationTests { private PlayerSummary summary; - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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 +72,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 +82,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..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,7 +8,8 @@ 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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; public class ItemTrackingTradeItemWriter implements ItemWriter { @@ -16,10 +17,10 @@ public class ItemTrackingTradeItemWriter implements ItemWriter { private String writeFailureISIN; - private SimpleJdbcTemplate jdbcTemplate; + private JdbcOperations 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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -37,21 +38,21 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration() public class JdbcCustomerDebitDaoTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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)"); + //insert customer credit + jdbcTemplate.execute("INSERT INTO CUSTOMER VALUES (99, 0, 'testName', 100)"); //create customer debit CustomerDebit customerDebit = new CustomerDebit(); @@ -62,7 +63,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..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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,13 +40,13 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration(locations = {"/data-source-context.xml"}) public class JdbcTradeWriterTests { - private SimpleJdbcTemplate simpleJdbcTemplate; + private JdbcOperations 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); @@ -65,10 +66,10 @@ public class JdbcTradeWriterTests { trade.setIsin("5647238492"); trade.setPrice(new BigDecimal(Double.toString(99.69))); 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..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,7 +32,8 @@ 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.JdbcOperations; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -50,12 +51,12 @@ public class TwoJobInstancesPagingFunctionalTests { @Autowired private Job job; - - private SimpleJdbcTemplate jdbcTemplate; - + + private JdbcOperations jdbcTemplate; + @Autowired public void setDataSource(DataSource dataSource) { - jdbcTemplate = new SimpleJdbcTemplate(dataSource); + jdbcTemplate = new JdbcTemplate(dataSource); } @Test