简体   繁体   中英

Mule Database Connector Multiple Queries

I am running multiple select queries and I want them to run one after the other. In this example, I select account numbers then use those numbers in the following query. Will the queries run consecutively one after the other ie next query only runs after the previous query has finished. Do I need to wrap them in a composite-source and wrap them in a transaction? What would that look like?

    <flow name="PopulateAccount">
          <db:select config-ref="dsConfig" doc:name="Get Account ID">
           <db:paramterized-query><![CDATA[

               SELECT ACC_NUM....
           </db:select>

           <custom-transformer class="com.vf.ListTransformer">

           <set-session-variable variableName="messageID" value="#[payload]" 
                              doc:name="Set Account IDs"/>


         <!-- The next query depends on the Account IDS from
               previous results in the session variable -->

        <db:select config-ref="dsConfig" doc:name="Get Account Detail">
           <db:paramterized-query><![CDATA[
               SELECT ACC_NAME,....
           </db:select>
         <custom-transformer class="com.vf.AccountsTransformer">

          <!-- More database operations ---> 
    </flow>

Will the queries run consecutively one after the other

yes, as long as you do not take any measures to run them in parallel, like for example moving the database component in a separate flow and call it in a asynchronous way.

Do I need to wrap them in a composite-source

no, especially not if you use the result of the first query in the second query (like in your example)

and wrap them in a transaction

why? you are not inserting/updating anything in your example.

What would that look like?

just like in your example. the only thing i would change is the way how you store the result of your first query. although there is nothing wrong with using set-variable i prefer using a enricher to store result of a component in variable instead of changing the payload and setting the variable afterwards.

<flow name="testFlow">
    <enricher target="#[flowVars.messageID]" doc:name="Message Enricher">
        <db:select config-ref="MySQL_Configuration" doc:name="select ACC_NUM">
            <db:parameterized-query><![CDATA[SELECT ACC_NUM ...]]></db:parameterized-query>
        </db:select>
    </enricher>
</flow>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM