Using StatementType for better control of MyBatis - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

When routing to an MyBatis endpoint you will want more fine grained control so you can control whether the SQL statement to be executed is a SELECT, UPDATE, DELETE or INSERT etc. So for instance if we want to route to an MyBatis endpoint in which the IN body contains parameters to a SELECT statement we can do:


In the code above we invoke the MyBatis statement selectAccountById and the IN body should contain the account id we want to retrieve, such as an Integer type.

We can do the same for some of the other operations, such as SelectList :


And the same for UPDATE, where we can send an Account object as the IN body to MyBatis:


Using onConsume

This component supports executing statements after data have been consumed and processed by Camel. This allows you to do post updates in the database. Notice all statements must be UPDATE statements. Camel supports executing multiple statements whose names should be separated by commas.

The route below illustrates executing the consumeAccount statement after the data is processed. This allows us to change the status of the row in the database to "processed", so we avoid consuming it twice or more.


And the statements in the sqlmap file:

<select id="selectUnprocessedAccounts" resultMap="AccountResult">
   select * from ACCOUNT where PROCESSED = false
<update id="consumeAccount" parameterClass="Account">
   update ACCOUNT set PROCESSED = true where ACC_ID = #id#