#infinite-loop-in-spring-batch-class

1 messages · Page 1 of 1 (latest)

viscid templeBOT
#

<@&1004656351647117403> please have a look, thanks.

thin lantern
#
public class ItemPeekableItemReader<T> extends SingleItemPeekableItemReader<T> implements InitializingBean {

    private T current;

    @Override
    public T read() throws Exception, UnexpectedInputException, ParseException {
        return current = super.read();
    }

    @Override
    public T peek() {
        try {
            return super.peek();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Field delegate = this.getClass().getSuperclass().getDeclaredField("delegate");
        delegate.setAccessible(true);
        Object object = delegate.get(this);
        Assert.notNull(object, "The delegate of " + delegate.getDeclaringClass().getName() + " must not be null.");
        delegate.setAccessible(false);
    }
    
    public T getCurrent() {
        return current;
    }
}
<!--config-->

<bean id="reportPeekingCompletionPolicy" class="com.reader.ReportPeekingCompletionPolicyReader" scope="step">
    <constructor-arg ref="itemPeekableItemReader"/>
</bean>

<bean id="itemPeekableItemReader" class="com.reader.ItemPeekableItemReader" scope="step">
    <property name="delegate" ref="jdbcCursorItemReader"/>
</bean>