Spring batch paginated reader and Exception handling

Viewed 2413

We created a custom item reader which extends AbstractPaginatedDataItemReader. Spring-batch allows to manage which exception stops or not a job (skipped exceptions).

In "classic" spring-batch readers, the doRead method throws any Exception. That means, if a skipped exception is thrown during the read, the item is skipped and the job continues running.

But in paginated readers, the doPageRead method, used to retrieve next data page, doesn't throw any exception:

protected abstract Iterator<T> doPageRead();

The doPageRead method is called by the doRead one:

protected T doRead() throws Exception {

    synchronized (lock) {
        if(results == null || !results.hasNext()) {

            results = doPageRead();

            page ++;

            if(results == null || !results.hasNext()) {
                return null;
            }
        }


        if(results.hasNext()) {
            return results.next();
        }
        else {
            return null;
        }
    }
}

As doPageRead method doesn't declare any thrown exception, that means a configured skipped exception can only be a RuntimeException?

Thanks

1 Answers

A Spring Batch reader is eventually an ItemReader irrespective of it being a paging reader or a non - paging reader. Which eventually means that it will hand over single - single items to processor and read() method contract is all that matters.

Paging readers simply have an optimization about how they actually read an item but no different than than a regular non - paging reader.

So in my opinion, your look out for doReadPage() method seems unnecessary, what matters is read() method contract.

If you are facing any issue ( and that is not clear from your question ) , do let me know.

Related