Generating pureQuery code from single tables, aliases, or views

You can generate a bean from a table, alias, view, or materialized query table (MQT) in a database. You can generate code that uses annotated methods or inline methods.

Before you begin

About this task

Beans are useful for passing input values to annotated or inline methods for querying or updating the database objects that the beans are based on.

If you want to use annotated methods, you can choose to generate the following Java objects:
  • An interface that contains abstract methods that are annotated with the SQL statements for querying and updating the database object that the generated bean is based on. You must have all of the privileges that are required for running the SQL statements.

    If you choose to generate this interface, the workbench also generates an implementation of the interface during a build of the Java project.

  • A test class that calls the methods in the implementation and displays the results in the Console view.

    If you choose not to generate the test class, you can do so at a later time by right-clicking the bean and selecting Data Access Development > Generate pureQuery Code. This option also regenerates the related interface and the implementation of that interface.

If you want to use inline methods, you can choose to generate a test class that contains inline methods for querying and updating the database object that the generated bean is based on. When you run the class, the results are displayed in the Console view. If you choose not to generate the test class, you can do so at a later time by right-clicking the bean and selecting Data Access Development > Generate pureQuery Code.

Procedure

To generate code from a single table, alias, view, or MQT:

  1. In the Data Source Explorer, right-click the table, alias, view, or MQT that you want to represent as a Java bean, and then select Data Access Development > Generate pureQuery Code. The Generate pureQuery Code from a Table wizard opens.
  2. Complete the steps of the wizard. For information about each field, press F1.
  3. Click Finish to generate the code that you specified.

Results

If you did not already add pureQuery support to your Java project, after you click Finish the workbench creates the folder dataAccessFolder in your Java project.

If you are using DB2® for z/OS®, or DB2 for Linux, UNIX, or Windows, this folder contains the files Default.genProps and Default.bindProps. You use these files if you plan to run SQL statements statically from applications that use annotated methods.


Feedback