Creating Eclipse Modeling Framework Technologies (EMFT) Java Emitter Templates (JET) to generate customized code

The workbench uses EMFT JET templates when generating pureQuery code. You can override this default JET transformation with your own.

About this task

Overriding the workbench's default JET transformation to produce pureQuery code involves creating an EMFT JET project, creating templates, and telling the workbench to use your JET transformation.

Important: You do not need to create XML documents to use as input models for your JET transformation. When you generate your customized pureQuery code, the wizards create the XML automatically, based on the object that you are basing the code upon. The XML is transitory and is not saved.
However, you must know the format of the XML that the wizards create. You can find the schema in the com.ibm.datatools.javatool.transform.codegen plugin. You can also view the following sample XML documents that are based on this schema:

To generate your customized code, you use the pureQuery code generation wizards that correspond to the templates that you are overriding. For example, if you override the GenTableBean.jet template, you can generate your customized code by using the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

For information about EMFT JET (which is called now called Model-To-Text JET), visit www.eclipse.org.

Procedure

To create and configure EMFT JET templates to generate customized code for pureQuery code:

  1. Create an EMFT JET Transformation project. Right-click in the Package Explorer and select New > Project. In the New Project wizard, select EMFT JET Transformations > EMFT JET Transformations Project.
  2. Edit the manifest.mf file for your project This file must specify that you are overriding pureQuery's default transformation.

    If you want to use the DBHelper class, a class in the com.ibm.datatools.javatool.transform.codegen plugin that obtains information about the database connection that the transformation needs, the manifest file must specify that it has a dependency on the com.ibm.datatools.javatool.transform.codegen plugin. Within this plugin is documentation of this class.

    1. Double-click the manifest.mf file in your project to open this file for editing.
    2. Click the Extensions tab.
    3. In the All Extensions field, expand org.eclipse.jet.transform and then select (transform).
    4. In the overrides field, type com.ibm.datatools.javatool.transform.codegen.
    5. Optional: Click the Dependencies tab and add the com.ibm.datatools.javatool.transform.codegen plugin as a required plugin, if you want to use the DBHelper class.
    6. Save and close the file.
  3. In your EMFT JET Transformation project, delete the file dump.jet. You can also delete the main.jet file if you want your transformation to use the main.jet file from the com.ibm.datatools.javatool.transform.codegen transformation.
  4. In the templates directory in your EMFT JET Transformation project, create templates that override templates in the com.ibm.datatools.javatool.transform.codegen transformation. To override one of the pureQuery default templates, create a template with the same name. If you do not override a default template, the workbench continues to use it when you generate the corresponding pureQuery code.

    The following table lists the templates that are in that transformation.

    Table 1. Templates in the com.ibm.datatools.javatool.transform.codegen transformation
    Name of template Supported DBMS Description
    GenProcedureHandler.jet Oracle Used when you generate code from a stored procedure that runs against an Oracle database.
    GenProcedureInlineJunit.jet
    • DB2® for Linux®, UNIX®, and Windows®
    • DB2 for z/OS®
    • Informix® Dynamic Server
    • Oracle
    Used when you select both the Generate test class for inline style check box and the Generate JUnit test cases check box on the Generate pureQuery Code from a Stored Procedure wizard.

    Generates a JUnit test case that contains inline methods for calling the corresponding stored procedure.

    GenProcedureInlineSample.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate test class for inline style check box on the Generate pureQuery Code from a Stored Procedure wizard.

    Generates a Java™ test class that contains inline methods for calling the corresponding stored procedure.

    GenProcedureInterface.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate Java interface for stored procedure check box on the Generate pureQuery Code from a Stored Procedure wizard.

    Generates a Java interface that contains annotated methods for calling the corresponding stored procedure.

    GenProcedureInterfaceJunit.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate Java interface for stored procedure check box, the Generate test class for Java interface for stored procedure check box, and the Generate JUnit test cases check box on the Generate pureQuery Code from a Stored Procedure wizard.

    Generates a JUnit test case that contains annotated methods for calling the corresponding stored procedure.

    GenProcedureInterfaceTest.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select both the Generate Java interface for stored procedure check box and the Generate test class for Java interface for stored procedure check box on the Generate pureQuery Code from a Stored Procedure wizard.

    Generates a test class for testing the implementation of the corresponding interface.

    GenProcedureParmBean.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when a stored procedure processed by the Generate pureQuery Code from a Stored Procedure wizard has parameters.

    Generates a bean that contains properties that represent the parameters of a stored procedure.

    GenSampleUtil.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle

    Generates a class that contains static methods that are called by the test classes when they run. These methods print to the Console view the results from running the test classes.

    This class also contains code for to establish database connections for the test classes.

    GenSQLBean.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you click Finish in the Generate pureQuery Code from an SQL Statement or the Generate pureQuery Code from SQL Statements wizard.

    Generates pureQuery code that is based on the type of SQL statement or statements being processed.

    GenTableBean.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you generate a bean from the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a bean that contains properties that represent the columns of a table or view.

    GenTableInlineJunit.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select both the Generate test class for inline style check box and the Generate JUnit test cases check box in the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a JUnit test case that contains inline methods for accessing the corresponding database object.

    GenTableInlineSample.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate test class for inline style check box in the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a Java test class that contains inline methods for accessing the corresponding database object.

    GenTableInterface.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate annotated-method interface for table check box in the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a Java interface that contains annotated methods for accessing the corresponding database object.

    GenTableInterfaceJUnit.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select the Generate annotated-method interface for table check box, the Generate test-class for annotated-method interface for table check box, and the Generate JUnit test cases check box in the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a JUnit test case for testing the implementation of the corresponding interface.

    GenTableInterfaceTest.jet
    • DB2 for Linux, UNIX, and Windows
    • DB2 for z/OS
    • Informix Dynamic Server
    • Oracle
    Used when you select both the Generate Java interface for table check box and the Generate test class for Java interface for table check box in the Generate pureQuery Code from a Table wizard or the Generate pureQuery Code from Tables wizard.

    Generates a test class for testing the implementation of the corresponding interface.

  5. On the pureQuery Transforms preference page, specify which transformation the workbench must use:
    1. Select Window > Preferences.
    2. Select Data Management > SQL Development > pureQuery > Transforms.
    3. In the Transform ID field, select the name of your EMFT JET Transformation project.

Example

The examples describe sample XML documents used as input for the pureQuery JET templates.


Feedback