fixed remaining warnings under main/java, added TODOs for IbatisDrivingQueryItemReader and MultipleColumnJdbcKeyCollector
This commit is contained in:
@@ -65,7 +65,7 @@ public class BatchSqlUpdateItemWriter<T> extends AbstractTransactionalResourceIt
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
|
||||
private ItemPreparedStatementSetter preparedStatementSetter;
|
||||
private ItemPreparedStatementSetter<T> preparedStatementSetter;
|
||||
|
||||
private String sql;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class BatchSqlUpdateItemWriter<T> extends AbstractTransactionalResourceIt
|
||||
* @param preparedStatementSetter the {@link ItemPreparedStatementSetter} to
|
||||
* set
|
||||
*/
|
||||
public void setItemPreparedStatementSetter(ItemPreparedStatementSetter preparedStatementSetter) {
|
||||
public void setItemPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter) {
|
||||
this.preparedStatementSetter = preparedStatementSetter;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class BatchSqlUpdateItemWriter<T> extends AbstractTransactionalResourceIt
|
||||
int[] values = (int[]) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
|
||||
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
|
||||
|
||||
for (Object item : processed) {
|
||||
for (T item : processed) {
|
||||
preparedStatementSetter.setValues(item, ps);
|
||||
ps.addBatch();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,13 @@ import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
* The writer is thread safe after its properties are set (normal singleton
|
||||
* behaviour).
|
||||
*
|
||||
* TODO remove this class? It does not return keys so it shouldn't extend
|
||||
* DrivingQueryItemReader
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @see IbatisKeyCollector
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IbatisDrivingQueryItemReader extends DrivingQueryItemReader {
|
||||
|
||||
private String detailsQueryId;
|
||||
|
||||
@@ -5,10 +5,7 @@ package org.springframework.batch.item.database.support;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.item.database.ItemPreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.ColumnMapRowMapper;
|
||||
@@ -27,15 +24,13 @@ import org.springframework.util.Assert;
|
||||
* @see ItemPreparedStatementSetter
|
||||
* @see ColumnMapRowMapper
|
||||
*/
|
||||
public class ColumnMapItemPreparedStatementSetter implements ItemPreparedStatementSetter {
|
||||
public class ColumnMapItemPreparedStatementSetter implements ItemPreparedStatementSetter<Map<String, Object>> {
|
||||
|
||||
public void setValues(Object item, PreparedStatement ps) throws SQLException {
|
||||
public void setValues(Map<String, Object> item, PreparedStatement ps) throws SQLException {
|
||||
Assert.isInstanceOf(Map.class, item, "Input to map PreparedStatement parameters must be of type Map.");
|
||||
Set keySet = ((Map)item).entrySet();
|
||||
int counter = 1;
|
||||
for(Iterator it = keySet.iterator(); it.hasNext();){
|
||||
Entry entry = (Entry)it.next();
|
||||
StatementCreatorUtils.setParameterValue(ps, counter, SqlTypeValue.TYPE_UNKNOWN, entry.getValue());
|
||||
for(Object value : item.values()){
|
||||
StatementCreatorUtils.setParameterValue(ps, counter, SqlTypeValue.TYPE_UNKNOWN, value);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,14 @@ import org.springframework.util.StringUtils;
|
||||
* {@link #setPreparedStatementSetter(ItemPreparedStatementSetter)} and
|
||||
* {@link #setKeyMapper(RowMapper)} are thread-safe (true for default values).
|
||||
*
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
* @see DrivingQueryItemReader
|
||||
* @see ItemPreparedStatementSetter
|
||||
*
|
||||
* TODO this class has nothing to do with "multiple columns" other than default
|
||||
* values form keyMapper and preparedStatementSetter. This should be sorted out for 2.0
|
||||
*/
|
||||
public class MultipleColumnJdbcKeyCollector<T> extends ExecutionContextUserSupport implements KeyCollector<T> {
|
||||
|
||||
@@ -57,6 +61,7 @@ public class MultipleColumnJdbcKeyCollector<T> extends ExecutionContextUserSuppo
|
||||
|
||||
private RowMapper keyMapper = new ColumnMapRowMapper();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ItemPreparedStatementSetter preparedStatementSetter = new ColumnMapItemPreparedStatementSetter();
|
||||
|
||||
private String sql;
|
||||
@@ -96,7 +101,7 @@ public class MultipleColumnJdbcKeyCollector<T> extends ExecutionContextUserSuppo
|
||||
+ " in order to restart.");
|
||||
|
||||
if (executionContext.size() > 0) {
|
||||
Object key = executionContext.get(getKey(CURRENT_KEY));
|
||||
T key = (T) executionContext.get(getKey(CURRENT_KEY));
|
||||
return jdbcTemplate.query(restartSql, new PreparedStatementSetterKeyWrapper(key, preparedStatementSetter),
|
||||
keyMapper);
|
||||
}
|
||||
@@ -162,17 +167,17 @@ public class MultipleColumnJdbcKeyCollector<T> extends ExecutionContextUserSuppo
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setPreparedStatementSetter(ItemPreparedStatementSetter preparedStatementSetter) {
|
||||
public void setPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter) {
|
||||
this.preparedStatementSetter = preparedStatementSetter;
|
||||
}
|
||||
|
||||
private static class PreparedStatementSetterKeyWrapper implements PreparedStatementSetter {
|
||||
private class PreparedStatementSetterKeyWrapper implements PreparedStatementSetter {
|
||||
|
||||
private Object key;
|
||||
private T key;
|
||||
|
||||
private ItemPreparedStatementSetter pss;
|
||||
private ItemPreparedStatementSetter<T> pss;
|
||||
|
||||
public PreparedStatementSetterKeyWrapper(Object key, ItemPreparedStatementSetter pss) {
|
||||
public PreparedStatementSetterKeyWrapper(T key, ItemPreparedStatementSetter<T> pss) {
|
||||
this.key = key;
|
||||
this.pss = pss;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ package org.springframework.batch.item.database.support;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
@@ -19,7 +19,7 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
|
||||
|
||||
private ColumnMapItemPreparedStatementSetter mapper;
|
||||
|
||||
private Map<Object, Object> key;
|
||||
private Map<String, Object> key;
|
||||
|
||||
private MockControl psControl = MockControl.createControl(PreparedStatement.class);
|
||||
private PreparedStatement ps;
|
||||
@@ -31,35 +31,15 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
|
||||
ps = (PreparedStatement)psControl.getMock();
|
||||
mapper = new ColumnMapItemPreparedStatementSetter();
|
||||
|
||||
key = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(2);
|
||||
key = new LinkedHashMap<String, Object>(2);
|
||||
key.put("1", new Integer(1));
|
||||
key.put("2", new Integer(2));
|
||||
}
|
||||
|
||||
public void testSetValuesWithInvalidType() throws Exception {
|
||||
|
||||
try{
|
||||
mapper.setValues(new Object(), ps);
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateExecutionContextWithNull() throws Exception{
|
||||
|
||||
try{
|
||||
mapper.setValues(ps, null);
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateExecutionContextFromEmptyKeys() throws Exception {
|
||||
|
||||
psControl.replay();
|
||||
mapper.setValues(new HashMap<Object, Object>(), ps);
|
||||
mapper.setValues(new HashMap<String, Object>(), ps);
|
||||
psControl.verify();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
|
||||
Reference in New Issue
Block a user