Editing generated pureQuery code that supports the annotated-method programming style

After you generate an interface that declares annotated methods, you can edit the SQL statements and change, add, or remove any of those methods. You can then regenerate the implementation of that interface before running the test class to test your code. You can also edit the implementation classes that correspond to your interfaces.

Procedure

To edit generated pureQuery code:

  1. If you want to edit a bean that the workbench generated from a table, follow these steps:
    1. In the Project Explorer, double-click the bean to open it in the Java™ editor.
    2. Make your changes.
    3. Regenerate the related interface and the implementation class for that interface:
      1. In the Java editor, right-click the bean and select pureQuery > Generate pureQuery Code.
      2. In the Generate pureQuery Code from a Table wizard, specify to generate the interface.
    4. If the workbench is not configured to perform incremental builds, select Project > Build Project to generate the implementation of the interface. You can configure the workbench to perform incremental builds by selecting Window > Preferences. In the Preferences window, select General > Workspace. On the Workspace page, select Build automatically.
  2. If you want to edit a generated interface, follow these steps:
    1. In the Project Explorer, double-click the interface to open it in the Java editor.
    2. Make your changes.
      • If you need to change the SQL statement for a method:
        • If you want to use the same number of positional input parameters and keep the same order for the parameters, edit the SQL statement but do not edit the signature of the method.
        • If you want to use a different number of input parameters, a different order for the parameters, or both:
          1. Edit the SQL statement.
          2. Edit the method signature to match the number of input parameters for the SQL statement.
          3. Edit the test class so that it passes the right number of input parameters to the method.
        • If the statement is a SELECT statement and you need a different result set, generate a bean that represents the result set. Right-click the SQL statement and select Generate pureQuery Code.
      • Change the names of any methods. Be sure to edit the test class so that it invokes the methods by their new names.
      • Add new methods and corresponding SQL statements. Be sure to add code in the test class so that the test class can invoke the new methods.
    3. Regenerate the implementation of the interface by using either of these two methods:
      • If the workbench is configured to build automatically, save your changes to the interface.
      • If the workbench is not configured to build automatically, select Project > Build Project to generate the implementation of the interface. You can configure the workbench to build automatically by selecting Window > Preferences. In the Preferences window, select General > Workspace. On the Workspace page, select Build automatically.
  3. If you want to edit a generated implementation class for an interface, follow these steps.

    By default, the workbench considers generated implementation classes to be user code. When you edit an interface, save the changes, and rebuild your Java project, the workbench regenerates the implementation class but does not delete any of the changes that you might have made in the implementation class, provided that you follow certain conventions when editing. Those conventions are explained in the steps that follow.

    Attention: Do not edit an implementation class if it contains the following comment:
    // This generated code should not be modified. Any changes should be made to the Interface source
    // file and this implementation code regenerated.

    To edit an implementation class:

    1. Double-click the implementation class to open it in the Java editor.
    2. Follow these conventions when making your changes.
      • Remove the @generated annotation in the comment above any definition of a method or property that you modify. Removing this annotation ensures that the workbench preserves your changes.
      • If you want to add comments, include them between the following tags:
        <\!-\- begin-user-doc \-->
        <\!-\- end-user-doc \-->
        For example, suppose that the workbench generates an implementation with the following definition of a property:
        /**   
        * @generated   
        */ 
        public static final String identifier = "ActInterface";
        You put your comment between the special tags, like this:
        /**   
        * <\!-\- begin-user-doc \-->
        * This is my comment.
        * <\!-\- end-user-doc \-->
        * @generated   
        */ 
        public static final String identifier = "ActInterface";
    If you do not want the workbench to consider generated implementation classes to be user code, follow these steps:
    1. Right-click your Java project and select Properties.
    2. On the pureQuery > Generator page, clear the Treat generated implementations as user code check box.
    From now on, the workbench ignores any changes that you might make to generated implementation classes. When you regenerate an implementation class, your changes are erased.

Feedback