Announcement Announcement Module
Collapse
No announcement yet.
Alter the fieldset value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alter the fieldset value

    Hi,

    I want to read from a file and checks some conditions on record and do some changes on few fields then after write to database.
    Do to this, first I thought read record and do the verification of conditions and alteration of field values on FieldSet then write to database. But the implemetation class for FieldSet is provided by frame work. So I cant do that.
    Please guide me to solve this issue.

    Thanks in advance,
    Shahul

  • #2
    There is a related issue: http://jira.springframework.org/browse/BATCH-394

    Currently you'll need to create new modified FieldSet instance rather than change values in the original instance.

    Comment


    • #3
      Couldn't you change some of the fields when you put them into a domain object?

      Comment


      • #4
        I am not using any specific VO classes, instead we are using map.

        I have two options.
        One is, alter the values just after creating tokens of fields but before creating fieldset. So we can instantiate fieldset with updated values.
        Second one is, extend our DefaultFieldSet class with options to updated the tokens. So we can alter the values just after tokenizing but before the fieldsetmapper.

        Please guide me to take a solution.

        ~Shahul

        Comment


        • #5
          I'm still confused, can't you alter the values when moving them from the fieldset to the map?

          Comment


          • #6
            Yes Lucas, We can alter the values in map. But I want to segregate that functions with creation of map. Because the alteration is little bit trickier. More of that, according to some values, i need to skip entire record from writing to database. Thats why I am thinking for a better solution.

            Comment


            • #7
              The skip part is easy, just throw an exception, and configure it as skippable. To be honest, I think modifying the values in the map is still your best option. A FieldSet is immutable for good reason, it is purely a transfer mechanism. If you absolutely don't want to do it in the map, put another abstraction between the fieldset and the map, but I would still leave the FieldSet alone.

              Comment


              • #8
                Thanks Lucas for your valuable suggestion. I will put a abstraction between fieldset and map such that create a new instance of fieldset using updated values in original instance of fieldset.
                I didnt understand to skip record using exception, please guide me.

                Comment


                • #9
                  Lucas,

                  I think above method also change the fieldset indirectly by creating new fieldset using updated values. Is it ok? I took the suggestion of Robert. Please guide me.

                  Comment


                  • #10
                    Here's the section in the documentation about configuring skip:

                    http://static.springframework.org/sp...n.html#d0e3747

                    You could use another FieldSet as your abstraction if you like, although it might be a bit overkill depending upon how many fields you need to alter.

                    Comment


                    • #11
                      Thanks Lucas and Robert for your valuable suggestions...

                      Comment

                      Working...
                      X