1.6 The sqlj Command-Line Utility
Now that you've seen how to translate and run the HelloWorld.sqlj program, I will go into the details of what the sqlj command-line utility does behind the scenes. The sqlj command-line utility parses the parameters that you pass to it, and then runs a Java Virtual Machine (JVM) to handle the translation of your SQLJ file to a Java file and the subsequent compilation of that Java file to a class file. The sqlj command-line utility has many options, which are documented in Appendix B.
The first thing the JVM does when you invoke sqlj is run the translator. The translator performs the following two checks on the SQLJ statements contained in the source file:
-
Syntax checking
-
Semantic checking
The syntax check examines the SQLJ statements to verify that they are formatted in accordance with the SQLJ standard. The semantic check examines the database tables and columns referenced in the statements to verify that they actually exist in the database. The semantic check is performed only if you use the -user command-line option of sqlj; see Appendix B for details.
Assuming that the source file passes the two checks, the translator then converts the embedded SQLJ statements into SQLJ runtime library method calls. The runtime methods then use JDBC to perform the actual database operations. A profile is also generated for each database connection made by the program; a profile is a small binary file that contains information, such as the tables referenced, for each SQL operation contained in the program. When the program is run, the information contained in the profile files is used in calls to the JDBC driver. Profile files have the extension .ser. In addition, a profile keys class file is also produced; this contains information that allows the profile files to be read by the JDBC driver at runtime. Profile keys files have the extension .class. You don't need to worry about the profile and profile keys files you don't have to code anything to use them but don't delete them either!
| In SQLJ 9i, you can use the -codegen=oracle option with the sqlj command-line utility to skip generation of the profile files. |
|
The end result of the translation process is a Java source file. By default, the name of the Java source file is the name of the SQLJ source file but with the .java extension. The JVM then uses the Java compiler to compile the Java source file into a class file (with the extension .class), which you may then run. When the class file is run, the information contained in the profile files is used during execution of the database operations.
Figure 1-2 shows the complete list of files produced when the command sqlj HelloWorld.sqlj is completed.