BATCH-1940: Replace org.springframework.batch.support.JdbcTestUtils with org.springframework.test.jdbc.JdbcTestUtils
This commit is contained in:
committed by
Michael Minella
parent
e9680c7f61
commit
a6ab68bbbb
@@ -1,49 +0,0 @@
|
||||
package org.springframework.batch.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Util class based off {@link org.springframework.test.jdbc.SimpleJdbcTestUtils} but for JdbcTemplate
|
||||
* rather than the deprecated 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(JdbcOperations 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(JdbcOperations 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;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml")
|
||||
|
||||
Reference in New Issue
Block a user