Announcement Announcement Module
No announcement yet.
Newbie baffled by RepeatOperations Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie baffled by RepeatOperations

    We're just starting with Spring Batch. We have set up a job with DefaultStepFactoryBean that reads rows from a database and writes them to an XML file. Only 5 lines of Java - fabulous!

    Now, we want to insert a little logic around the item processing. So instead of read -> write, it becomes read -> process -> write. But we're baffled as to how to do this. It seems like RepeatOperations is the key - in ItemOrientedStep we have stepOperations and chunkOperations, which looks perfect. But we're totally confused as to how to do this, since it's the RepeatCallback that has the logic. And anyway, non of the callback or listener signatures ever pass the Item in.

    We've seen direct calls to RepeatTemplate.iterate(), but how would we integrate that call into the Step? Implementing a Step from scratch seems like a shame, given the sophistication of the ItemOrientedStep implementation.

    Are we supposed to extend RepeatTemplate and force a RepeatCallback? How do we get our grubby little paws on the item inbetween the read and write?

  • #2
    I think what you're really looking for is the ItemTransformerItemWriter, that will 'transform' the item, before writing. The fact that you're having trouble getting access to the callback is actually intentional, there's a lot of very specific logic in there that shouldn't be overridden.

    Another option would be to make an ItemWriter that is a processor that calls an ItemWriter (A composite ItemWriter, if you will)

    I've added a jira issue to cover ItemTransformers in the reference documentation:


    • #3
      I see, so we'd continue to use ItemOrientedStep and put the business logic in the transformer that sits between the Step and the "real" ItemWriter. Got it. Thank you for your reply!

      Is there ever any case where we as application programmers would use RepeatTemplate?


      • #4
        The only use case I can think of is it's collaborators, such as the completion policy. I've personally worked with a project that had a custom completion policy to stop the job immediately after the batch window had passed. I've seen others in the past that needed to throttle the commit interval once the batch window had passed as well. There may be a couple scenarios where you might need a custom ExceptionHandler as well, but hopefully we've provided enough hooks so that it's only necessary in a small minority of cases.