Announcement Announcement Module
No announcement yet.
How can I pass different objects to different writers in CompositeItemWriter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I pass different objects to different writers in CompositeItemWriter

    Hi.. My app reads a single object from the DB, processes it and writes 2 objects to 2 different tables. I tried using CompositeItemWriter and registered 2 different item writers with it. But I found that it passes the same List of objects to both writers. Is there any built-in support for passing different objects to different itemwiters or do I have to handle that programatically ?

  • #2
    Look at the footballJob example in the spring batch samples, it uses a DAO to write. Here you can just use jdbctemplate to write your 2 objects to different tables


    • #3
      I checked out the football job example. But there the job consists of a number of steps, each having an ItemReader, ItemProcessor and an ItemWriter which calls a DAO for the database write. My job has only one step, where you read one object, process it and split it into two objects and write those objects to 2 different tables. My question was if an itemprocessor can be configured to give the 2 different object to two different writers (DAOs) or can we have two itemprocessors which are called by the ItemReader? . This will make my design simpler by keeping the 2 output objects decoupled. If I handle it myself, then I have to write a class composed of the two objects and write a method int it to call the respective DAOs one by one. I hope this makes my problem clearer.



      • #4
        How about implementing your own Customwriter, having 2 delegates. in your write method, break up your object into 2 objects, and in turn call the write method on the delegate of choice for each of your 2 created objects.

        I know Dave has done some work in a Classifier pattern in this regard.


        • #5
          ClassifierCompositeItemWriter will be in RC2 (and in snapshots for about a week now).