BATCH-1928: Convert deprecated classes from the org.springframework.jdbc.core.simple package in samples
This commit is contained in:
committed by
Michael Minella
parent
a65cc58117
commit
bdece6640c
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Long, Long> 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 {
|
||||
|
||||
@@ -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<T> implements ItemProcessor<ProcessIndicatorItemWrapper<T>, 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 {
|
||||
|
||||
@@ -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<T> implements ItemReader<ProcessIndicatorItemWrap
|
||||
|
||||
private volatile Iterator<Long> 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 {
|
||||
|
||||
@@ -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<Game> {
|
||||
public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
|
||||
|
||||
private SimpleJdbcInsert insertGame;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PlayerSummary> {
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class JdbcPlayerSummaryDao implements ItemWriter<PlayerSummary> {
|
||||
|
||||
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<? extends PlayerSummary> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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++);
|
||||
|
||||
@@ -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<Customer> customers;
|
||||
private int activeRow = 0;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private Map<String, Double> credits = new HashMap<String, Double>();
|
||||
|
||||
@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<Map<String, Object>> 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<Map<String, Object>> list = jdbcTemplate.queryForList("select name, CREDIT from CUSTOMER");
|
||||
for (Map<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<BigDecimal>) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
return simpleJdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper<BigDecimal>() {
|
||||
return jdbcTemplate.query(ALL_CUSTOMERS, new ParameterizedRowMapper<BigDecimal>() {
|
||||
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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<String, Object> 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);
|
||||
}
|
||||
|
||||
@@ -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<Trade> trades;
|
||||
private int activeRow = 0;
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private Map<String, Double> credits = new HashMap<String, Double>();
|
||||
|
||||
@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<Map<String, Object>> list = simpleJdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER");
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList("select NAME, CREDIT from CUSTOMER");
|
||||
for (Map<String, Object> 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++);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<String> updater = new StagingItemProcessor<String>();
|
||||
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);
|
||||
|
||||
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Trade> {
|
||||
|
||||
@@ -16,10 +16,10 @@ public class ItemTrackingTradeItemWriter implements ItemWriter<Trade> {
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user