#
#
# JDBC Distributive example
#
#

# $Id: README.txt,v 1.2 2005/04/18 16:50:56 rogerperey Exp $ 

Scenario:
---------

The JDBC Distributive example is a simple example showing how
to use JTA transactions with two JDBC databases.

Setup:
------

o A RMI registry
o JOTM is the Transaction Manager
o A database:
        - Oracle
	- MySQL
	- PostgreSQL

o DistDatabaseHelper setups the JDBC objects (i.e., the JDBC Connections) with Enhydra
  wrappers and associates them to JOTM as their transaction manager.

o JdbcDistExample then will ask the DistDatabaseHelper for two connections, update a table
  in two different databases within a transaction and complete this transaction thanks to
  arguments given by the user.

Database Setup:
---------------

The example expects:
o a database named javatest for each host name
  If using localhost, define two databases named
  javatest1 and javatest2
  Change the SQL commands in the java code to reference
  the javatest1 and javatest2 databases
o a user of login "mojo" and password "jojo"
o a *transactional* table named testdata which is like 

+----+-------+
| ID | FOO   |
+----+-------+
|  1 | 1     |
+----+-------+
	
	o id being an int (primary key)
	o foo being an int
	
For example on MySQL:

$$$    Note: Use below for javatest1 and repeat for javatest2   $$$

mysql> GRANT ALL PRIVILEGES ON *.* TO [userid]
    ->   IDENTIFIED BY '[password]' WITH GRANT OPTION;
mysql> create database javatest1;
mysql> use javatest1;
mysql> create table testdata (
    ->   id int not null auto_increment primary key,
    ->   foo int)type=InnoDB;
mysql> insert into testdata values(null, 1);

Database configuration are stored in properties file (mysql1.propertiesand mysql2.properties,
postgresql1.properties and postgress2.properties, and oracle1.properties and oracle2.properties)
which contains the following properties:
o driver - Name of the JDBC driver
o url - URL to connect to the data base
o login - user login
o password - user password 

Compilation:
------------

Set JOTM_HOME to the examples/jdbc-dist directory of your JOTM distribution (e.g.,
.../jotm/output/examples/jdbc-dist (JOTM_HOME/examples/jdbc-dist) from CVS)

Type

    ant compile

to compile the example
------------------------------------------------------------------------------------

To run the example:
----------------

o To run the example, first check that only RMI protocol will be
activated (in the (JOTM_HOME/conf/carol.properties , carol.rmi.activated
should be set to jrmp); then type in $JOTM_HOME/lib/ directory

UNIX:
   $ rmiregistry -J-classpath -Jjotm.jar:jotm_jrmp_stubs.jar -J-Djava.security.policy=../config/java.policy &

WINDOWS:
     rmiregistry -J-classpath -Jjotm.jar;jotm_jrmp_stubs.jar;commons-cli-1.0.jar;connector-1_5.jar;howl.jar;mysql-connector-java-3.1.6-bin.jar -J-Djava.security.policy=../conf/java.policy

to start a RMI registry on default port (i.e. 1099).
---------------------------------------------------------------------------------------

o Setting the classpath

UNIX:

   $ export CLASSPATH=../../lib/jotm.jar:../../lib/jotm_jrmp_stubs.jar:../../lib/xapool.jar:../../conf:../../lib/connector-1_5.jar:../../lib/howl.jar:../../lib/commons-cli-1.0.jar:../../lib/mysql-connector-java-3.1.7-bin.jar:.:../../conf/

WINDOWS:
   
     set CLASSPATH=%CLASSPATH%;../../lib/jotm.jar;../../lib/jotm_jrmp_stubs.jar;../../lib/xapool.jar;../../lib/mysql-connector-java-3.1.7-bin.jar;../../lib/jdbc.jar;../../lib/connector-1_5.jar;../../lib/howl.jar;../../lib/commons-cli-1.0.jar;./;../../conf/
-------------------------------------------------------------------------------------------

    o change mysql1.properties and mysql2.properties password/user to database user/password 
    o change mysql1.properties and mysql2.properties to reflect javatest1 and javatest2
--------------------------------------------------------------------------------------------

o Start the example

UNIX:
   $ jave JdbcDistExample oracle1 oracle2 commit 4 // set table value to 4 and commit the transaction on Oracle &
   $ java JdbcDistExample postgresql1 postgres2 commit 2 // set table value to 2 and commit the transaction on PostgreSQL &
   $ java JdbcDistExample mysql1 mysql2 rollback 0 // set table value to 0 but rollback the transaction on MySQL &
   $ java JdbcDistExample mysql1 mysql2 commit 2 &
   $ java JdbcDistExample ...   

WINDOWS:
   jave JdbcDistExample oracle1 oracle2 commit 4 // set table value to 4 and commit the transaction on Oracle
   java JdbcDistExample postgresql1 postgres2 commit 2 // set table value to 2 and commit the transaction on PostgreSQL
   java JdbcDistExample mysql1 mysql2 rollback 0 // set table value to 0 but rollback the transaction on MySQL
   java JdbcDistExample mysql1 mysql2 commit 0
   java JdbcDistExample ...

o Of course you can mix databases

UNIX:
   $ java JdbcDistExample oracle1 mysql1 rollback 0 & // set table value to 0 but rollback the transaction on MySQL

WINDOWS:
     java JdbcDistExample oracle1 mysql1 rollback 0

Usage:
------

UNIX:
   $ java JdbcExample [database1] [database2] [completion] [number] &

WINDOWS:
     java JdbcExample [database1] [database2] [completion] [number]

where
o database can be:
        - oracle
	- postgresql 
	- mysql (example will look for a configuration file name [database].properties)
o completion can be:
	- commit
	- rollback
o number has to be a integer
		
Enjoy!



