IN PROGRESS - BATCH-711: Upgrade ItemWriter and implementations to use parameterized types
This commit is contained in:
@@ -37,9 +37,9 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractTransactionalResourceItemWriter implements ItemWriter {
|
||||
public abstract class AbstractTransactionalResourceItemWriter<T> implements ItemWriter<T> {
|
||||
|
||||
private Set<Object> failed = new HashSet<Object>();
|
||||
private Set<T> failed = new HashSet<T>();
|
||||
|
||||
/**
|
||||
* Flushing delegated to subclass surrounded by binding and unbinding of
|
||||
@@ -73,7 +73,7 @@ public abstract class AbstractTransactionalResourceItemWriter implements ItemWri
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemWriter#write(Object)
|
||||
*/
|
||||
public void write(Object output) throws Exception {
|
||||
public void write(T output) throws Exception {
|
||||
bindTransactionResources();
|
||||
getProcessed().add(output);
|
||||
doWrite(output);
|
||||
@@ -123,7 +123,7 @@ public abstract class AbstractTransactionalResourceItemWriter implements ItemWri
|
||||
/**
|
||||
* Callback method of {@link #write(Object)}.
|
||||
*/
|
||||
protected abstract void doWrite(Object output) throws Exception;
|
||||
protected abstract void doWrite(T item) throws Exception;
|
||||
|
||||
/**
|
||||
* @return Key for items processed in the current transaction
|
||||
@@ -159,10 +159,10 @@ public abstract class AbstractTransactionalResourceItemWriter implements ItemWri
|
||||
* @return the processed
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<Object> getProcessed() {
|
||||
protected Set<T> getProcessed() {
|
||||
Assert.state(TransactionSynchronizationManager.hasResource(getResourceKey()),
|
||||
"Processed items not bound to transaction.");
|
||||
Set<Object> processed = (Set<Object>) TransactionSynchronizationManager.getResource(getResourceKey());
|
||||
Set<T> processed = (Set<T>) TransactionSynchronizationManager.getResource(getResourceKey());
|
||||
return processed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class BatchSqlUpdateItemWriter extends AbstractTransactionalResourceItemWriter implements InitializingBean {
|
||||
public class BatchSqlUpdateItemWriter<T> extends AbstractTransactionalResourceItemWriter<T> implements InitializingBean {
|
||||
|
||||
/**
|
||||
* Key for items processed in the current transaction {@link RepeatContext}.
|
||||
@@ -122,7 +122,7 @@ public class BatchSqlUpdateItemWriter extends AbstractTransactionalResourceItemW
|
||||
*/
|
||||
protected void doFlush() throws EmptyResultDataAccessException {
|
||||
|
||||
final List<Object> processed = new ArrayList<Object>(getProcessed());
|
||||
final List<T> processed = new ArrayList<T>(getProcessed());
|
||||
|
||||
if (!processed.isEmpty()) {
|
||||
|
||||
@@ -158,7 +158,7 @@ public class BatchSqlUpdateItemWriter extends AbstractTransactionalResourceItemW
|
||||
/**
|
||||
* No-op.
|
||||
*/
|
||||
protected void doWrite(Object output) {
|
||||
protected void doWrite(T item) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,14 +44,14 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class HibernateAwareItemWriter extends AbstractTransactionalResourceItemWriter implements InitializingBean {
|
||||
public class HibernateAwareItemWriter<T> extends AbstractTransactionalResourceItemWriter<T> implements InitializingBean {
|
||||
|
||||
/**
|
||||
* Key for items processed in the current transaction {@link RepeatContext}.
|
||||
*/
|
||||
private static final String ITEMS_PROCESSED = HibernateAwareItemWriter.class.getName() + ".ITEMS_PROCESSED";
|
||||
|
||||
private ItemWriter delegate;
|
||||
private ItemWriter<? super T> delegate;
|
||||
|
||||
private HibernateOperations hibernateTemplate;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class HibernateAwareItemWriter extends AbstractTransactionalResourceItemW
|
||||
*
|
||||
* @param delegate the delegate to set
|
||||
*/
|
||||
public void setDelegate(ItemWriter delegate) {
|
||||
public void setDelegate(ItemWriter<? super T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ public class HibernateAwareItemWriter extends AbstractTransactionalResourceItemW
|
||||
return ITEMS_PROCESSED;
|
||||
}
|
||||
|
||||
protected void doWrite(Object output) throws Exception {
|
||||
delegate.write(output);
|
||||
protected void doWrite(T item) throws Exception {
|
||||
delegate.write(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user