<?xml version="1.0"?>
<!--
  JBoss, Home of Professional Open Source
  Copyright 2006, Red Hat Middleware LLC, and individual contributors
  as indicated by the @author tags.
  See the copyright.txt in the distribution for a full listing
  of individual contributors.
  This copyrighted material is made available to anyone wishing to use,
  modify, copy, or redistribute it subject to the terms and conditions
  of the GNU Lesser General Public License, v. 2.1.
  This program is distributed in the hope that it will be useful, but WITHOUT A
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License,
  v.2.1 along with this distribution; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA  02110-1301, USA.


  (C) 2005-2006,
  @author JBoss Inc.
-->
<page title="JBossTS Trail map: Running and Testing Examples" rootpath="../..">
	<header>         Trail map: Running and Testing Examples     </header>
	<content>
		<navigation>
			<links include="includes/www_arjuna_com_navigation.xml"/>
			<links include="includes/trailmap_navigation.xml"/>
			<links title="Navigation">
				<link ref="index.html">Home</link>
				<link ref="part5.html">Previous</link>
			</links>
			<links include="includes/trailmap_additional.xml"/>
		</navigation>
		<area title="Running The Banking application with JTA">
			<html>
			<h4>Configuring JBossTS</h4>
			<p>Program Applications that create transactions using te JTA interface may invoke as well local services as remote
services. When a remote invocation need to be performed, the current transactional context need to be propagated
to the remote service in order to involve it to the transaction in progress. JBoss Transaction Service allows the
possibility to provide such feature using the facilities provided by JTS and ORB. More precisely JBossTS need to be configured
to determine in which type of transaction, local or distributed, the JTA interface is used.
</p>

<h4>Executing the JTA sample</h4>
The Banking sample using JTA creates local transactions, ensure that JTA is configured for local transactions as explained above.
<p>To launch the <a class="linkscoloured" href="part5_jta.html">JTA version of the Banking application</a>,
  which creates only local transactions, execute the following java program: </p>
<blockquote>
<pre>
java com.arjuna.demo.jta.localbank.BankClient
</pre>
</blockquote>
<p>Once one of the program given above is launched the following lines are displayed:</p>
<blockquote>
<pre>
-------------------------------------------------
  Bank client
-------------------------------------------------
Select an option :
   0. Quit
   1. Create a new account.
   2. Get an account information.
   3. Make a transfer.
   4. Credit an account.
   5. Withdraw from an account

Your choice :
</pre>
</blockquote>
<p>After introducing your choice, the appropriate operation is performed by the
  Bank object, to get the requested account, and by the account to execute the
  credit or withdraw or to return the current balance. Let's consider the following
  execution. </p>
<p>Enter the number 1 as your choice, then give the name &quot;Foo&quot; as the
  account name and &quot;1000&quot; as an initial value of the account to create.
  You should get the following lines:</p>
<blockquote>
<pre>Your choice : 1
- Create a new account -
------------------------
Name : Foo
Initial balance : 1000
Beginning a User transaction to create account
XA_START[]
Attempt to commit the account creation transaction
XA_END[]
XA_COMMIT (ONE_PHASE)[]
</pre>
</blockquote>
				<ul>
					<li>The line XA_START indicates that the AccountResource object that implements
    the XAResource interface and enlisted to participate in the account creation
    transaction, receives the indication from the Transaction Manager that the
    transaction has started.</li>
					<li>The line XA_END indicates that the calling thread in which the AccountRessource
    object is associated shall be ended to enable the transaction completion as
    recommended by the X/Open specification.</li>
					<li>Since only one AccountResource then only one XAResource is involved in the
    account creation transaction, the two phases needed to get a consensus in
    the 2PC protocol are not mandatory. The one phase commit optimization, indicated
    by the &quot;XA_COMMIT (ONE_PHASE)&quot;, is applied. </li>
				</ul>
				<p>In the same way create a second account with the name &quot;Bar&quot; and the
  initial balance set to 500. </p>
				<p>As a choice now, enter &quot;3&quot; to make a transfer (300) from &quot;Foo&quot;
  to &quot;Bar&quot;. </p>
<blockquote>
<pre>Your choice : 3
- Make a transfer -
-------------------
Take money from : Foo
Put money to : Bar
Transfert amount : 300
Beginning a User transaction to get balance
XA_START[]
XA_START[]
XA_END[]
XA_PREPARE[]
XA_END[]
XA_PREPARE[]
XA_COMMIT[]
XA_COMMIT[]
</pre>
</blockquote>
				<ul>
					<li>Now two AccountResource objects, then two XAResource objects are enlisted
    with the transaction. The displayed lines show that the two phases, prepare
    and commit, are applied. </li>
				</ul>
				<p>Any attempt to manipulate an account that it doesn't exist leads to throw the
  NotExistingAccount exception and to rollback the transaction in progress. For
  instance, let's withdraw money from an account FooBar not previously created.</p>
<blockquote>
<pre>Your choice : 5
- Withdraw from an Account -
----------------------------
Give the Account name : FooBar
Amount to withdraw : 200
Beginning a User transaction to
withdraw from an account
The requested account does not exist!
ERROR - javax.transaction.RollbackException
</pre>
</blockquote>
			</html>
		</area>
	</content>
	<footer/>
</page>
