Variable fields within fixed field in beanio

246 views
Skip to first unread message

rs

unread,
Jan 27, 2016, 1:40:38 AM1/27/16
to beanio-users
Greetings,

I am using beanio + Spring batch in order to read records from the database and write it to a fixed length flat file. One of the fields within the flat file (say, variableData) which is 40 bytes long is composed of different columns starting at different positions, overlapping in nature based upon certain conditions in the databse record.

For example,


Parent Field Name - VariableData (Length = 40; Starting position = 203; End position = 242)

If condition1 = true, then - 
Child Field 1 - field1 (Length = 4; Starting position = 203; End position = 206)
Child Field 2 - field2 (Length = 35; Starting position = 207; End position = 241)
Child Field 3 - field3 (Length = 1; Starting position = 242; End position = 242)

If condition2 = true, then - 
Child Field 1 - field1 (Length = 6; Starting position = 203; End position = 208)
Child Field 2 - field2 (Length = 31; Starting position = 209; End position = 239)
Child Field 3 - field3 (Length = 1; Starting position = 240; End position = 240)
Child Field 4 - field4 (Length = 2; Starting position = 241; End position = 242)

Note: Condition1 and Condition2 is derived from multiple values in the record

Please advise whether its possible to accomplish this w/ beanio and if yes, how?

Thanks,
Riddhi



Vitalii Tymchyshyn

unread,
Jan 27, 2016, 7:45:55 AM1/27/16
to beanio-users

Please describe the conditions in more detail.


Ср, 27 січ. 2016 01:40 rs <riddhi...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rs

unread,
Jan 27, 2016, 9:54:08 AM1/27/16
to beanio-users
Greetings,

//condition1:
if (dbColVal1.equalsIgnoreCase("2") | dbColVal1.equalsIgnoreCase("5") && item.dbColVal2.equalsIgnoreCase("ABC")) {
VariableData should be composed ONLY of the following fields:
Child Field 1 - field1 (Length = 4; Starting position = 203; End position = 206)
Child Field 2 - field2 (Length = 35; Starting position = 207; End position = 241)
Child Field 3 - field3 (Length = 1; Starting position = 242; End position = 242)
//condition2:
else if (dbColVal2.equalsIgnoreCase("XYZ") | dbColVal2.equalsIgnoreCase("QWR")) {
VariableData should be composed ONLY of the following fields:
Child Field 4 - field4 (Length = 6; Starting position = 203; End position = 208)
Child Field 5 - field5 (Length = 31; Starting position = 209; End position = 239)
Child Field 6 - field6 (Length = 1; Starting position = 240; End position = 240)
Child Field 7 - field7 (Length = 2; Starting position = 241; End position = 242)
} //default condition:
else {
VariableData should be  a filler of length = 40
}


Based upon the condition, the VariableData field should ONLY be composed of any one set of child fields. The database columns - dbColVal1 & dbColVal2 is returned by the Spring Batch reader by querying the database. Basically, is there any way in beanio to implement segments based upon if-else condition?

Please advise.

Thanks,
Riddhi
------------------------------------------------------------------------------------------------------

Vitalii Tymchyshyn

unread,
Jan 27, 2016, 8:52:22 PM1/27/16
to beanio-users
Well, for marshalling, I think the easiest is to preprocess your items by wrapping them into 1 of three different value holder classes depending on the condition check result and add three records to single beanio stream identified by the corresponding class.

Best regards, Vitalii Tymchyshyn

Ср, 27 січ. 2016 о 09:54 rs <riddhi...@gmail.com> пише:
Reply all
Reply to author
Forward
0 new messages