0

I have spring batch config xml as below .If I use row mapper method ,it processing one result set at a time. but I need to process 10 result set to make into one xml file. The first half of the result set going to contain same results for all the 10 result set. the other half for the ten result sets are going to different address values. Based on the each id, I need to provide ten set of address. Each provider can have 5 addresses. How can I implement this .I think row mapper is not the proper one for this scenario. Please suggest the suitable solution.

<bean id="pagingItemReader"
        class="org.springframework.batch.item.database.JdbcPagingItemReader"
        scope="step">
        <property name="dataSource" ref="dataSource" />
        <property name="queryProvider">
          <bean
            class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="selectClause" value="select *" />
            <property name="fromClause" value="from extract_VIEW" />
             <property name="sortKey" value="PR_EXTRCT_ID" /> 
          </bean>
        </property>
            <property name="pageSize" value="100" />
        <property name="rowMapper">
            <bean class="com.pr.comp.PrdrDataExtractRowMapper" />
        </property>
      </bean>
    <bean id="xmlItemWriter" class="com.PR.comp.IndentingStaxEventItemWriter">
        <property name="resource"  value="file:xml1/output/pre1.xml" />
        <property name="encoding" value="UTF-8" />
        <property name="version" value="1.0" />
        <property name="marshaller" ref="reportMarshaller" />
        <property name="rootTagName" value="PrDtaReqst1"/> 
        <!-- TRUE means, that output file will be overwritten if exists - default is TRUE -->
        <property name="overwriteOutput" value="true" />
    </bean>

     <bean id="reportMarshaller"
            class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <value>com.pr.comp.model.jaxb.some.PrDataRequest</value>
            </property>`enter code here`
        </bean> 

        <batch:job id="someprocessingJob">
            <batch:step id="step1">
                <batch:tasklet>
                    <!-- <batch:chunk reader="dbItemReader" -->
                    <batch:chunk reader="pagingItemReader"
                        processor="itemProcessor"
                        writer="xmlItemWriter" 
                        commit-interval="100" />
                </batch:tasklet>
            </batch:step>
        </batch:job>

I need the output like below

    <root element>
     <Header>
        <HeaderCode></HeaderCode>       
      </Header>
      <PrDetailsRequest>
        <UniqueIdentifier>1</UniqueIdentifier>
          <PersonGroupName>
          <FirstName></FirstName>
          <MiddleInitialName></MiddleInitialName>
          <LastName> mm</LastName>
        </PersonGroupName>   
        <PrStatus>active</PrStatus>
        <prAddress>
          <AddressLine1>address1</AddressLine1>
          <AddressLine2>address2</AddressLine2>
          <CityName>everett</CityName>
          <State>WA</State>
          <Zip>2222</Zip>
          <CountryCode></CountryCode>
          <PhoneNumber>2222222222</PhoneNumber>         
          <Suffix>suffix</Suffix>
          <indicator>N</indicator>
        </prAddress>
        <prAddress>
          <AddressLine1>address21</AddressLine1>
          <AddressLine2>address22</AddressLine2>
          <CityName>everett</CityName>
          <State>WA</State>
          <Zip>2222</Zip>
          <CountryCode></CountryCode>
          <PhoneNumber>6666622</PhoneNumber>         
          <Suffix>suffix</Suffix>
          <indicator>N</indicator>
        </prAddress><prAddress>
          <AddressLine1>address23</AddressLine1>
          <AddressLine2>address24</AddressLine2>
          <CityName>everett</CityName>
          <State>WA</State>
          <Zip>2222</Zip>
          <CountryCode></CountryCode>
          <PhoneNumber>2222222222</PhoneNumber>         
          <Suffix>suffix</Suffix>
          <indicator>N</indicator>        
          </rootelement>    
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
juniper
  • 11
  • 2
  • 4

1 Answers1

0

I happen to have written a ControlBreakItemReader<ITEM, RECORD, KEY> which implements an ItemReader<ITEM> based on the control-break algorithm. It seems to fit your use case. You would need to create a model class ITEM representing the root element of your XML schema, and a KEY type corresponding to your <UniqueIdentifier>. The rows returned by pagingItemReader are of type RECORD (could be e.g. a Map containing the key-value pairs of each row). Then you need to inject basically two lambdas:

  • keyExtractor which extracts the unique identifier from each RECORD
  • itemUpdater which updates the ITEM under construction from the next RECORD

I hope the provided test cases help to understand how it works.

Stefan Reisner
  • 607
  • 5
  • 12