BATCH-1906: add support to access an item's line number
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package org.springframework.batch.item;
|
||||
|
||||
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
|
||||
|
||||
/**
|
||||
* Marker interface indicating that an item should have the item count set on it. Typically used within
|
||||
* an {@link AbstractItemCountingItemStreamItemReader}.
|
||||
*
|
||||
* @author Jimmy Praet
|
||||
*/
|
||||
public interface ItemCountAware {
|
||||
|
||||
void setItemCount(int count);
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.batch.item.support;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemCountAware;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
@@ -79,7 +80,11 @@ public abstract class AbstractItemCountingItemStreamItemReader<T> extends Abstra
|
||||
return null;
|
||||
}
|
||||
currentItemCount++;
|
||||
return doRead();
|
||||
T item = doRead();
|
||||
if(item instanceof ItemCountAware) {
|
||||
((ItemCountAware) item).setItemCount(currentItemCount);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected int getCurrentItemCount() {
|
||||
|
||||
Reference in New Issue
Block a user