Announcement Announcement Module
Collapse
No announcement yet.
Can I create a dynamic query for Spring Integration JDBC outbound-channel-adapter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I create a dynamic query for Spring Integration JDBC outbound-channel-adapter?

    I need to create a dynamic update statement to be be executed by a jdbc:outbound-channel-adapter, because I need to set one field using a case expression that has variable number of conditions as follows:

    Code:
    UPDATE tableA
    SET    fieldA = CASE
                       WHEN fieldB IN ('a','b') THEN 1
                       WHEN fieldB IN ('c','d') THEN 2
                       ...
                       WHEN fieldB IN (...) THEN N
                    END
    WHERE  fieldC = :headers[MY_FIELDC]
    I can create this dynamic update statement in a Spring expression as follows:

    Code:
    "'UPDATE tableA SET fieldA = ' + headers[MY_CASE_EXP] + ' WHERE fieldC = :headers[MY_FIELDC]'"
    But the query attribute does not seem to support Spring expressions.

    How can I generate a dynamic query for use by the jdbc:outbound-channel-adapter?

  • #2
    Hi!
    Well, I suggest to use jdbcTemplate directly:
    HTML Code:
    <outbound-channel-adapter channel="fooChannel"
    expression="@jdbcTemplate.update('UPDATE tableA SET fieldA = ' + headers['MY_CASE_EXP'] + ' WHERE fieldC = ?', headers['MY_FIELDC'])"/>
    I'm not sure, that we should add "query-expression" to the Framework: it will break a loosely-coupled principle of the Messaging.
    And in this case we fully tie messages to the JDBC.

    Take care,
    Artem

    Comment


    • #3
      Hi Artem,

      Thanks for the helpful response. Using the jdbcTemplate approach, how does the dataSource get specified?

      I agree about wanting to maintain loose coupling, but it does seem like there would be times when an ability to dynamically construct the Query would be useful.

      Regards,
      Dave

      Comment


      • #4
        how does the dataSource get specified?
        It's just a custrcuctor argument of the JdbcTemplate. Declare it as a bean and voila.
        an ability to dynamically construct the Query would be useful.
        IMO SpEL may produce some side effects to the SQL and vise versa.

        Comment

        Working...
        X