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

@@ -29,16 +29,15 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.util.Assert;
/**
* <p>{@link ItemWriter} that uses the batching features from
* {@link SimpleJdbcTemplate} to execute a batch of statements for all items
* {@link NamedParameterJdbcTemplate} to execute a batch of statements for all items
* provided.</p>
*
* The user must provide an SQL query and a special callback in the for of either
@@ -62,7 +61,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
protected static final Log logger = LogFactory.getLog(JdbcBatchItemWriter.class);
private SimpleJdbcOperations simpleJdbcTemplate;
private NamedParameterJdbcOperations namedParameterJdbcTemplate;
private ItemPreparedStatementSetter<T> itemPreparedStatementSetter;
@@ -119,17 +118,17 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
* @param dataSource
*/
public void setDataSource(DataSource dataSource) {
if (simpleJdbcTemplate == null) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
if (namedParameterJdbcTemplate == null) {
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
}
/**
* Public setter for the {@link JdbcOperations}.
* @param simpleJdbcTemplate the {@link JdbcOperations} to set
* Public setter for the {@link NamedParameterJdbcOperations}.
* @param namedParameterJdbcTemplate the {@link NamedParameterJdbcOperations} to set
*/
public void setSimpleJdbcTemplate(SimpleJdbcOperations simpleJdbcTemplate) {
this.simpleJdbcTemplate = simpleJdbcTemplate;
public void setJdbcTemplate(NamedParameterJdbcOperations namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}
/**
@@ -137,7 +136,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
* parameter source.
*/
public void afterPropertiesSet() {
Assert.notNull(simpleJdbcTemplate, "A DataSource or a SimpleJdbcTemplate is required.");
Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required.");
Assert.notNull(sql, "An SQL statement is required.");
List<String> namedParameters = new ArrayList<String>();
parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters);
@@ -174,10 +173,10 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
for (T item : items) {
batchArgs[i++] = itemSqlParameterSourceProvider.createSqlParameterSource(item);
}
updateCounts = simpleJdbcTemplate.batchUpdate(sql, batchArgs);
updateCounts = namedParameterJdbcTemplate.batchUpdate(sql, batchArgs);
}
else {
updateCounts = (int[]) simpleJdbcTemplate.getJdbcOperations().execute(sql, new PreparedStatementCallback() {
updateCounts = (int[]) namedParameterJdbcTemplate.getJdbcOperations().execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
for (T item : items) {
itemPreparedStatementSetter.setValues(item, ps);
@@ -197,9 +196,6 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
}
}
}
}
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.batch.item.ItemStreamException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -73,10 +73,6 @@ import org.springframework.util.ClassUtils;
* @since 2.0
*/
public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> implements InitializingBean {
/**
*
*/
private static final String START_AFTER_VALUE = "start.after";
public static final int VALUE_NOT_SET = -1;
@@ -87,7 +83,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
private Map<String, Object> parameterValues;
private SimpleJdbcTemplate simpleJdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private RowMapper rowMapper;
@@ -169,7 +165,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
jdbcTemplate.setFetchSize(fetchSize);
}
jdbcTemplate.setMaxRows(getPageSize());
this.simpleJdbcTemplate = new SimpleJdbcTemplate(jdbcTemplate);
namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
Assert.notNull(queryProvider);
queryProvider.init(dataSource);
this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize());
@@ -196,16 +192,16 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
}
if (parameterValues != null && parameterValues.size() > 0) {
if (this.queryProvider.isUsingNamedParameters()) {
query = simpleJdbcTemplate.getNamedParameterJdbcOperations().query(firstPageSql,
query = namedParameterJdbcTemplate.query(firstPageSql,
getParameterMap(parameterValues, null), rowCallback);
}
else {
query = simpleJdbcTemplate.getJdbcOperations().query(firstPageSql,
query = getJdbcTemplate().query(firstPageSql,
getParameterList(parameterValues, null).toArray(), rowCallback);
}
}
else {
query = simpleJdbcTemplate.getJdbcOperations().query(firstPageSql, rowCallback);
query = getJdbcTemplate().query(firstPageSql, rowCallback);
}
}
@@ -214,11 +210,11 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
logger.debug("SQL used for reading remaining pages: [" + remainingPagesSql + "]");
}
if (this.queryProvider.isUsingNamedParameters()) {
query = simpleJdbcTemplate.getNamedParameterJdbcOperations().query(remainingPagesSql,
query = namedParameterJdbcTemplate.query(remainingPagesSql,
getParameterMap(parameterValues, startAfterValue), rowCallback);
}
else {
query = simpleJdbcTemplate.getJdbcOperations().query(remainingPagesSql,
query = getJdbcTemplate().query(remainingPagesSql,
getParameterList(parameterValues, startAfterValue).toArray(), rowCallback);
}
}
@@ -266,11 +262,11 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
}
};
if (this.queryProvider.isUsingNamedParameters()) {
startAfterValue = simpleJdbcTemplate.getNamedParameterJdbcOperations().queryForObject(jumpToItemSql,
startAfterValue = namedParameterJdbcTemplate.queryForObject(jumpToItemSql,
getParameterMap(parameterValues, startAfterValue), startMapper);
}
else {
startAfterValue = simpleJdbcTemplate.getJdbcOperations().queryForObject(jumpToItemSql,
startAfterValue = getJdbcTemplate().queryForObject(jumpToItemSql,
getParameterList(parameterValues, startAfterValue).toArray(), startMapper);
}
@@ -314,4 +310,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
}
}
private JdbcTemplate getJdbcTemplate() {
return (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations();
}
}

View File

@@ -15,24 +15,44 @@
*/
package org.springframework.batch.item.file.transform;
import org.springframework.core.enums.StringCodedLabeledEnum;
import org.springframework.util.Assert;
/**
* @author Dave Syer
*
*/
public class Alignment extends StringCodedLabeledEnum {
public static final Alignment CENTER = new Alignment("CENTER", "center");
public static final Alignment RIGHT = new Alignment("RIGHT", "right");
public static final Alignment LEFT = new Alignment("LEFT", "left");
public enum Alignment {
CENTER("CENTER", "center"),
RIGHT("RIGHT", "right"),
LEFT("LEFT", "left");
private String code;
private String label;
/**
* @param code
* @param label
*/
public Alignment(String code, String label) {
super(code, label);
private Alignment(String code, String label) {
Assert.notNull(code, "'code' must not be null");
this.code = code;
this.label = label;
}
public Comparable getCode() {
return code;
}
public String getStringCode() {
return (String) getCode();
}
public String getLabel() {
if (this.label != null) {
return label;
}
return getCode().toString();
}
}

View File

@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.util.List;
import java.util.Map;

View File

@@ -0,0 +1,49 @@
package org.springframework.batch.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* <p>
* Util class based off {@link org.springframework.test.jdbc.SimpleJdbcTestUtils} but for JdbcTemplate
* rather than the deprecated {@link org.springframework.jdbc.core.simple.SimpleJdbcTemplate}.
*
* This class should be removed when Batch uses Spring 3.2 - see:
* https://jira.springsource.org/browse/SPR-9235
* </p>
*/
public final class JdbcTestUtils {
private static final Log LOG = LogFactory.getLog(JdbcTestUtils.class);
private JdbcTestUtils() {
}
/**
* Count the rows in the given table.
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
* @param tableName table name to count rows in
* @return the number of rows in the table
*/
public static int countRowsInTable(JdbcTemplate jdbcTemplate, String tableName) {
return jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName);
}
/**
* Delete all rows from the specified tables.
* @param jdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
* @param tableNames the names of the tables from which to delete
* @return the total number of rows deleted from all specified tables
*/
public static int deleteFromTables(JdbcTemplate jdbcTemplate, String... tableNames) {
int totalRowCount = 0;
for (String tableName : tableNames) {
int rowCount = jdbcTemplate.update("DELETE FROM " + tableName);
totalRowCount += rowCount;
if (LOG.isInfoEnabled()) {
LOG.info("Deleted " + rowCount + " rows from table " + tableName);
}
}
return totalRowCount;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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