Change ClassifierCompositeItemWriter to honor item order
The ClassifierCompositeItemWriter loops through the items passed to the write method twice. The first time to classifier each item. The second tiem to perform the actual writes (this prevents the unnecessicary IO if an error occurs during classification). A HashMap was previously used to hold the classified items (key to the writer : item) however this causes the items to be written out of order. This update changes it to a LinkedHashMap to honor the order the items come in.
This commit is contained in:
committed by
Michael Minella
parent
04b339b8f4
commit
44fc2b1069
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.item.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ClassifierCompositeItemWriter<T> implements ItemWriter<T> {
|
||||
@Override
|
||||
public void write(List<? extends T> items) throws Exception {
|
||||
|
||||
Map<ItemWriter<? super T>, List<T>> map = new HashMap<ItemWriter<? super T>, List<T>>();
|
||||
Map<ItemWriter<? super T>, List<T>> map = new LinkedHashMap<ItemWriter<? super T>, List<T>>();
|
||||
|
||||
for (T item : items) {
|
||||
ItemWriter<? super T> key = classifier.classify(item);
|
||||
|
||||
Reference in New Issue
Block a user