Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: skipListener : howto get the item read

  1. #11
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    That was quite a long post, but it looks to me like you're generally happy except for two points:

    1) If calling fieldSet.read* fails, you get a FlatFileParseException, which contains the original line and the line number of the file, but you don't get the FieldSet itself. I'm not quite sure I understand why this is a problem? What advantage would having the FieldSet give you over having the original line itself? Since trying to parse the FieldSet has already caused an error, it seems like all you would want to do is log out the original line that was parsed into the fieldset?

    2) If you are able to create an 'Item' successfully from the FieldSetMapper (or any other ItemReader) and it fails Validation, you have no way of getting the item from any Spring Batch listener. This is a valid issue, and I hope it's tracked in Jira (if not, please add it). However, it's an interesting issue from an API standpoint. There's a general contract in the ItemReader API that it either returns an item (i.e. reads successfully) or fails by throwing an Exception. I don't see anyway to support this scenario without some fairly major changes to the api so that you could have a validator separate from the ItemReader but before the ItemWriter. This would be part of a much bigger change that would have to be handled as a 2.0 issue. However, there may be a much better workaround for 1.1. There's an issue here to be able to select which exceptions cause rollback or not. Therefore, you could put your validation in the ItemWriter, and list a validation exception as something that shouldn't cause rollback. In that way you would have your item to log out, but wouldn't have the extra unnecessary rollback. I actually have a client doing this now by inserting a custom ExceptionHandler in the chunkOperations, so it's doable even in 1.0, but it should be much cleaner in 1.1.

  2. #12
    Join Date
    Jul 2005
    Posts
    156

    Default

    you're generally happy except for two points
    Yes !

    1)
    Since trying to parse the FieldSet has already caused an error, it seems like all you would want to do is log out the original line that was parsed into the fieldset?
    You're right I only want it for logging purposes and better localizing the error.
    This is for me an improvement but really not essential since I already got err.getMessage() which gives the value of the field in error.

    2) Thanks for the explanation !
    I'll wait for 1.1 for this one.

    3) Just one more question :

    why don't you nest the original item in org.springframework.batch.item.validator.Validatio nException ?
    i.e. adding a method getObjectInError or shting like that (similar to FlatFileParseException).

    Thanks very much for your input !

  3. #13
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    3) So you're asking for a ValidationException that contains the item? I suppose we could do that (although it would be fairly easy for users of the framework to setup themselves) I still kind of like pushing the validation to the ItemWriter and using other controls to prevent rollback.

  4. #14
    Join Date
    Jul 2005
    Posts
    156

    Default

    3) So you're asking for a ValidationException
    Yes.
    I know it would be rather easy to do it myself, but I really would prefer to have it done in Spring Batch if it's a common need.

    I still kind of like pushing the validation to the ItemWriter and using other controls to prevent rollback.
    In fact I was always doing my business validations in a Transformer, but stop ped using this when I discovered that any exception caused the rollback of the chunk.
    Would you advice (from a generic viewpoint) to do business validation (or whatever validation) in a transformer (during the write process), or in a itemReaderDelegate (read process) ?

    Thanks

  5. #15
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    The more I think about it, the more it makes sense to do validation in the ItemWriter, leaving an ItemReader to completely focus on generating a valid Item (even if it's from multiple sources) Of course the problem now is rollback, but once that's solved in 1.1 it will be my general recommendation.

  6. #16
    Join Date
    Jul 2005
    Posts
    156

    Default

    Thanks very much for you help Lucas.

    Sorry for the long thread, but it helped me understand some fundamentals of Spring batch.

  7. #17
    Join Date
    Jul 2005
    Posts
    156

    Default

    3) So you're asking for a ValidationException that contains the item? I suppose we could do that
    Added in JIRA http://jira.springframework.org/browse/BATCH-587.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •