[
https://issues.apache.org/jira/browse/CAMEL-21112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17876812#comment-17876812
]
Alexander Zobkov commented on CAMEL-21112:
------------------------------------------
Thank you for the fix! Would you please backport the fix to Camel 3.22.x line?
As of now, it would be problematic for us migrate to Camel 4.x line but willing
eagerly to get rid of applied workaround for the issue.
> camel-sql - Simple language to lookup parameter value is not compatible with
> batch mode
> ----------------------------------------------------------------------------------------
>
> Key: CAMEL-21112
> URL: https://issues.apache.org/jira/browse/CAMEL-21112
> Project: Camel
> Issue Type: Bug
> Components: camel-sql
> Affects Versions: 3.22.1, 4.7.0
> Reporter: Alexander Zobkov
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.4.4, 4.8.0
>
>
> It seems there is an issue when using simple language to lookup parameters on
> producer endpoint in batch mode, like the following:
>
> {code:java}
> to("sql:insert into Table1 ( col1) values ( :#${myBean.field1})?batch=true")
> {code}
>
> DefaultSqlPrepareStatementStrategy and particular method lookupParameter(…)
> in class PopulateIterator tries to evaluate the specified simple expression
> on a body of the exchange. However when body is iterator that contains the
> parameter iterators for batch mode (as told in the doc:
> [https://camel.apache.org/components/4.4.x/sql-component.html#_treatment_of_the_message_body])
> then simple language expression written for an object to be returned by the
> parameter iterator makes no sense and will always fail.
> It seems when batch mode is enabled than
> DefaultSqlPrepareStatementStrategy.PopulateIterator needs to create a kind of
> fake Exchange from an object to be returned by the parameter iterator and
> pass to the simple language engine.
> Vanilla code
> https://github.com/apache/camel/blob/0e6dd1ea1ddb566fc4ee4eb4757d4a3c703ca06f/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java#L262
> Suggested code change:
> {code:java}
> org.apache.camel.component.sql.DefaultSqlPrepareStatementStrategy.PopulateIterato
> r
> import org.apache.camel.builder.ExchangeBuilder
> protected static Object lookupParameter(String nextParam, Exchange
> exchange, Object body) {
> …
> Exchange fakeExchange =
> ExchangeBuilder.anExchange(camelContext).withBody(body).build();
> answer =
> exchange.getContext().resolveLanguage("simple").createExpression(nextParam).evaluate(fakeExchange,
> …
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)