如何从Mule 3.5数据库连接器中的属性文件读取SQL查询 [英] How to read SQL queries from properties file in Mule 3.5 Database connector

查看:61
本文介绍了如何从Mule 3.5数据库连接器中的属性文件读取SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Mule 3.5数据库连接器从数据库中获取数据的Mule流...我的Mule流如下:-

I have a Mule flow which is fetching Data from Database using Mule 3.5 Database connector ... My Mule Flow is following :-

<flow name="BestelItems" doc:name="BestelItems">
 <poll doc:name="Poll">
 <fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
  <db:select config-ref="Generic_Database_Configuration" doc:name="Database">
     <db:parameterized-query><![CDATA[select * from getData]]></db:parameterized-query>
 </db:select>
  </poll>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<logger message="Payload :- #[message.payload]" level="INFO" doc:name="Logger" />
</flow>

现在这可以正常工作,并从数据库中获取所有数据,并使用logger ..在控制台中显示.

Now this works fine and fetch all the Data from DB and display in console using logger ..

现在的问题是,如果我尝试从属性文件中读取查询,则会引发异常……例如,如果我将SQL查询select * from getData放入属性文件中,如下所示:-QueryFromPropertyfile= select * from getData然后尝试读取流中的值,例如:-

Now the issue is, if I try to read the query from a property file then it throws an exception ... for example if I put the SQL query select * from getData in a Property file like the following :- QueryFromPropertyfile= select * from getData and then try to read the value in the flow like :-

 <db:select config-ref="Generic_Database_Configuration" doc:name="Database">
   <db:parameterized-query><![CDATA[${QueryFromPropertyfile}]]></db:parameterized-query>
 </db:select>

然后它生成以下异常:-

Then it generate the following exception :-

ERROR 2014-08-02 22:39:51,064 [pool-14-thread-1] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
java.lang.IllegalArgumentException: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
    at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.validateQueryType(AbstractDbMessageProcessor.java:164)
    at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:40)
    at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:164)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:148)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
    at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
    at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
    at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
    at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver.pollWith(MessageProcessorPollingMessageReceiver.java:147)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver.poll(MessageProcessorPollingMessageReceiver.java:138)
    at org.mule.transport.AbstractPollingMessageReceiver.performPoll(AbstractPollingMessageReceiver.java:216)
    at org.mule.transport.PollingReceiverWorker.poll(PollingReceiverWorker.java:80)
    at org.mule.transport.PollingReceiverWorker.run(PollingReceiverWorker.java:49)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
ERROR 2014-08-02 22:40:20,667 [pool-14-thread-1] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
java.lang.IllegalArgumentException: Query type must me '[SELECT, STORE_PROCEDURE_CALL]' but was 'DDL'
    at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.validateQueryType(AbstractDbMessageProcessor.java:164)
    at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:40)
    at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:164)
    at org.mule.transport.polling.MessageProcessorPollingMessageReceiver$1.process(MessageProcessorPollingMessageReceiver.java:148)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)

请帮助..从新的Mule 3.5数据库连接器中的属性文件读取SQL查询该怎么办..我已经在网上进行了所有搜索..但是找不到解决方法...

Please help .. what should I need to do to read SQL queries from properties file in the new Mule 3.5 Database connector .. I have searched all through the net .. but couldn't able to find solution ...

推荐答案

似乎出于任何原因,都可以在数据库查询中使用属性(感觉像是IMO的错误,我建议您将其报告给MuleSoft).

It seems like for any reason, properties can be used in DB queries (feels like a bug IMO, I suggest you report it to MuleSoft).

因此,另一种选择是使用查询创建流变量并使用它:

So another option would be to create a flow variable with the query in it and use it:

<flow name="the_flow">
  <poll>
     <fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
     <processor-chain>
       <set-variable variableName="selectQuery" value="${QueryFromPropertyfile}" />
       <db:select config-ref="Generic_Database_Configuration">
         <db:dynamic-query>#[flowVars.selectQuery]</db:dynamic-query>
       </db:select>
     </processor-chain>
  </poll>
  ..
</flow>

这篇关于如何从Mule 3.5数据库连接器中的属性文件读取SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆