Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-21112

camel-sql - Simple language to lookup parameter value is not compatible with batch mode

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.22.1, 4.7.0
    • 3.22.3, 4.4.4, 4.8.0
    • camel-sql
    • None
    • Unknown

    Description

      It seems there is an issue when using simple language to lookup parameters on producer endpoint in batch mode, like the following:

       

      to("sql:insert into Table1 ( col1) values ( :#${myBean.field1})?batch=true") 

       

      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:

      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,
      …
      

       

       

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              alexanderz Alexander Zobkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: