#
#
# JDBC example
#
#

# $Id$ 

Scenario:
---------

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

Setup:
------

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

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

o JdbcExample then will ask the DatabaseHelper for a connection, update a table within a transaction 
   and complete this transaction thanks to arguments given by the user.

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

The example expects:
o a database named javatest
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:
mysql> GRANT ALL PRIVILEGES ON *.* TO mojo
    ->   IDENTIFIED BY 'jojo' WITH GRANT OPTION;
mysql> create database javatest;
mysql> use javatest;
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 (mysql.properties 
and postgresql.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 directory of your JOTM distribution (e.g.,
.../jotm/output/dist from CVS)

In the  JOTM_HOME/examples/jdbc directory type:

     ant compile

to compile the JDBC example

Running the JDBC example:
----------------

   o To run the example, first check that only RMI JRMP protocol is activated in the JOTM_HOME/conf/carol.properties file, 
     (carol.protocols=jrmp)); 

In  JOTM_HOME/lib/ directory type:

UNIX:
   $ 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.7-bin.jar -J-Djava.security.policy=../conf/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.7-bin.jar -J-Djava.security.policy=../conf/java.policy 

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

o Set the classpath

In the JOTM_HOME/examples/jdbc directory:

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\connector-1_5.jar;..\..\lib\howl.jar;..\..\lib\commons-cli-1.0.jar;.;..\..\conf\
 
   
where  JDBC_JARS is the location of the JDBC driver jar file(s) you want to use.

NOTE:
When a new/updated JDBC driver is downloaded:
 
   o  the driver must be copied into the $JOTM_HOME/lib directory

   o    the mysql-connector-java-[version]-bin.jar file is copied to the $JAVA_HOME/jre/lib/ext directory

Set WD to examples/jdbc:

NOTE--- I had to make the below changes---

Change mysql.properties:
user = user name
password = password

----------------------------------
o Start the example
     java JdbcExample postgresql commit 2 // set table value to 2 and commit the transaction on PostgreSQL
     java JdbcExample mysql commit 2 // set table value to 0 but rollback the transaction on MySQL
     java JdbcExample ...   

Usage:
------

     java JdbcExample [database] [completion] [number]

where
o database can be:
	- 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!



