Generating pureQuery code from beans

You can generate pureQuery code from a bean that is open in the Java™ editor. If a table corresponding to the bean does not yet exist in the associated database, you can generate a DDL statement for creating the table.

Before you begin

Display the Data Source Explorer and Console view in your workbench:
  • If the Data Source Explorer is not open in the workbench, select Window > Show View > Other. In the Show View window, select Connectivity > Data Source Explorer.
  • If the Console view is not open in the workbench, select Window > Show View > Console.
  • If the Console view is open in the workbench, right-click in that view and select Clear.

About this task

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 table that the 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 pureQuery > 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 table that the 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 pureQuery > Generate pureQuery Code.

Restriction: You cannot generate views from beans.

Procedure

To generate code from a bean:

  1. Create a bean that corresponds to a table, or import such a bean into your Java project.
  2. Open the bean in the Java editor.
  3. If the database that is associated with your Java project does not yet contain a table that corresponds to the bean, follow these steps:
    1. Right-click in the bean and select pureQuery > Generate DDL. The DDL appears in the Console view.
    2. Copy the DDL and paste it into a new text file. If you want to run the DDL from the workbench, you can create a new file in your Java project. Give the file a .sql extension.
    3. Run the DDL on the database.
    4. If you want to verify that the table was created correctly, follow either or both of these steps:
      • To verify that the name of the bean maps to the correct table, right-click in the bean and select Show Table in Data Source Explorer. The table is highlighted.
      • To verify that a property maps to the correct column, right-click the name of a property and select Show Table in Data Source Explorer. The column that is mapped to the property is highlighted.
  4. In the Java editor, right-click in the bean and select pureQuery > Generate pureQuery Code. The Generate pureQuery Code from a Table wizard opens.
  5. Complete the wizard steps. For detailed information about each field, press F1.
  6. Click Finish to generate the files that you specified.

Results

The following table lists Java data types and the corresponding Oracle SQL data types:

Table 1. How Java data types map to Oracle SQL types in DDL that the workbench generates from beans
Java data type Oracle SQL data type
BigDecimal NUMBER(9 , 2)
Blob BLOB
Boolean RAW(1)
boolean RAW(1)
byte RAW(1)
BYTE_ARRAY RAW(2000)
char CHAR(1)
CHAR_ARRAY VARCHAR2(255)
Clob CLOB
Date DATE
Double BINARY_DOUBLE
double BINARY_DOUBLE
Float BINARY_FLOAT
float BINARY_FLOAT
int NUMBER
Integer NUMBER
Long NUMBER
long NUMBER
Ref VARCHAR2(255)
Short NUMBER
short NUMBER
String VARCHAR2(255)
Time DATE
Timestamp TIMESTAMP(6)
URL BFILE

Feedback