Creating and implementing Java Emitter Templates for the New SQLJ File wizard

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, 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.etools.sqlj directory is omitted. The full path is install_directory\rwd\eclipse\plugins\com.ibm.etools.sqlj.

To create and implement a JET template for the New SQLJ File wizard:

  1. Add a skeleton to the JET project:

    • Import the SQLJFileSkeleton.skel file into your JET project. The file is in the ...\com.ibm.etools.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.

  2. 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.etools.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.etools.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.

  3. Add the run-time JAR file for the SQLJ plug-in to your project's Java build path. In the project's 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.etools.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.

  4. After the template compiles successfully, copy its .sqljjet file to the ...\com.ibm.etools.sqlj\templates directory. If you created a new skeleton file, copy it to the subdirectory under ...\com.ibm.etools.sqlj that matches the reference in the JET directive.

  5. Add the description for your template to the user.properties file in the ...\com.ibm.etools.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.

  6. 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:

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.

 

Related concepts

Java Emitter Templates and the New SQLJ File wizard

Related reference
SQLJ template interfaces