【发布时间】:2016-02-26 16:34:03
【问题描述】:
我试图将调用变量传递给动态 jdbc-ee 查询但没有成功。如果我在查询中用硬编码整数(即:1)替换变量 salesforcecontactcount,它工作正常。调试时,如果我在查询上放置断点,则表明变量正在正确填充。我没有收到任何错误,查询只是没有运行。关于我做错了什么有什么建议吗?
我检查了数据库日志,当我对 payloadsize 的值进行硬编码时,查询会被执行,但是当我使用 #[variable:salesforcecontactcount] 时,尽管驱动程序确实连接了,但查询不会传递到服务器,它只是不发送任何东西。
查看调试输出时,我在使用变量时看到以下内容:
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Preparing batch for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Executing batch for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);
DEBUG 2013-10-22 00:44:58,048 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Command executed successfully: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', ?);
当我对值进行硬编码时,调试输出为:
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Filling input parameters for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: SQL: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9); input params: []
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Registering output parameters for: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,186 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Executing update: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
DEBUG 2013-10-22 00:48:16,188 [[salesforce_integration].dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.PreparedSqlCommandExecutor: Command executed successfully: INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', 9);
以下是相关代码:
<message-properties-transformer scope="invocation" doc:name="Store Retrieved Objects">
<add-message-property key="salesforcecontactcount" value="#[payload.size()]"/>
</message-properties-transformer>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="logRequestHistory" queryTimeout="-1" connector-ref="aclu_ads_db" doc:name="Log the Request">
<jdbc-ee:query key="logRequestHistory" value="INSERT INTO internal_request_history (executedon, source, type, payload, payloadsize) VALUES (now(), 'salesforce', 'contact', '', #[variable:salesforcecontactcount]); "/>
</jdbc-ee:outbound-endpoint>
<logger message="count: #[salesforcecontactcount]" level="INFO" doc:name="LoggerMessage"></logger>
编辑:好的,我想我离答案越来越近了,如果我将查询更改为 SELECT 而不是 INSERT,它可以很好地与传入的参数一起工作:
<jdbc-ee:query key="logRequestHistory" value="SELECT * FROM internal_request_history WHERE payloadsize = #[variable:salesforcecontactcount];"/>
附加编辑:如果我执行存储过程,我会得到与插入相同的“非结果”和相同的调试模式:
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="logRequestHistory" queryTimeout="-1" connector-ref="aclu_ads_db" doc:name="Log the Request">
<jdbc-ee:query key="logRequestHistory" value="CALL create_log('salesforce', 'contact', #[variable:salesforcecontactcount]);" />
</jdbc-ee:outbound-endpoint>
DEBUG 2013-10-22 06:55:00,576 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Preparing batch for: { CALL create_log('salesforce', 'contact', ?); }
DEBUG 2013-10-22 06:55:00,576 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Executing batch for: { CALL create_log('salesforce', 'contact', ?); }
DEBUG 2013-10-22 06:55:00,577 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Command executed successfully: { CALL create_log('salesforce', 'contact', ?); }
DEBUG 2013-10-22 06:55:00,577 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sqlstrategy.BatchUpdateSqlStatementStrategy: Batch duration: 0.006
如果我对数据库的调用进行硬编码,这就是我在调试时得到的:
DEBUG 2013-10-22 07:10:47,067 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Filling input parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: SQL: { CALL create_log('salesforce', 'contact', 5) } input params: []
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Registering output parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,068 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Executing: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Command executed successfully: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processing resultSets for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,069 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processed resultsets: 0
DEBUG 2013-10-22 07:10:47,070 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sql.command.executor.CallableSqlCommandExecutor: Processing output parameters for: { CALL create_log('salesforce', 'contact', 5) }
DEBUG 2013-10-22 07:10:47,070 [[salesforce_integration].aclu_ads_db.dispatcher.01] com.mulesoft.mule.transport.jdbc.sqlstrategy.ExecuteSqlStatementStrategy: Obtained result: {}
我认为问题归结为所调用的策略。如何阻止查询使用 BatchUpdateSqlStatementStrategy?
【问题讨论】:
-
如果插入失败应该是jdbc异常。你没找到吗?
-
不,没有抛出 jdbc 异常。这就是如此令人困惑的地方。问题是插入永远不会发送到服务器,即使调试语句说它确实如此。
-
我认为问题可能归结为正在使用的策略 ExecuteSqlStatementStrategy 与 BatchUpdateSqlStatementStrategy。
-
好的,我想出了一个解决方法。正在调用 BatchUpdateSqlStatementStrategy,因为有效负载是一个数组。如果这是有效负载,它将自动被调用,但它希望数据作为列表传递。现在,我将有效负载重置为空字符串,并将稍后需要的数据存储到变量中。对我来说,这确实看起来很骇人听闻 - 我会暂时保留答案,并奖励任何可以告诉我如何强制正确更新策略以便它使用 BatchUpdateSqlStatementStrategy 以外的东西的人。