Apr 10th, 2008, 09:08 AM
How to allow empty key list in DrivingQueryItemReader
How can I allow empty key lists in DrivingQueryItemReader? In http://jira.springframework.org/browse/BATCH-413 Lucas Ward suggests that it can be done by using some kind of StepListener, but I have a hard time to figure out how. As far as I can tell, no matter what you do, the step/batch will be marked as failed anyway and the exception (NoWorkFoundException) will be rethrown.
Then I must also say that I disagree with the assumption that the step is a failure when there aren't any items to process. Nothing has been said about the number of items to expect to process. I've actually never come across a case where no items (left) to process means failure, but it's possible that they exist.
Apr 10th, 2008, 11:10 AM
Someone else commented on this in Jira as well, the issue can be found here:
I'd rather not duplicate it, so please read my last comment if you're curious about my reasoning for throwing a NoWorkFoundException. I'm still very much open for discussion (I'd like to think I'm always open for discussion), but I still feel pretty strongly about throwing the exception. Why can't you simply wrap the reader and catch the exception? This gives you the chance to log out the fact that no work was found. You can then return null and it will finish successfully? It seems like this gives you the opportunity to know that there was nothing found, without having to be stateful, while still allowing for others who would like a job to fail for this reason to have the exception thrown.