
 README file: How to store and run the ServerDemo SQLJ stored program
 ********************************************************************

Steps in Creating a SQLJ Stored Program
***************************************

The steps involved in creating a SQLJ stored program are as follows:

1) Translate SQLJ source
   
In Oracle 8i SQLJ programs can be translated on the client, or on
the server.  In either case, the translator produces .class files and also
serialized objects for SQLJ profiles (.ser files).

For client-side translation, the SQLJ translator automatically calls the Java
compiler for the generated .java files.  The generated byte code can be loaded
and stored in the Oracle 8i server, and executed as a stored program.

For server-side translation, the sqlj translation and java compilation step are
also integrated, and happens automatically for all sqlj source files loaded
into the server.

2) Upload byte or source code

A client-side utility called 'loadjava' can be conveniently used to upload both
Java byte code as well as Java/SQLJ source code.

Loading of class or source files can also be done through the CREATE OR REPLACE
command in SQL*Plus.  We do not use this method in this demo - refer to the SQL
and Java Stored Procedures documentation for details of this command.

3) Publish SQL wrappers for Java methods

To be able to call a Java/SQLJ stored program from SQL, PL/SQL spec-style
'wrappers' need to be 'published' for those Java methods that are meant to be
entry points from SQL.  These wrappers specify the correspondence between a
Java method and its SQL name, and also map its Java arguments to SQL types.

4) Run the SQLJ stored program

The 'published' methods in the Java/SQLJ program can be used in SQL statements,
just like any other stored procedure or function call.


The ServerDemo SQLJ Program 
***************************

It is a simple stored program along the lines of 'Hello, World!' that
illustrates the general steps and functionality. 

For this demo, we illustrate both client translation as well as server
translation of SQLJ files.  In both cases, we make use of the 'loadjava'
utility to upload Java byte code / SQLJ source code to the server.  After
publishing the SQL wrappers for the entry method 'main', we execute the stored
SQLJ program in SQL*Plus.  The expected output looks as follows:

Hello! I'm SQLJ in server!
Today is 1999-01-25
End of SQLJ demo.

The ServerDemo program lives in

       ${ORACLE_HOME}/sqlj/demo/server/ServerDemo.sqlj


How to load and run ServerDemo as a stored program
**************************************************

Environment Setup
*****************

To run ServerDemo, check that your environment has the following setup:

- sqlj, javac, jar, loadjava, and sqlplus are available in your PATH
- Your CLASSPATH includes: 
   - The SQLJ library from ${ORACLE_HOME}/sqlj/lib/classes.zip 
   - the loadjava utility from ${ORACLE_HOME}/lib/aurora_client.jar

The demo
********

There are several ways to load and run a SQLJ program in the server.  We
demonstrate 2 common methods in this demo.

Method 1: Client-side translation, and Java byte code upload via loadjava
********

Steps are (shell script available in ${ORACLE_HOME}/sqlj/demo/server/demo1.sh,
bat file in ${ORACLE_HOME}/sqlj/demo/server/demo1.bat):

# 1)  First, translate the sqlj file, compile, and customize it
sqlj ServerDemo.sqlj

# 2) jar the generated files into demo.jar
jar cvf0 demo.jar ServerDemo*.class ServerDemo*.ser

# 3) Clean up the database
sqlplus scott/tiger @Drop.sql

# 4) Load the jar into the server.
loadjava -resolve -force -thin -user scott/tiger@${HOST}:5521:${ORACLE_SID} demo.jar

# 5) Publish SQL wrappers and run the demo through SQL*Plus.
sqlplus scott/tiger @Run.sql



Method 2: Server-side translation through SQLJ source file upload via loadjava
********

Steps are (shell script available in ${ORACLE_HOME}/sqlj/demo/server/demo2.sh,
and bat file in ${ORACLE_HOME}/sqlj/demo/server/demo2.bat):

# 1) First, clean up the database
sqlplus scott/tiger @Drop.sql

# 2) Load the SQLJ source directly 
loadjava -resolve -force -thin -user scott/tiger@${HOST}:5521:${ORACLE_SID} \
ServerDemo.sqlj

# 2)  Publish SQL wrappers and run the demo through SQL*Plus.
sqlplus scott/tiger @Run.sql

