From 4b04e4a7cf890c3b192408f16a25636b17d5020f Mon Sep 17 00:00:00 2001 From: robokaso Date: Wed, 16 Jul 2008 10:10:15 +0000 Subject: [PATCH] IN PROGRESS - BATCH-709: Change all collections to use generics --- .../step/item/AbstractStepFactoryBean.java | 1 + .../step/item/BatchListenerFactoryHelper.java | 15 +++++----- .../step/item/ItemSkipPolicyItemHandler.java | 29 +++++++++---------- .../item/SimpleRetryExceptionHandler.java | 2 +- .../step/item/SkipLimitStepFactoryBean.java | 25 ++++++++-------- .../skip/LimitCheckingItemSkipPolicy.java | 14 ++++----- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/AbstractStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/AbstractStepFactoryBean.java index bca952f2c..52fcf1894 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/AbstractStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/AbstractStepFactoryBean.java @@ -270,6 +270,7 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw } + @SuppressWarnings("unchecked") public Class getObjectType() { return Step.class; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java index 82205715f..2a9c8b0b8 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/BatchListenerFactoryHelper.java @@ -105,7 +105,7 @@ abstract class BatchListenerFactoryHelper { } } }; - + return itemWriter; } @@ -141,6 +141,7 @@ abstract class BatchListenerFactoryHelper { public void open(RepeatContext context) { multicaster.beforeChunk(); } + public void close(RepeatContext context) { multicaster.afterChunk(); } @@ -156,28 +157,28 @@ abstract class BatchListenerFactoryHelper { * @param listeners */ public static StepExecutionListener[] getStepListeners(StepListener[] listeners) { - List list = new ArrayList(); + List list = new ArrayList(); for (int i = 0; i < listeners.length; i++) { StepListener listener = listeners[i]; if (listener instanceof StepExecutionListener) { - list.add(listener); + list.add((StepExecutionListener) listener); } } - return (StepExecutionListener[]) list.toArray(new StepExecutionListener[list.size()]); + return list.toArray(new StepExecutionListener[list.size()]); } /** * @param listeners */ public static SkipListener[] getSkipListeners(StepListener[] listeners) { - List list = new ArrayList(); + List list = new ArrayList(); for (int i = 0; i < listeners.length; i++) { StepListener listener = listeners[i]; if (listener instanceof SkipListener) { - list.add(listener); + list.add((SkipListener) listener); } } - return (SkipListener[]) list.toArray(new SkipListener[list.size()]); + return list.toArray(new SkipListener[list.size()]); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemSkipPolicyItemHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemSkipPolicyItemHandler.java index 2ef727219..9654ba99b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemSkipPolicyItemHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ItemSkipPolicyItemHandler.java @@ -17,7 +17,6 @@ package org.springframework.batch.core.step.item; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -58,14 +57,14 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { * removed */ private static final String TO_BE_REMOVED = ItemSkipPolicyItemHandler.class.getName() + ".TO_BE_REMOVED"; - + private ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy(); private int skipCacheCapacity = 1024; - private Map skippedExceptions = new HashMap(); + private Map skippedExceptions = new HashMap(); - private Class[] doNotRethrowExceptionClasses = new Class[] {}; + private Class[] doNotRethrowExceptionClasses = new Class[] {}; private static final ItemKeyGenerator defaultItemKeyGenerator = new ItemKeyGenerator() { public Object getKey(Object item) { @@ -162,7 +161,7 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { while (item != null && throwable != null) { logger.debug("Skipping item on input, previously failed on output; key=[" + key + "]"); scheduleForRemoval(key); - + item = doRead(); key = itemKeyGenerator.getKey(item); throwable = getSkippedException(key); @@ -175,9 +174,9 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { if (itemSkipPolicy.shouldSkip(e, contribution.getStepSkipCount())) { // increment skip count and try again contribution.incrementTemporaryReadSkipCount(); - + listener.onSkipInRead(e); - + logger.debug("Skipping failed input", e); } else { @@ -225,12 +224,12 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { catch (Exception e) { if (itemSkipPolicy.shouldSkip(e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); - + addSkippedException(key, e); logger.debug("Added item to skip list; key=" + key); listener.onSkipInWrite(item, e); - + // return without re-throwing if exception shouldn't cause // rollback if (!shouldRethrow(e)) { @@ -278,25 +277,25 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { * * @param key */ + @SuppressWarnings("unchecked") private void scheduleForRemoval(Object key) { if (!TransactionSynchronizationManager.hasResource(TO_BE_REMOVED)) { - TransactionSynchronizationManager.bindResource(TO_BE_REMOVED, new HashSet()); + TransactionSynchronizationManager.bindResource(TO_BE_REMOVED, new HashSet()); } - ((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).add(key); + ((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).add(key); } /** * Clear the map of skipped exception corresponding to key. * @param key the key to clear */ + @SuppressWarnings("unchecked") private void clearSkippedExceptions() { if (!TransactionSynchronizationManager.hasResource(TO_BE_REMOVED)) { return; } synchronized (skippedExceptions) { - for (Iterator iterator = ((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED)).iterator(); iterator - .hasNext();) { - Object key = iterator.next(); + for (Object key : ((Set) TransactionSynchronizationManager.getResource(TO_BE_REMOVED))) { skippedExceptions.remove(key); } TransactionSynchronizationManager.unbindResource(TO_BE_REMOVED); @@ -317,7 +316,7 @@ public class ItemSkipPolicyItemHandler extends SimpleItemHandler { * doNotRethrowExceptionClasses will not be re-thrown when skipped. * @param doNotRethrowExceptionClasses empty by default */ - public void setDoNotRethrowExceptionClasses(Class[] doNotRethrowExceptionClasses) { + public void setDoNotRethrowExceptionClasses(Class[] doNotRethrowExceptionClasses) { this.doNotRethrowExceptionClasses = doNotRethrowExceptionClasses; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java index cd14f5955..892e5fe7c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java @@ -46,7 +46,7 @@ public class SimpleRetryExceptionHandler extends RetryListenerSupport implements * @param exceptionHandler * @param classes */ - public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Class[] classes) { + public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Class[] classes) { this.retryPolicy = retryPolicy; this.exceptionHandler = exceptionHandler; this.fatalExceptionClassifier = new BinaryExceptionClassifier(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java index 7f3aece1d..eeb05dc7b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipLimitStepFactoryBean.java @@ -20,6 +20,7 @@ import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.RetryException; import org.springframework.batch.retry.RetryListener; import org.springframework.batch.retry.RetryOperations; +import org.springframework.batch.retry.RetryPolicy; import org.springframework.batch.retry.backoff.BackOffPolicy; import org.springframework.batch.retry.callback.RecoveryRetryCallback; import org.springframework.batch.retry.policy.ExceptionClassifierRetryPolicy; @@ -53,9 +54,9 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { private int skipLimit = 0; - private Class[] skippableExceptionClasses = new Class[] { Exception.class }; + private Class[] skippableExceptionClasses = new Class[] { Exception.class }; - private Class[] fatalExceptionClasses = new Class[] { Error.class }; + private Class[] fatalExceptionClasses = new Class[] { Error.class }; private ItemKeyGenerator itemKeyGenerator; @@ -63,7 +64,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { private int retryLimit; - private Class[] retryableExceptionClasses = new Class[] {}; + private Class[] retryableExceptionClasses = new Class[] {}; private BackOffPolicy backOffPolicy; @@ -103,7 +104,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { * Public setter for the Class[]. * @param retryableExceptionClasses the retryableExceptionClasses to set */ - public void setRetryableExceptionClasses(Class[] retryableExceptionClasses) { + public void setRetryableExceptionClasses(Class[] retryableExceptionClasses) { this.retryableExceptionClasses = retryableExceptionClasses; } @@ -143,7 +144,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { * * @param exceptionClasses defaults to Exception */ - public void setSkippableExceptionClasses(Class[] exceptionClasses) { + public void setSkippableExceptionClasses(Class[] exceptionClasses) { this.skippableExceptionClasses = exceptionClasses; } @@ -152,7 +153,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { * * @param fatalExceptionClasses {@link Error} by default */ - public void setFatalExceptionClasses(Class[] fatalExceptionClasses) { + public void setFatalExceptionClasses(Class[] fatalExceptionClasses) { this.fatalExceptionClasses = fatalExceptionClasses; } @@ -188,13 +189,13 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { ExceptionClassifierRetryPolicy retryPolicy = new ExceptionClassifierRetryPolicy(); SubclassExceptionClassifier exceptionClassifier = new SubclassExceptionClassifier(); - HashMap exceptionTypeMap = new HashMap(); + HashMap, String> exceptionTypeMap = new HashMap, String>(); for (int i = 0; i < retryableExceptionClasses.length; i++) { - Class cls = retryableExceptionClasses[i]; + Class cls = retryableExceptionClasses[i]; exceptionTypeMap.put(cls, "retry"); } exceptionClassifier.setTypeMap(exceptionTypeMap); - HashMap retryPolicyMap = new HashMap(); + HashMap retryPolicyMap = new HashMap(); retryPolicyMap.put("retry", simpleRetryPolicy); retryPolicyMap.put("default", new NeverRetryPolicy()); retryPolicy.setPolicyMap(retryPolicyMap); @@ -222,7 +223,7 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { retryTemplate.setBackOffPolicy(backOffPolicy); } - List exceptions = new ArrayList(Arrays.asList(skippableExceptionClasses)); + List> exceptions = new ArrayList>(Arrays.asList(skippableExceptionClasses)); ItemSkipPolicy readSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, exceptions, Arrays .asList(fatalExceptionClasses)); exceptions.addAll(Arrays.asList(retryableExceptionClasses)); @@ -242,8 +243,8 @@ public class SkipLimitStepFactoryBean extends SimpleStepFactoryBean { } - public void addFatalExceptionIfMissing(Class cls) { - List fatalExceptionList = new ArrayList(Arrays.asList(fatalExceptionClasses)); + public void addFatalExceptionIfMissing(Class cls) { + List> fatalExceptionList = new ArrayList>(Arrays.asList(fatalExceptionClasses)); if (!fatalExceptionList.contains(cls)) { fatalExceptionList.add(cls); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java index 361a75500..921abbc26 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/skip/LimitCheckingItemSkipPolicy.java @@ -18,7 +18,6 @@ package org.springframework.batch.core.step.skip; import java.io.FileNotFoundException; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -77,8 +76,9 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy { * and none are fatal. * @param skipLimit the number of exceptions allowed to skip */ + @SuppressWarnings("unchecked") public LimitCheckingItemSkipPolicy(int skipLimit) { - this(skipLimit, Collections.singletonList(Exception.class), Collections.EMPTY_LIST); + this(skipLimit, (List) Collections.singletonList(Exception.class), Collections.EMPTY_LIST); } /** @@ -89,16 +89,14 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy { * (non-critical) * @param fatalExceptions exception classes that should never be skipped */ - public LimitCheckingItemSkipPolicy(int skipLimit, List skippableExceptions, List fatalExceptions) { + public LimitCheckingItemSkipPolicy(int skipLimit, List> skippableExceptions, List>fatalExceptions) { this.skipLimit = skipLimit; SubclassExceptionClassifier exceptionClassifier = new SubclassExceptionClassifier(); - Map typeMap = new HashMap(); - for (Iterator iterator = skippableExceptions.iterator(); iterator.hasNext();) { - Class throwable = (Class) iterator.next(); + Map, String> typeMap = new HashMap, String>(); + for (Class throwable : skippableExceptions) { typeMap.put(throwable, SKIP); } - for (Iterator iterator = fatalExceptions.iterator(); iterator.hasNext();) { - Class throwable = (Class) iterator.next(); + for (Class throwable : fatalExceptions) { typeMap.put(throwable, NEVER_SKIP); } exceptionClassifier.setTypeMap(typeMap);