如何在mule studio应用程序中访问jdbc端点中的流量变量

时间:2014-01-07 14:55:11

标签: mule

<jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="root" password="root" url="jdbc:mysql://localhost:3306/test" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
<jdbc-ee:connector name="test" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<data-mapper:config name="DataMapper" transformationGraphPath="mapper.grf" doc:name="DataMapper"/>
<flow name="EmployeeListFlow1" doc:name="EmployeeListFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="employeelist"/>
    <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"/>
    <choice doc:name="Choice">
        <when expression="payload.storeId == null || payload.storeId &lt;= 0 ">
            <set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where companyid = #[message.payload.companyId]" doc:name="CompanyId"/>
        </when>
        <otherwise>
            <set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid =#[message.payload.storeId] )" doc:name="StoreId"/>
        </otherwise>
    </choice>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response"  queryTimeout="-1" doc:name="EmployeeListFetch" connector-ref="Theatro" queryKey="employees_list">
        <jdbc-ee:query key="employees_list" value="#[flowVars['query']]"/>
    </jdbc-ee:outbound-endpoint>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

例外:

Root异常堆栈跟踪: java.lang.IllegalArgumentException:找不到SQL语句的SQL策略:#[flowVars ['query']]     在com.mulesoft.mule.transport.jdbc.sqlstrategy.EESqlStatementStrategyFactory.create(EESqlStatementStrategyFactory.java:109)     at org.mule.transport.jdbc.JdbcMessageDispatcher.doSend(JdbcMessageDispatcher.java:69)     在org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:81)     + 3个以上(设置调试级别日志记录或'-Dmule.verbose.exceptions = true'用于所有内容)

这里我想基于输入动态构建jdbc查询。

json data {“companyId”:“1”,“storeId”:“1”} 请帮帮我。

2 个答案:

答案 0 :(得分:0)

尝试使用类似以下内容的jdbc动态出站端点:

<outbound-endpoint address="jdbc://select * from ${datasource.table} #[variable:where-statement]" exchange-pattern="request-response"/>

HTH

答案 1 :(得分:0)

这里有2个错误,
在选择中,表达式缺失[]
类似<when expression="[payload.storeId == null || payload.storeId &lt;= 0] ">的东西 接下来你的查询应该是这样的: -

select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid ='#[message.payload.storeId]' )  

#[message.payload.storeId]应位于''内,因为storeId是一个字符串