1
votes

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 ???

1
Shall I write my own custom writer ?Sinda MOKADDEM
Nobody has an idea for my problem :( ?Sinda MOKADDEM
Sorry, the question is too broad. And it seems nothing to do with JAXB as you are apparently using XStream.lexicore
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
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

1 Answers

0
votes

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

HTH