Alexander Zobkov created CAMEL-21112:
----------------------------------------

             Summary: 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: 4.7.0, 3.22.1
            Reporter: Alexander Zobkov


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)

Reply via email to