<?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 410</title>
    </properties>
    <body>
        <section name="Sample 410: Distributed Transactions Management with the Transaction Mediator">
            <div class="xmlConf"><![CDATA[<definitions xmlns="http://ws.apache.org/ns/synapse">

<sequence name="myFaultHandler">
    <log level="custom">
        <property name="text" value="** Rollback Transaction**"/>
    </log>
    <transaction action="rollback"/>
    <send/>
</sequence>

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

    <out>
        <transaction action="new"/>

        <log level="custom">
            <property name="text" value="** Reporting to the Database esbdb**"/>
        </log>
        <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse">
            <connection>
                <pool>
                    <dsName>java:jdbc/XADerbyDS</dsName>
                    <icClass>org.jnp.interfaces.NamingContextFactory</icClass>
                    <url>localhost:1099</url>
                    <user>synapse</user>
                    <password>synapse</password>
                </pool>
            </connection>
            <statement>
                <sql>delete from company where name =?</sql>
                <parameter expression="//m0:return/m0:symbol/child::text()"
                           xmlns:m0="http://services.samples"
                           type="VARCHAR"/>
            </statement>
        </dbreport>

        <log level="custom">
            <property name="text" value="** Reporting to the Database esbdb1**"/>
        </log>
        <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse">
            <connection>
                <pool>
                    <dsName>java:jdbc/XADerbyDS1</dsName>
                    <icClass>org.jnp.interfaces.NamingContextFactory</icClass>
                    <url>localhost:1099</url>
                    <user>synapse</user>
                    <password>synapse</password>
                </pool>
            </connection>
            <statement>
                <sql> INSERT into company values ('IBM','c4',12.0)</sql>
            </statement>
        </dbreport>
        <transaction action="commit"/>
        <send/>
    </out>
</sequence>
</definitions>]]></div>
            <subsection name="Objective">
                <p>
                    Demonstrate how to manage complex distributed transactions using the transaction
                    mediator
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            To run this sample it is required to deploy Synpase on JBoss application
                            server(This is only tested with JBoss application sever). You can use the
                            Synapse war distribution to deploy Synapse on JBoss. Use the synpase_sample_410.xml
                            as the synapse confiuration file and start JBoss. Also you need to define
                            two XA datasources for above the two datasources defined in Synapse. You'll
                            need to refer JBoss documentation to see how to do this.
                        </li>
                        <li>
                            Setup two Derby database instances as described in the database setup guide.
                            These databases will be used by the XA datasources in JBoss.
                        </li>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    In this sample a record is deleted from one database and it is added to the
                    second database. If either of the operations(deleting from the 1st database and
                    adding to the second database) fails the entire operation will be roll backed.
                    The records will be left intact.
                </p>
                <p>
                    Invoke the client as follows to try this out.
                </p>
                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</div>
                <p>
                    You can force an error by shutting down one of the two database instances.
                </p>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>
    </body>
</document>