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:
- If you want to edit a bean that the workbench generated
from a table, follow these steps:
- In the Project Explorer, double-click the bean to open
it in the Java editor.
- Make your changes.
- Regenerate the related interface and the implementation
class for that interface:
- In the Java editor, right-click
the bean and select .
- In the Generate pureQuery Code from a Table wizard,
specify to generate the interface.
- 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 . In the Preferences window,
select . On the Workspace page, select Build
automatically.
- If you want to edit a generated interface, follow these
steps:
- In the Project Explorer, double-click the interface
to open it in the Java editor.
- 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:
- Edit the SQL statement.
- Edit the method signature to match the number of input parameters
for the SQL statement.
- 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.
- 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 to generate the implementation of the interface. You
can configure the workbench to build automatically by selecting . In the Preferences window, select . On the Workspace page, select Build
automatically.
- 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:
- Double-click the implementation class to open it in
the Java editor.
- 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: - Right-click your Java project
and select Properties.
- On the 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.