Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The DBReport Mediator is very similar to the DBLookup Mediator, but writes information to a Database, using the specified insert SQL statement.

...

Table of Contents
maxLevel3
minLevel3
locationtop
styleborder:1
typeflat
separatorpipe

...

Syntax

Code Block
XML
XML

<dbreport>
   <connection>
     <pool>
      (
        <driver/>
        <url/>
        <user/>
        <password/>

        <dsName/>
        <icClass/>
        <url/>
        <user/>
        <password/>
      )
        <property name="name" value="value"/>*
     </pool>
   </connection>
   <statement>
      <sql>insert into something values(?, ?, ?, ?)</sql>
      <parameter [value="" | expression=""] type="CHAR|VARCHAR|LONGVARCHAR|NUMERIC|DECIMAL|BIT|TINYINT|SMALLINT|INTEGER|BIGINT|REAL|FLOAT|DOUBLE|DATE|TIME|TIMESTAMP"/>*
   </statement>+
</dblreport>dbreport>

...

UI Configuration

Connection Information of the DBReport Mediator can be chosen as:

...

  • Use Transaction - (Yes/No)
  • Connection Information - Specifies whether the connection is taken from a connection pool or from a data source.
  • Database Type:
    • External
    • Carbon Datasource
  • Data Source Name

    Info
    titleTip

    You can view the available data sources by clicking the "Load Data Sources" icon.

...

  • SQL- One or more SQL Statements.
  • Parameters- Specify how the values of parameters in the SQL will be calculated. A value can be a static literal text and can be calculated at runtime based on the given expression.
    • Parameter Type
      • CHAR
      • VARCHAR
      • NUMERIC
      • DECIMAL
      • BIT
      • TINYINT
      • SAMLLINT
      • INTEGER
      • BIGINT
      • REAL
      • DOUBLE
      • DATE
      • TIME
      • TIMESTAMP
    • Property Type
      • Value
      • Expression
    • Value/Expression
    • Namespace - Gives possibility to choose an Expression from the list.
Info
titleTip

You can click this link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have used in the XPath expression. 

    • Action - Delete the parameter.
  • Results - Specify how to deal with rerun result from Database query execution.
  • Result Name
  • Column
  • Action - Deletes the result.
Info
titleNote

You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.

Image Modified

 

...

Example

Code Block
XML
XML

<dbreport xmlns="http://ws.apache.org/ns/synapse">
    <connection>
        <pool>
            <driver>org.apache.derby.jdbc.ClientDriver</driver>
            <url>jdbc:derby://localhost:1527/esbdb;create=false</url>
            <user>esb</user>
            <password>esb</password>
        </pool>
    </connection>
    <statement>
        <sql>update company set price=? where name =?</sql>
        <parameter expression="//m0:return/m1:last/child::text()"
                   xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="DOUBLE"/>
        <parameter expression="//m0:return/m1:symbol/child::text()"
                   xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="VARCHAR"/>
    </statement>
</dbreport>

This example demonstrates simple database write operations. The DBReport Mediator writes to a table using the message's details. It works the same way as the DBLookup Mediator. In this sample DBReport Mediator is used for updating the stock price of the company using the last quote value which is calculated by evaluating an XPath against the response message.

Excerpt
hiddentrue

Description of the DBReport Mediator in WSO2 ESB.