Announcement Announcement Module
Collapse
No announcement yet.
springBatch- include arraylists dynamically to beanrowmapper of JdbcCursorItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • springBatch- include arraylists dynamically to beanrowmapper of JdbcCursorItemReader

    I read from the database using JdbcCursorItemReader and for each of the rows, need to invoke another web service which returns a list of values for each request. And need to write it to a flatfile.

    Say my reader retruns 2 rows.
    ref id serviceNo
    ref1 s1
    ref2 s2

    for each of the serviceNo, in the process method of chunk processor, I make a web service call and first one returns 2 and second returns 3 values in the response.

    The flat file that I get is
    ref id serviceNo account no branch
    ref1 s1 acc_b branch_b
    ref2 s2 acc_e branch_e

    I am looking for values like this in the flat file
    ref id serviceNo account no branch
    ref1 s1 acc_a branch_a
    ref1 s1 acc_b branch_b
    ref2 s2 acc_q branch_q
    ref2 s2 acc_w branch_w
    ref2 s2 acc_e branch_e


    for the flatfilewriter bean in the context.xml I have <property name="fieldExtractor">
    <bean class="org.springframework.batch.item.file.transfo rm.BeanWrapperFieldExtractor">
    <property name="names" value="refId,serviceNo,accountNo,branch" />
    </bean>
    </property>

    How do I provide accountNo and branch as an arrayList here?

    Anyone has suggestion on how to generate the number the rows in the flat file dynamically after reading from a database?

  • #2
    Basically, I need to use arraylist inside the property name of BeanWrapperFieldExtractor.

    may be something similar to this
    <property name="fieldExtractor">
    <bean class="org.springframework.batch.item.file.transfo rm.BeanWrapperFieldExtractor">
    <property name="names" value="refId,serviceNo,ws.accountNo,ws.branch" />
    </bean>
    </property>

    Comment


    • #3
      1. Please use [CODE] tags when posting configuration and other fixed width information so it is readable.
      2. What does your item look like (both the input into the processor and the output of the processor)?

      Comment


      • #4
        My rowMapper from the JDBCCursorItemRaeder has 2 fields.
        ref, sName

        For each sName, I invoke the web service and it returns the list of detailsBean.

        public class DataBean {

        private String ref;
        private String sName;
        private List<DetailsBean> wsBeanList;
        ....
        }

        public class DetailsBean {
        private String accNo;
        private String branch;
        ...
        }

        My input and output to the ItemProcessor should be DataBean.


        So, I am wondering how do I associate this list of DetailsBean(the accNo and branch) and iterate it in the below context.xml

        <bean id="flatFileWriter" class="org.springframework.batch.item.file.FlatFil eItemWriter">
        <property name="resource" value="file:C://test.txt" />
        <property name="headerCallback">
        <bean class="test.HeaderCallBack" />
        </property>
        <property name="lineAggregator">
        <bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineAggregator">
        <property name="delimiter" value="" />
        <property name="fieldExtractor">
        <bean class="org.springframework.batch.item.file.transfo rm.BeanWrapperFieldExtractor">
        <property name="names" value="ref,sName,accNo,branch" />
        </bean>
        </property>
        </bean>
        </property>

        Comment


        • #5
          You can't dynamically map the list the way you have it with the BeanWrapperFieldExtractor. The way you have it configured, the FieldExtractor will look for a ref, sName, accNo and branch attribute on the DataBean. I think you could do something like wsBeanList[0].acctNo but that would hardcode the index. Your best bet would be to write your own FieldExtractor implementation that iterates over the wsBeanList elements to generate the required String.

          Comment


          • #6
            Thanks for your suggestion. I am able to create my own customFieldExtractor to display the list of arrays using new lines.

            Comment

            Working...
            X