在Mule(3.8.1)和Anypoint Studio(6.2.1)中从SQL Server 2016获取结果集

时间:2017-01-20 19:57:00

标签: mule mule-component

在当前的Mule流程中,我能够在SQL Server 2016中执行存储过程,结果集将以{resultSet1 = [{ROWEXISTS = 1}]}的形式返回。这将命中一个流变量rowExists,我将使用变量集进一步做出决定。我期望从存储过程中获得的值是0或1,它在ROWEXISTS列中正确返回。现在我的问题是我如何从结果集中访问ROWEXISTS列。我尝试了#[payload.get(0).ROWEXISTS]和#[payload.get(0)['ROWEXISTS']]等。但没有运气。它会给我一个错误或者为空。

我正在使用的示例XML Payload如下所示。我将从XML有效负载中提取EmployeeNumber并执行存储过程以丰富消息。目标变量#[flowVars.rowExists]。但我在这里看到的是从存储过程中得到的0或1的具体值。 我无法检索该值。任何帮助都非常感谢。

 <Employees>
    <Employee>
            <CompanyCode>SMBMI</CompanyCode>
            <EmployeeLastName>LastName1</EmployeeLastName>
            <EmployeeFirstName>FirstName1</EmployeeFirstName>
            <MiddleName/>
            <EmployeeNumber>00479</EmployeeNumber>
            <Department>Public Safety</Department>
    </Employee>
    <Employee>
            <CompanyCode>SMBMI</CompanyCode>
            <EmployeeLastName>LastName2</EmployeeLastName>
            <EmployeeFirstName>FirstName2</EmployeeFirstName>
            <MiddleName/>
            <EmployeeNumber>08945</EmployeeNumber>
            <Department>Transport</Department>
    </Employee>
</Employees>                    

Mule flow xml在下面给出

<flow name="DBtest" >
        <file:inbound-endpoint path="C:\Backup\Files\Input" moveToDirectory="C:\Backup\Files\Output" connector-ref="FileGodsake" responseTimeout="10000" doc:name="File">
            <file:filename-regex-filter pattern="(EmployeeList){1}.*(\.xml)" caseSensitive="true"/>
        </file:inbound-endpoint>
        <splitter expression="#[xpath3('//Employee',payload,'NODESET')]" doc:name="Splitter"/>
        <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
        <enricher  target="#[flowVars.rowExists]" doc:name="Message Enricher">
            <db:stored-procedure config-ref="adventure" doc:name="Check Employee Exists">
                <db:parameterized-query><![CDATA[{CALL EmployeeExists (:EmployeeNumber)}]]></db:parameterized-query>
                <db:in-param name="EmployeeNumber" value="#[xpath3('//EmployeeNumber',payload,'STRING')]"/>
            </db:stored-procedure>
        </enricher>
        <logger message="Employee Number:  #[xpath3('//EmployeeNumber',payload,'STRING')] and If Exists is #[flowVars.rowExists] . The get request #[flowVars.rowExists]" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[flowVars.rowExists]">
                <db:stored-procedure config-ref="adventure" doc:name="Update Employee">
                    <db:parameterized-query><![CDATA[{CALL UpdateEmployee (:CompanyCode,:EmployeeLastName,:EmployeeFirstName,:MiddleName,:EmployeeNumber,:Department
,:DeptNumber)}]]></db:parameterized-query>
                    <db:in-param name="CompanyCode" type="VARCHAR" value="#[xpath3('//CompanyCode',payload,'STRING')]"/>
                    <db:in-param name="EmployeeLastName" type="VARCHAR" value="#[xpath3('//EmployeeLastName',payload,'STRING')]"/>
                    <db:in-param name="EmployeeFirstName" type="VARCHAR" value="#[xpath3('//EmployeeFirstName',payload,'STRING')]"/>
                    <db:in-param name="MiddleName" type="VARCHAR" value="#[xpath3('//MiddleName',payload,'STRING')]"/>
                    <db:in-param name="EmployeeNumber" type="VARCHAR" value="#[xpath3('//EmployeeNumber',payload,'STRING')]"/>
                    <db:in-param name="Department" type="VARCHAR" value="#[xpath3('//Department',payload,'STRING')]"/>
                 </db:stored-procedure>
            </when>
            <otherwise>
                <db:stored-procedure config-ref="adventure" doc:name="Insert Employee">
                    <db:parameterized-query><![CDATA[{CALL InsertEmployee (:CompanyCode,:EmployeeLastName,:EmployeeFirstName,:MiddleName,:EmployeeNumber,:Department)}]]></db:parameterized-query>
                    <db:in-param name="CompanyCode" type="VARCHAR" value="#[xpath3('//CompanyCode',payload,'STRING')]"/>
                    <db:in-param name="EmployeeLastName" type="VARCHAR" value="#[xpath3('//EmployeeLastName',payload,'STRING')]"/>
                    <db:in-param name="EmployeeFirstName" type="VARCHAR" value="#[xpath3('//EmployeeFirstName',payload,'STRING')]"/>
                    <db:in-param name="MiddleName" type="VARCHAR" value="#[xpath3('//MiddleName',payload,'STRING')]"/>
                    <db:in-param name="EmployeeNumber" type="VARCHAR" value="#[xpath3('//EmployeeNumber',payload,'STRING')]"/>
                    <db:in-param name="Department" type="VARCHAR" value="#[xpath3('//Department',payload,'STRING')]"/>                
        </db:stored-procedure>
            </otherwise>
        </choice>
 </flow >  

我希望将ROWEXISTS的值提取并更新到目标变量rowExists

2 个答案:

答案 0 :(得分:0)

试试这个表达式 - #[payload.resultSet1.get(0).ROWEXISTS]

答案 1 :(得分:0)

确定。我打算给Senthil。 Enricher来源应该是

[payload.resultSet1.get(0)== .ROWEXISTS 1]。根据行返回为1还是0

,这将评估为true或false