IN PROGRESS - BATCH-709: Change all collections to use generics

This commit is contained in:
robokaso
2008-07-15 09:20:41 +00:00
parent 877737ab72
commit 0e74543186
7 changed files with 42 additions and 34 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.item;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -27,10 +26,9 @@ import java.util.Map.Entry;
import org.springframework.util.Assert;
/**
* Object representing a context for an {@link ItemStream}. It is a thin
* wrapper for a map that allows optionally for type safety on reads. It also
* allows for dirty checking by setting a 'dirty' flag whenever any put is
* called.
* Object representing a context for an {@link ItemStream}. It is a thin wrapper
* for a map that allows optionally for type safety on reads. It also allows for
* dirty checking by setting a 'dirty' flag whenever any put is called.
*
* @author Lucas Ward
* @author Douglas Kaminsky
@@ -39,14 +37,14 @@ public class ExecutionContext implements Serializable {
private boolean dirty = false;
private final Map map;
private final Map<Object, Object> map;
/**
* Default constructor. Initializes a new execution context with an empty
* internal map.
*/
public ExecutionContext() {
map = new HashMap();
map = new HashMap<Object, Object>();
}
/**
@@ -54,7 +52,7 @@ public class ExecutionContext implements Serializable {
*
* @param map Initial contents of context.
*/
public ExecutionContext(Map map) {
public ExecutionContext(Map<Object, Object> map) {
this.map = map;
}
@@ -63,11 +61,10 @@ public class ExecutionContext implements Serializable {
*/
public ExecutionContext(ExecutionContext executionContext) {
this();
if (executionContext==null) {
if (executionContext == null) {
return;
}
for (Iterator iterator = executionContext.entrySet().iterator(); iterator.hasNext();) {
Entry entry = (Entry) iterator.next();
for (Entry<Object, Object> entry : executionContext.entrySet()) {
this.map.put(entry.getKey(), entry.getValue());
}
}
@@ -233,7 +230,7 @@ public class ExecutionContext implements Serializable {
* @param type Class against which value should be validated
* @return Value typed to the specified <code>Class</code>
*/
private Object readAndValidate(String key, Class type) {
private Object readAndValidate(String key, Class<?> type) {
Object value = map.get(key);
@@ -268,7 +265,7 @@ public class ExecutionContext implements Serializable {
* @return A set representing the contents of the context
* @see java.util.Map#entrySet()
*/
public Set entrySet() {
public Set<Entry<Object, Object>> entrySet() {
return map.entrySet();
}
@@ -305,8 +302,7 @@ public class ExecutionContext implements Serializable {
*/
public Properties getProperties() {
Properties props = new Properties();
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
for (Entry<Object, Object> entry : map.entrySet()) {
props.setProperty(entry.getKey().toString(), entry.getValue().toString());
}
@@ -315,6 +311,7 @@ public class ExecutionContext implements Serializable {
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
@@ -330,6 +327,7 @@ public class ExecutionContext implements Serializable {
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
@@ -338,6 +336,7 @@ public class ExecutionContext implements Serializable {
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {

View File

@@ -130,7 +130,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
for (int i=0; i < methods.length; i++) {
if (methods[i].getName().equals(targetMethodName)) {
Class[] params = methods[i].getParameterTypes();
Class<?>[] params = methods[i].getParameterTypes();
if (arguments == null) {
return true;
} else if (arguments.length == params.length) {

View File

@@ -39,7 +39,7 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractTransactionalResourceItemWriter implements ItemWriter {
private Set failed = new HashSet();
private Set<Object> failed = new HashSet<Object>();
/**
* Flushing delegated to subclass surrounded by binding and unbinding of
@@ -140,7 +140,7 @@ public abstract class AbstractTransactionalResourceItemWriter implements ItemWri
if (TransactionSynchronizationManager.hasResource(getResourceKey())) {
return;
}
TransactionSynchronizationManager.bindResource(getResourceKey(), new HashSet());
TransactionSynchronizationManager.bindResource(getResourceKey(), new HashSet<Object>());
}
/**
@@ -158,10 +158,11 @@ public abstract class AbstractTransactionalResourceItemWriter implements ItemWri
*
* @return the processed
*/
protected Set getProcessed() {
@SuppressWarnings("unchecked")
protected Set<Object> getProcessed() {
Assert.state(TransactionSynchronizationManager.hasResource(getResourceKey()),
"Processed items not bound to transaction.");
Set processed = (Set) TransactionSynchronizationManager.getResource(getResourceKey());
Set<Object> processed = (Set<Object>) TransactionSynchronizationManager.getResource(getResourceKey());
return processed;
}
}

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.item.database;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.batch.item.ClearFailedException;
@@ -36,7 +35,8 @@ import org.springframework.util.Assert;
* {@link PreparedStatement} if available and can take some rudimentary steps to
* locate a failure during a flush, and identify the items that failed. When one
* of those items is encountered again the batch is flushed aggressively so that
* the bad item is eventually identified and can be dealt with in isolation.<br/>
* the bad item is eventually identified and can be dealt with in
* isolation.<br/>
*
* The user must provide an SQL query and a special callback
* {@link ItemPreparedStatementSetter}, which is responsible for mapping the
@@ -117,18 +117,19 @@ public class BatchSqlUpdateItemWriter extends AbstractTransactionalResourceItemW
/**
* Create and execute batch prepared statement.
* @throws EmptyResultDataAccessException if any of the items does not cause an update
* @throws EmptyResultDataAccessException if any of the items does not cause
* an update
*/
protected void doFlush() throws EmptyResultDataAccessException {
final List processed = new ArrayList(getProcessed());
final List<Object> processed = new ArrayList<Object>(getProcessed());
if (!processed.isEmpty()) {
int[] values = (int[]) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
for (Iterator iterator = processed.iterator(); iterator.hasNext();) {
Object item = (Object) iterator.next();
for (Object item : processed) {
preparedStatementSetter.setValues(item, ps);
ps.addBatch();
}

View File

@@ -69,9 +69,9 @@ public class DrivingQueryItemReader implements ItemReader, InitializingBean, Ite
private boolean initialized = false;
private List keys;
private List<Object> keys;
private Iterator keysIterator;
private Iterator<Object> keysIterator;
private int currentIndex = 0;
@@ -90,7 +90,7 @@ public class DrivingQueryItemReader implements ItemReader, InitializingBean, Ite
*
* @param keys
*/
public DrivingQueryItemReader(List keys) {
public DrivingQueryItemReader(List<Object> keys) {
this.keys = keys;
this.keysIterator = keys.iterator();
}

View File

@@ -28,7 +28,7 @@ public interface KeyCollector {
* that could potentially be used to retrieve the correct keys.
* @return list of keys returned by the driving query (can be empty but not null)
*/
List retrieveKeys(ExecutionContext executionContext);
List<Object> retrieveKeys(ExecutionContext executionContext);
/**
* Given the provided key, store it in the provided ExecutionContext. This