Swordfish
Swordfish

Reputation: 1281

Spring Integration JDBC Outbound Channel Adapter using DSL

Is there a way to specify a JDBC Outbound Channel Adapter using DSL?

e.g.

<int-jdbc:outbound-channel-adapter
            query="insert into foos (id, status, name) values (:headers[id], 0, :payload[foo])"
            data-source="dataSource"
            channel="input"/>

Also is it possible to handle parameters which may be null (e.g. if a field is null, substitute an empty string value).

Upvotes: 3

Views: 2429

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121590

According <int-jdbc:outbound-channel-adapter> description:

 <xsd:documentation>
            Configures a Consumer Endpoint for the
            'org.springframework.integration.jdbc.JdbcMessageHandler' for updating a
            database.
        </xsd:documentation>

we have JdbcMessageHandler which can be used as:

@Bean
public MessageHandler jdbcMessageHandler() {
    JdbcMessageHandler handler = new JdbcMessageHandler(this.dataSource,
       "insert into foos (id, status, name) values (:headers[id], 0, :payload[foo])");
    return handler;
}

@Bean
public IntegrationFlow jdbcFlow() {
      ...
      .handle(jdbcMessageHandler())
      ...
}

The null -> empty string is possible via custom SqlParameterSourceFactory.

Upvotes: 4

Related Questions