BATCH-1891: Migrate usage of deprecated classes

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

View File

@@ -16,7 +16,7 @@ import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -35,12 +35,12 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
protected DataSource dataSource;
protected SimpleJdbcTemplate simpleJdbcTemplate;
protected JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Before

View File

@@ -21,7 +21,7 @@ import java.util.logging.Logger;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@@ -33,7 +33,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class ExtendedConnectionDataSourceProxyTests {
@Test

View File

@@ -8,9 +8,9 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
import org.junit.runner.RunWith;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class HibernateCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
protected ItemReader<Foo> getItemReader() throws Exception {

View File

@@ -24,13 +24,13 @@ import org.junit.runner.RunWith;
import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import com.ibatis.sqlmap.client.SqlMapClient;
import org.springframework.batch.support.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml")
@@ -55,17 +55,17 @@ public class IbatisPagingItemReaderAsyncTests {
@Before
public void init() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
for (int i = maxId + 1; i <= ITEM_COUNT; i++) {
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
}
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
}
@After
public void destroy() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
}

View File

@@ -1,6 +1,6 @@
package org.springframework.batch.item.database;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
@@ -10,7 +10,7 @@ import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
import com.ibatis.sqlmap.client.SqlMapClient;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
protected ItemReader<Foo> getItemReader() throws Exception {

View File

@@ -31,7 +31,7 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
/**
* @author Dave Syer
@@ -62,7 +62,7 @@ public class JdbcBatchItemWriterClassicTests {
}
};
writer.setSql("SQL");
writer.setSimpleJdbcTemplate(new SimpleJdbcTemplate(jdbcTemplate));
writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate));
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<String>() {
public void setValues(String item, PreparedStatement ps) throws SQLException {
list.add(item);
@@ -71,11 +71,6 @@ public class JdbcBatchItemWriterClassicTests {
writer.afterPropertiesSet();
}
// @After
// public void tearDown() throws Exception {
// RepeatSynchronizationManager.clear();
// }
/**
* Test method for
* {@link org.springframework.batch.item.database.JdbcBatchItemWriter#afterPropertiesSet()}
@@ -92,9 +87,9 @@ public class JdbcBatchItemWriterClassicTests {
catch (IllegalArgumentException e) {
// expected
String message = e.getMessage();
assertTrue("Message does not contain 'SimpleJdbcTemplate'.", message.indexOf("SimpleJdbcTemplate") >= 0);
assertTrue("Message does not contain ' NamedParameterJdbcTemplate'.", message.indexOf("NamedParameterJdbcTemplate") >= 0);
}
writer.setSimpleJdbcTemplate(new SimpleJdbcTemplate(jdbcTemplate));
writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate));
try {
writer.afterPropertiesSet();
fail("Expected IllegalArgumentException");

View File

@@ -27,7 +27,7 @@ import org.junit.Test;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
/**
* @author Thomas Risberg
@@ -36,7 +36,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
private JdbcBatchItemWriter<Foo> writer = new JdbcBatchItemWriter<Foo>();
private SimpleJdbcOperations sjt;
private NamedParameterJdbcOperations namedParameterJdbcOperations;
private String sql = "update foo set bar = :bar where id = :id";
@@ -70,9 +70,9 @@ public class JdbcBatchItemWriterNamedParameterTests {
@Before
public void setUp() throws Exception {
sjt = createMock(SimpleJdbcOperations.class);
namedParameterJdbcOperations = createMock(NamedParameterJdbcOperations.class);
writer.setSql(sql);
writer.setSimpleJdbcTemplate(sjt);
writer.setJdbcTemplate(namedParameterJdbcOperations);
writer.setItemSqlParameterSourceProvider(
new BeanPropertyItemSqlParameterSourceProvider<Foo>());
writer.afterPropertiesSet();
@@ -94,9 +94,9 @@ public class JdbcBatchItemWriterNamedParameterTests {
catch (IllegalArgumentException e) {
// expected
String message = e.getMessage();
assertTrue("Message does not contain 'SimpleJdbcTemplate'.", message.indexOf("SimpleJdbcTemplate") >= 0);
assertTrue("Message does not contain 'NamedParameterJdbcTemplate'.", message.indexOf("NamedParameterJdbcTemplate") >= 0);
}
writer.setSimpleJdbcTemplate(sjt);
writer.setJdbcTemplate(namedParameterJdbcOperations);
try {
writer.afterPropertiesSet();
fail("Expected IllegalArgumentException");
@@ -123,20 +123,20 @@ public class JdbcBatchItemWriterNamedParameterTests {
@Test
public void testWriteAndFlush() throws Exception {
expect(sjt.batchUpdate(eq(sql),
expect(namedParameterJdbcOperations.batchUpdate(eq(sql),
eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))})))
.andReturn(new int[] {1});
replay(sjt);
replay(namedParameterJdbcOperations);
writer.write(Collections.singletonList(new Foo("bar")));
verify(sjt);
verify(namedParameterJdbcOperations);
}
@Test
public void testWriteAndFlushWithEmptyUpdate() throws Exception {
expect(sjt.batchUpdate(eq(sql),
expect(namedParameterJdbcOperations.batchUpdate(eq(sql),
eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))})))
.andReturn(new int[] {0});
replay(sjt);
replay(namedParameterJdbcOperations);
try {
writer.write(Collections.singletonList(new Foo("bar")));
fail("Expected EmptyResultDataAccessException");
@@ -146,16 +146,16 @@ public class JdbcBatchItemWriterNamedParameterTests {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.indexOf("did not update") >= 0);
}
verify(sjt);
verify(namedParameterJdbcOperations);
}
@Test
public void testWriteAndFlushWithFailure() throws Exception {
final RuntimeException ex = new RuntimeException("ERROR");
expect(sjt.batchUpdate(eq(sql),
expect(namedParameterJdbcOperations.batchUpdate(eq(sql),
eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))})))
.andThrow(ex);
replay(sjt);
replay(namedParameterJdbcOperations);
try {
writer.write(Collections.singletonList(new Foo("bar")));
fail("Expected RuntimeException");
@@ -163,7 +163,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
catch (RuntimeException e) {
assertEquals("ERROR", e.getMessage());
}
verify(sjt);
verify(namedParameterJdbcOperations);
}
public static SqlParameterSource[] eqSqlParameterSourceArray(SqlParameterSource[] in) {

View File

@@ -1,14 +1,14 @@
package org.springframework.batch.item.database;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ReaderNotOpenException;
import org.springframework.batch.item.sample.Foo;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
protected ItemReader<Foo> getItemReader() throws Exception {

View File

@@ -13,7 +13,7 @@ import java.sql.ResultSet;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@@ -22,7 +22,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class JdbcCursorItemReaderConfigTests {
/*

View File

@@ -28,10 +28,10 @@ import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import org.springframework.batch.support.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml")
@@ -61,17 +61,17 @@ public class JdbcPagingItemReaderAsyncTests {
@Before
public void init() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
for (int i = maxId + 1; i <= ITEM_COUNT; i++) {
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
}
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
}
@After
public void destroy() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
}

View File

@@ -9,7 +9,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.util.ReflectionTestUtils;
@@ -23,8 +23,9 @@ public class JdbcPagingItemReaderConfigTests {
@Test
public void testConfig() {
assertNotNull(jdbcPagingItemReder);
SimpleJdbcTemplate simpleJdbcTemplate = (SimpleJdbcTemplate) ReflectionTestUtils.getField(jdbcPagingItemReder, "simpleJdbcTemplate");
JdbcTemplate jdbcTemplate = (JdbcTemplate) simpleJdbcTemplate.getJdbcOperations();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate)
ReflectionTestUtils.getField(jdbcPagingItemReder, "namedParameterJdbcTemplate");
JdbcTemplate jdbcTemplate = (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations();
assertEquals(1000, jdbcTemplate.getMaxRows());
assertEquals(100, jdbcTemplate.getFetchSize());
}

View File

@@ -25,10 +25,10 @@ import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import org.springframework.batch.support.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml")
@@ -56,17 +56,17 @@ public class JpaPagingItemReaderAsyncTests {
@Before
public void init() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
maxId = jdbcTemplate.queryForInt("SELECT MAX(ID) from T_FOOS");
for (int i = maxId + 1; i <= ITEM_COUNT; i++) {
jdbcTemplate.update("INSERT into T_FOOS (ID,NAME,VALUE) values (?, ?, ?)", i, "foo" + i, i);
}
assertEquals(ITEM_COUNT, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
}
@After
public void destroy() {
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
}

View File

@@ -5,9 +5,9 @@ import java.sql.SQLException;
import org.springframework.batch.item.sample.Foo;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class SingleKeyFooDao extends SimpleJdbcDaoSupport implements FooDao {
public class SingleKeyFooDao extends JdbcDaoSupport implements FooDao {
public Foo getFoo(Object key){

View File

@@ -5,7 +5,7 @@ import java.sql.SQLException;
import org.hsqldb.Types;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
@@ -15,7 +15,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.SqlParameter;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
protected ItemReader<Foo> getItemReader() throws Exception {

View File

@@ -17,7 +17,7 @@ import javax.sql.DataSource;
import org.hsqldb.Types;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.jdbc.core.PreparedStatementSetter;
@@ -28,7 +28,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class StoredprocedureItemReaderConfigTests {
/*

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.item.file;
import java.util.Comparator;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.AbstractItemStreamItemReaderTests;
import org.springframework.batch.item.ExecutionContext;
@@ -11,7 +11,7 @@ import org.springframework.batch.item.sample.Foo;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MultiResourceItemReaderFlatFileTests extends
AbstractItemStreamItemReaderTests {

View File

@@ -10,7 +10,7 @@ import javax.xml.transform.Source;
import junit.framework.Assert;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.AbstractItemStreamItemReaderTests;
import org.springframework.batch.item.ExecutionContext;
@@ -23,7 +23,7 @@ import org.springframework.core.io.Resource;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.XmlMappingException;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MultiResourceItemReaderXmlTests extends AbstractItemStreamItemReaderTests {
protected ItemReader<Foo> getItemReader() throws Exception {

View File

@@ -9,7 +9,7 @@ import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.transform.Source;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.item.AbstractItemStreamItemReaderTests;
import org.springframework.batch.item.ExecutionContext;
@@ -19,7 +19,7 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.XmlMappingException;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class StaxEventItemReaderCommonTests extends AbstractItemStreamItemReaderTests {
private final static String FOOS = "<foos> <foo value=\"1\"/> <foo value=\"2\"/> <foo value=\"3\"/> <foo value=\"4\"/> <foo value=\"5\"/> </foos>";