# @@@ START COPYRIGHT @@@
#
# 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.
#
# @@@ END COPYRIGHT @@@

Following are the sample Java programs that illustrate the features
of Type2 Driver

	T2Sample.java
	HoldCustorSample.java
	MultiThreadTest.java
	CreateDataSource.java
	TestDataSource.java
	JdbcRowSetSample.java
	TestConnectionPool.java
	LobSample.java
	ISO88591Sample.java
	TransactionMode.java

T2Sample.java
-----------------
This program illustrates the concept of loading the JDBC Type2 driver and
obtaining a JDBC connection using DriverManager.

To compile this java program, issue the following command:

   javac T2Sample.java

Then, run this Java program using the following command:

   Set your CLASSPATH and LD_PRELOAD path
        export CLASSPATH=$TRAF_HOME/export/lib/jdbcT2.jar:.:$CLASSPATH
        export LD_PRELOAD=$JAVA_HOME/jre/lib/amd64/libjsig.so:$TRAF_HOME/export/lib64d/libseabasesig.so

   java -Dt2jdbc.schema=<defaultCatalog>.<defaultSchema> T2Sample

where <defaultCatalog> and <defaultSchema> are the user's default
catalog and schema, respectively.  The "-Dt2jdbc.schema" command line
option can be removed if the default catalog and schema are the desired
catalog and schema to be used.

CreateDataSource.java and TestDataSource.java
---------------------------------------------
These programs illustrate the concept of making a connection using
DataSource and thereby avoiding embedding driver specific codes
in the java programs.

CreateDataSource.java creates the SQLMXDataSource object and registers
it with Java Naming and Directory Interface (JNDI).  An additional package
is required in order to run the CreateDataSource sample. The File
System Service Provider package for accessing the file system can be
downloaded from the Oracle web site.

     1. Go to http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html

     2. Scroll down to the "Download JNDI 1.2.1" section and
        select "Download".

     3. Accept the license agreement and select "File System Service
        Provider 1.2 BETA 3". Then download the fscontext-1_2-beta3.zip
        zip file.

     4. Unzip the fscontext-1_2-beta3.zip file. Under the lib directory, which
        was created by the unzip, are two jar files that you need to transfer
        to the system. These files are fscontext.jar and
        providerutil.jar.

     5. Put these files in the directory from which you run the demo and
        add these to your CLASSPATH environment variable.

Create a directory dataSources/jdbc in any directory before running this
program.  The recommended location is your current working directory.

To compile these programs, issue the following command:

   javac CreateDataSource.java
   javac TestDataSource.java

Then, run this Java program using the following command, assuming that
fscontext.jar and providerutil.jar have been added to CLASSPATH:

   mkdir -p dataSources/jdbc
   java CreateDataSource `pwd`
   java TestDataSource `pwd`

If the directory dataSources/jdbc is not in the current working directory,
substitute the correct path name for the `pwd`.


MultiThreadTest.java
--------------------
This program demonstrates the non-blocking JDBC Type2 feature. By default, this
program creates two threads. These threads run concurrently while the JDBC Type2
driver is configured to run in non-blocking mode. This program displays the
thread id and status of SQL operation before and after each operation.
In blocking mode, you will observe only one thread switch due to non-blocking
BEGINTRANSACTION. In non-blocking mode you will observe many thread switches.

To compile this java program, issue the following command:

   javac MultiThreadTest.java

Then, run this Java program using the following command:

For non-blocking mode (default is non-blocking):
   java MultiThreadTest

For blocking mode :
   java -Dsql_nowait=off MultiThreadTest


HoldCustorSample.java
---------------------
This program illustrates the holdable cursor support in JDBC Type2 driver.
It creates a subscriber thread that subscribes to a message queue. When all
the rows in the message queue are read, the subscriber times out after 5
seconds.

To compile this java program, issue the following command:

   javac HoldCursorSample.java

Then, run this Java program using the following command:

   java HoldCursorSample


TestConnectionPool.java
-----------------------
This program demonstrates the benefits of connection and statement pooling.
You need to run CreateDataSource.java to create the 'DataSource' object before
running this program. See above for instructions to run CreateDataSource.java.

This program makes a JDBC connection and executes a few SQL statements and
closes the connection in a loop for 100 times.  Use the 'time' command to
measure the performance benefits of connection and statement pooling in this
program.

To compile this program, issue the following command:

   javac TestConnectionPool.java

Then run this Java program using the following command, assuming that
fscontext.jar and providerutil.jar have been added to CLASSPATH (refer to
the CreateDataSource.java and TestDataSource.java demo information):

   time java TestConnectionPool <DataSourceDir> <TestType>

Use the same value for <DataSourceDir> that was previously used when the
CreateDataSource.java demo was executed.

Here <TestType> can be
  0 : Using DataSource - Connection and Statement pooling enabled
  1 : Using DataSource - Connection enabled, but Statement pooling disabled
  2 : Using DataSource - Both Connection and Statement pooling disabled

You will observe improvements in elapsed time and cpu time when the connection
and statement pooling is enabled.


JdbcRowSetSample.java
-----------------------
This program demonstrates the use of the SQLJdbcRowSet implementation.

To compile this java program, issue the following command:

   javac JdbcRowSetSample.java

Then, run this Java program using the following command:

   java JdbcRowSetSample


LobSample.java <not currently supported>
--------------
This program demonstrates LOB functionality via the JDBC Type2 driver. The
program creates the LOB base and data tables, inserts BLOB/CLOB data via
the PreparedStatement interface, inserts an empty BLOB/CLOB row, then
updates the empty BLOB/CLOB row with data using the blob and clob API
interfaces.

To compile this java program, issue the following command:

   javac LobSample.java

Then, run this Java program using the following command:

   java -Dt2jdbc.catalog=<catalog> -Dt2jdbc.schema=<schema> LobSample

where <catalog> and <schema> are the user's default Trafodion catalog and schema.


ISO88591Sample.java
-------------------
This program demonstrates the use of the ISO88591 property.

To compile this java program, issue the following command:

   javac -encoding Shift_JIS ISO88591Sample.java

Then, run this Java program using the following command:

   java -Dt2jdbc.ISO88591=SJIS ISO88591Sample


TransactionMode.java
--------------------
The TransactionMode.java program demonstrates the use of the transactionMode
property within the JDBC driver. The transactionMode property can be one of
three configurable values: 'internal', 'mixed', or 'external'.  Refer to the
JDBC Type2 documentation for the specific details and behavior for each
transactionMode.

You need to run CreateDataSource.java to create the 'DataSource' object before
running this program. See above for instructions to run CreateDataSource.java.

To compile this java program, issue the following command:

   javac TransactionMode.java

Then, run this Java program using the following command:

   java TransactionMode <DataSourceDir> <TestType>

Use the same value for <DataSourceDir> that was previously used when the
CreateDataSource.java demo was executed.

Here <TestType> can be:
  1 : Using DataSource - TransactionMode = 'internal'
  2 : Using DataSource - TransactionMode = 'mixed'
  3 : Using DataSource - TransactionMode = 'external'

Note: The above java command assumes the path to the fscontext.jar,
providerutil.jar, and current directory (i.e., ".") are defined within
the CLASSPATH environment variable. Alternatively, the java "-cp" option
can be specified as shown in the following example:

java -cp $CLASSPATH:.:./fscontext.jar:./providerutil.jar TransactionMode `pwd` 3

Note: This assumes the specified jar files and the dataSources/jdbc directory
reside in the current demo directory.
