1

I'm supposed to extract data from a particular database and put it into an XML file.

But the data can only be obtained by doing multiple select queries to different tables of the database.

Here is my configuration:

<!-- Reader for getting msisdn -->
<bean id="pagingdbItemReader2"
    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 SUBSTR(DN_NUM,4) AS MSISDN" />
            <property name="fromClause"
                value="FROM contr_services_cap cs, directory_number d" />
            <property name="whereClause"
                value="WHERE co_id in (select co_id from contract_all where customer_id =:CUSTOMER_ID)
                        AND cs.dn_id = d.dn_id 
                        AND cs.sncode = 1 
                        AND CS.MAIN_DIRNUM = 'X'" />
            <property name="sortKey" value="MSISDN" />
        </bean>
    </property>
    <property name="parameterValues">
        <map>
            <entry key="CUSTOMER_ID" value="#{jobParameters['CUSTOMER_ID']}" />
        </map>
    </property>
    <property name="pageSize" value="10" />
    <property name="rowMapper">
        <bean class="com.ooredoo.model.inputDB.MSISDNRowMapper" />
    </property>
</bean>

<!-- Writer for getting msisdn -->
<bean id="dbItemWriter2" class="org.springframework.batch.item.xml.StaxEventItemWriter">
    <property name="resource" value="file:xml/outputs/DonneesFactureFromDB.xml" />
    <property name="marshaller" ref="dbMarshaller2" />
    <property name="rootTagName" value="Facture" />
</bean>

<!-- Marshaller for getting msisdn -->
<bean id="dbMarshaller2" class="org.springframework.oxm.xstream.XStreamMarshaller">
    <property name="aliases">
        <util:map id="aliases">
            <entry key="msisdn" value="com.ooredoo.model.inputDB.MSISDN" />
        </util:map>
    </property>
</bean>

Shall I do ALL this config (and create corresponding java classes) for EVERY query ?


EDIT:

I've done this config to extract data from database using a query "A" (And it worked). So my question is: Am I supposed to write the same configuration (with the reader, the writer, the marshaller...etc) for EVERY query I want to execute... or can I write maybe a kind of "group of queries" that can be executed one after the other and render their results to be written in ONE XML file ???

Sinda MOKADDEM
  • 796
  • 2
  • 12
  • 35
  • Shall I write my own custom writer ? – Sinda MOKADDEM Oct 17 '14 at 17:17
  • Nobody has an idea for my problem :( ? – Sinda MOKADDEM Oct 20 '14 at 09:01
  • Sorry, the question is too broad. And it seems nothing to do with JAXB as you are apparently using XStream. – lexicore Oct 20 '14 at 09:18
  • OK, let me specify my question: I've done this config to extract data from database using a query "A" (And it worked). So my question is: Am I supposed to write the same configuration (with the reader, the writer, the marshaller...etc) for EVERY query I want to execute... or can I write maybe a sort of "group of queries" that can be executed one after the other and render their results to be written in ONE XML file ??? – Sinda MOKADDEM Oct 20 '14 at 09:29
  • Please notice that I tried to make the same configuration for a second query "B", but the result of query "A" were overwritten by the data of query "B" in the XML file. That's why I believe that making a configuration for each query is NOT the right way to do. – Sinda MOKADDEM Oct 20 '14 at 09:31
  • Please notice also that I'm really new at spring batch – Sinda MOKADDEM Oct 20 '14 at 09:32
  • Please edit your question to explain what you want. (And sorry, I won't be able to help as I don't have the relevant experience in spring batch. I have edited the tags to attract the right audience, hope it helps.) – lexicore Oct 20 '14 at 09:55
  • I explained want I want in my previous comments... – Sinda MOKADDEM Oct 20 '14 at 09:56
  • It is better to include the relevant information in the question itself, not in the comments. – lexicore Oct 20 '14 at 09:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63330/discussion-between-siho-and-lexicore). – Sinda MOKADDEM Oct 20 '14 at 10:03

1 Answers1

0

I think you need to create multiple readers having each queries and then chain them together using composite pattern.

HTH

aalmero
  • 345
  • 2
  • 18
  • Could you please provide sample code or link to support your answer? –  Apr 02 '16 at 07:44