|
[
Permlink
| « Hide
]
Dave Syer added a comment - 26/May/08 07:11 AM
It's pretty unusual I would say to need the line number to create a domain object (what would it mean in business terms?). Can't you add a column to the file that is being read with the extra information you need?
I am not really constructing a pure domain object, but rather a holder for a domain object that contains additional technical information attached to it; the goal is to be aware of the line number we are treating in the writer.
This is not possible to add a column to the input file, as I do not control it (I receive it from a third party). Anyway, I cannot imagine a file that contains the line number as the first field of each line; this information must be held by the parser of the file itself (this is actually what LineReader.getPosition() does).
Further, holding line number in the file would prevent any operation on it : split file in smaller portions, re-order, remove or add lines. Dave, can we really make a change like that in a point release? Won't this change break everyone's FieldSetMappers?
This issue is superceded by
closed inappropriately -
> I am not really constructing a pure domain object, but rather a holder for a domain object that contains additional technical information attached to it; the goal is to be aware of the line number we are treating in the writer.
Gaetan, would implementing ItemReadListener and counting reads do the job? Passing the line number from the input file to writer through the item inevitably leads to spaghetti code I think. The question only is whether the spaghetti is in user's or framework's code - line number needs to cut through all abstractions between the raw line and domain object. There must be a better way (at least I hope so). On seconds thoughts ItemReadListener won't help due to rollbacks and restart.
How about this: FlatFileItemReader and ResourceLineReader can expose a getter for current line number. ItemProcessor that wants to bundle the line number with the item would then be coupled to the reader (have a reference to the reader bean in Spring config). This issue is now superceded by
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||