You can create Java™ Emitter
Templates (JET) to generate
SQLJ files that use the information that the New SQLJ File wizard
collects.
Prerequisite: Create a JET project in the
workbench.
To perform
this task, you must have experience with creating Java Emitter
Templates. For information
about creating Java Emitter Templates, see the
following articles on
the eclipse.org Web site:
To save space in the task steps, the
full path to the ...\com.ibm.datatools.sqlj directory
is omitted. The full path is install_directory\eclipse\plugins\com.ibm.datatools.sqlj.
To
create and implement a JET template for the New SQLJ File wizard:
- Add a skeleton to the JET project:
- Import
the SQLJFileSkeleton.skel file into your JET
project. The file is in the ...\com.ibm.datatools.sqlj\templates\skeleton directory.
- Create a skeleton in your JET project. The skeleton must define
a class
that implements the ISQLTemplate interface with a generate() method
that accepts IBeanData as a parameter.
- Create your template in your JET project. You
can create
a file or you can import one of the templates that is supplied with
the workbench
and change its content to fit your needs. The template files are in
the ...\com.ibm.datatools.sqlj\templates directory.
The
JET directive in your template must contain:
- A class name that
is unique among all the templates in the ...\com.ibm.datatools.sqlj\templates directory.
A class name that is the same as the template name is a good practice.
- A skeleton attribute that references the skeleton
that
you are using.
- Add the run-time
JAR file for the SQLJ plug-in to the Java build
path of your project. In the project Properties window, click Java
Build Path, and then do one of the following actions on
the Libraries
page:
- If you created an SQLJ file with the New
SQLJ File wizard, click Add
Variable, and then double-click SQLJPLUGIN in
the New Variable Classpath Entry window.
- If you did
not use the New SQLJ File wizard, click Add
External JARs, go to the ...\com.ibm.datatools.sqlj directory
in the JAR Selection window, and then double-click the sqlj.jar file.
The run-time JAR file for the SQLJ plug-in resolves
the references in
your template to the classes in the SQLJ plug-in.
- After the template compiles successfully, copy its .sqljjet file
to the ...\com.ibm.datatools.sqlj\templates directory.
If you created a new skeleton file, copy it to the subdirectory under ...\com.ibm.datatools.sqlj that
matches the reference in the JET directive.
- Add
the description for your template to the user.properties file
in the ...\com.ibm.datatools.sqlj\template\properties directory. Open the file in a text editor and add the following two lines
after
the comment lines:
template_file_name.label=Template name
template_file_name.desc=Template description.
The template name that is specified in the label is included
in
the Template list in the New SQLJ File wizard.
When
the template is selected in the list, its description is shown in
the display
box next to the list.
- Use the wizard
to create an SQLJ file, select your template, and
then review the resulting code in the generated SQLJ file.
If you need to make changes to the template, you
can use one of the
following methods:
- Use a text editor to change the template
file directly in the ...\com.ibm.datatools.sqlj\templates directory.
- Use the workbench to change the template in your JET project,
and then
copy the updated file to the SQLJ plug-in directory (...\com.ibm.datatools.sqlj\templates).
The next time that you use the New SQLJ File wizard to create
a new SQLJ
file, the SQLJ plug-in will detect that your template file changed
and will
use the updated template.