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 . 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 .
Restriction: You cannot generate views from beans.
Procedure
To generate code from a bean:
- Create a bean that corresponds to a table, or import such
a bean into your Java project.
- Open the bean in the Java editor.
- If the database that is associated with your Java project does not yet contain a table that
corresponds to the bean, follow these steps:
- Right-click in the bean and select Data Access
Development > Generate DDL. The DDL appears in the Console view.
- 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.
- Run the DDL on the database.
- 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.
- In the Java editor,
right-click in the bean and select Data Access Development > Generate
pureQuery Code. The Generate pureQuery
Code from a Table wizard opens.
- Complete the wizard steps. For detailed information
about each field, press F1.
- 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 beansJava 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 |