<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 361</title>
    </properties>
    <body>
        <section name="Sample 361: Introduction to DBReport Mediator">
            <div class="xmlConf"><![CDATA[<definitions xmlns="http://ws.apache.org/ns/synapse">

    <sequence name="main">
        <in>
            <send>
                <endpoint>
                    <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
            </send>
        </in>

        <out>
            <log level="custom">
                <property name="text" value="** Reporting to the Database **"/>
            </log>
            <dbreport>
                <connection>
                    <pool>
                        <driver>org.apache.derby.jdbc.ClientDriver</driver>
                        <url>jdbc:derby://localhost:1527/synapsedb;create=false</url>
                        <user>synapse</user>
                        <password>synapse</password>
                    </pool>
                </connection>
                <statement>
                    <sql>update company set price=? where name =?</sql>
                    <parameter xmlns:m0="http://services.samples"
                               expression="//m0:return/m0:last/child::text()" type="DOUBLE"/>
                    <parameter xmlns:m0="http://services.samples"
                               expression="//m0:return/m0:symbol/child::text()" type="VARCHAR"/>
                </statement>
            </dbreport>
            <send/>
        </out>
    </sequence>

</definitions>]]></div>
            <subsection name="Objective">
                <p>
                    <a href="sample360.html">Sample 360</a> shows how to perform database lookups
                    in Synapse. This sample illustrates how to write to a given database from
                    Synapse using the dbreport mediator.
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Setup a Derby database as described in the <a href="setup/db.html">database setup guide</a>
                        </li>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 361 (repository/conf/sample/synapse_sample_361.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 361<br/>
                                Windows: synapse.bat -sample 361
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    This sample demonstrates how to perform simple database write operations in
                    Synapse. The dbreport mediator writes (i.e. inserts one row) to a table using the
                    details available in messages. 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. After running this sample, user can check the
                    company table using the Derby client tool. It will show the value inserted by the 
                    dbreport mediator.
                </p>
                <p>
                    To try this out run the sample client as follows.
                </p>
                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
                <p>
                    Now execute the following SQL query against the Derby database using the Derby
                    client tool.
                </p>
                <div class="command">select price from company where name='IBM';</div>
                <p>
                    This operation will return the stock quote value returned earlier by Axis2. You
                    can compare the output of the sample Axis2 client with the output of the Derby
                    client tool for confirmation.
                </p>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>