Monday, July 6, 2015

Use DBReport Mediator in WSO2 ESB

DBReport mediator is same as DBLookup mediator with having small difference, dbreport mediator can write something into the database. You can use insert or update query in dbreport mediator.

UI Configuration:

This is the UI screen of the DB Report Mediator where you can put some required value and use it. You can even write this code to synapse itself.
In UI you have to pass database details to make connection like Driver call, URL, user name and the database password. You can use internal connection or external connection in that. If you have created a datasourse that can be used into that.

In above screen you need to choose the Connection info, Datasource type etc.

In the above screen you need to pass sql statement which you need to pass to insert information in database or update the database and the same way you have to pass required parameter and its type.

Synapse Code:

                        <property name="autocommit" value="false"/>
                <sql><![CDATA[INSERT INTO EMP_DETAILS (EMP_ID, EMP_NAME, EMP_ADDRESS, EMP_DOB) VALUES (?, ?, ?, ?)]]></sql>
                <parameter expression="synapse:get-property('empID')" type="VARCHAR"/>
                <parameter expression="synapse:get-property('empName')" type="VARCHAR"/>
                <parameter expression="synapse:get-property('empAddress')" type="VARCHAR"/>
                <parameter expression="synapse:get-property('empDOB')" type="VARCHAR"/>    

In above example I have used Oracle database so given driver and other required details of the oracle database, this is used to insert the employee detail into EMP_DETAILS table.