Announcement Announcement Module
Collapse
No announcement yet.
ItemReader and ItemWriter for my scenario Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ItemReader and ItemWriter for my scenario

    Hi All,

    I have a scenario for which i am not able to decide which ItemReader and ItemWriter to use.

    My flat file is of the following format

    Code:
    1;abcd;xyz;abc;123
    2;xyz;abcd;1234
    3;dhfjds;sdjfhsdj;sdfjhj
    3;djfhsdj;asdewr;ghgfh;sdfsdf
    2;dhsfgh;sdfds;sdfsd;sdfsd;adas
    3;gdfjghj;dfgdf;asdfsad;fghdfh;dsfsd
    4;dhfgh;sdfsd;sdfsdf;sdfsd;sdf
    4;dhfgh;sdfsd;fsdf
    4;dhfgh;dskfjdsjkfkd;sdjfhsdj
    1;dshfj;sjdfhsdj;sjdfhsdj;sdfs
    2;xyz;abcd;1234
    3;dhfjds;sdjfhsdj;sdfjhj
    2;dhsfgh;sdfds;sdfsd;sdfsd;adas
    3;gdfjghj;dfgdf;asdfsad;fghdfh;dsfsd
    4;dhfgh;dskfjdsjkfkd;sdjfhsdj
    4;dhfgh;dskfjdsjkfkd;sdjfhsdj
    1 - Object1
    2 - Object2
    3 - Object3
    4 - Object4

    Object1 is composed of Object2 and Object4.
    Object2 is composed of Object3.

    Which reader do i need to use for this scenario?

    Similarly i want to persist Object1 with all its composed Objects in one shot. I want a transaction boundary for each Object1 persistence. How do i achieve this?

    Which writer can I use for this scenario?

    Thanks
    Venkatesh

  • #2
    I think the writer is fairly simple. Writing out an object of composed objects isn't difficult. If you're writing to a Database, it's simple. If you're writing to a flat file, you'll need to tell the aggregator how to flatten the object using the FieldSetCreator interface.

    In terms of reading, you're going to have to use a composite pattern in multiple places. It's a bit easier in 2.0, but in 1.1 you'll need a composite reader that contains a FlatFileItemReader, and you'll likely need Composite tokenizers and mappers as well. In this way you can call reader multiple times. It will still be somewhat tricky though. I had a client with a similar problem who ultimately decided to write their own custom reader.

    Comment


    • #3
      Thanks for the reply.

      I'll give a shot at the composite readers. One thing I am a bit worried about is that since i have multiple readers and mappers, my code becomes a bit messy in terms of deciding which ones to invoke. How do we make it clean?

      Thanks
      Venkatesh

      Comment


      • #4
        I understand what you're saying, since the various components will be somewhat tightly coupled. In 1.1, there isn't much option but to accept that or 'roll your own' so to speak. In 2.0, we've broadened the interface somewhat, which will give better control in these types of scenarios.

        Comment


        • #5
          Thanks for the update. I'll go with some custom implementation now.

          Comment

          Working...
          X