Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
Each descriptor in the OracleAS TopLink Mapping Workbench contains the following default tabs and specific properties.
Descriptor Info
Class Info
Query Keys
Queries
EJB Info (for EJB descriptors only)
Use the Set Advanced Properties function (see "Working with Advanced Properties" and "To Specify the Default Advanced Properties for Descriptors:" on page 2-12) to specify additional properties for each descriptor.
Use the Descriptor Info tab to map a descriptor to a specific table in the database, define primary key(s), specify sequencing information, and set caching options.
To map a descriptor to a table:
Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.
Use this table to enter data in each field:
Field | Description |
---|---|
Associated Table | Use the drop-down list to select a database table for the descriptor. |
Primary Keys | Specify the primary key(s) for the table. |
Use Sequencing | Specify if this descriptor uses sequencing. If selected, specify the Name, Table, and Field for sequencing. See "Working with Sequencing" for more information. |
Read Only | Specify if this descriptor is read-only. |
Conform Results in Unit of Work | Specify to use the conformResultsInUnitOfWork() method for any read object or read all query.
Refer to the Oracle Application Server TopLink Application Developer's Guide for more information. |
Refreshing Cache |
|
Default | Use the project's default caching options. OracleAS TopLink will not refresh the cache unless a read query is configured to refresh the cache. |
Always Refresh | Refreshes the objects in the cache on all queries.
Note: Using this property may impact performance. |
Disable Cache Hits | Disables the cache hits on primary key read object queries. |
Only Refresh if Newer | Refreshes the cache only if the object in the database is newer than the object in the cache (as determined by the Optimistic Locking field). See "Working with Optimistic Locking" for more information. |
After generating classes and descriptors, use the Class Info tab to:
Rename classes, attributes, and methods
Add, delete, or edit the generated attributes and methods
Generate Java source to create new classes
To specify class info:
Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.
Click the Class Info tab in the Editor pane.
Select the appropriate tab:
Attributes Tab
Methods Tab
To add a new interface to implement, click Add.
To delete an interface, select the interface and click Remove.
To generate source code for the descriptor, click Generate Source Code.
Use this table to enter data in each field:
To add a new attribute, click Add.
To delete an existing attribute, select the attribute and click Remove.
To rename an existing attribute, select the attribute and click on Rename.
Select an attribute, then use this table to enter data in each field on the General tab.
Field | Description |
---|---|
Modifiers |
|
Access Modifiers | Specify how the attribute is accessible:
|
Other Modifiers | Specify whether the attribute is Final, Static, Transient, or Volatile.
Note: Selecting some modifiers may disable others. |
Type Information |
|
Type | Click Browse and select a class and package for the attribute. |
Type Dimensionality | Specify the length of an array. This field applies only if Type is an array. |
Select an attribute, then use this table to enter data in each field on the Accessors tab.
Field | Description |
---|---|
Get Method | Choose the get( ) method for the attribute.
|
Set Method | Choose the set( ) method for the attribute.
|
To generate a get
or set
method for an attribute, click Generate Get/Set Methods.
To add a new method, click Add.
To delete an existing method, select the method and click Remove.
Select a method, then use this table to enter data in each field:
Field | Description |
---|---|
Modifiers |
|
Access Modifiers | Specify how the attribute is accessible:
|
Other Modifiers | Specify whether the attribute is Final, Static, Transient, or Volatile.
Note: Selecting some modifiers may disable others. |
Return Type | Click Browse and select a class and package. |
Type Dimensionality | Specify the length of the array (Return Type). |
Parameters | Click Add to include parameter(s) for the method.
Note: The parameters are loaded in the order listed. |
Use the Queries tab to specify EJB QL and SQL queries and finders to use for database access. The Queries tab contains two additional tabs: Named Queries and Custom SQL.
For 2.0 CMP projects, the ejb-jar.xml
file stores query lists. You can define the queries in the file and then read them into the OracleAS TopLink Mapping Workbench, or define them on the Queries tab and write them to the file. See "Writing to the ejb-jar.xml File" on page 2-19 for more information.
To create queries:
In the Navigator pane, select a descriptor.
Click the Queries tab in the Editor pane.
Select the appropriate tab:
Custom SQL Queries
Named Queries
Use this procedure to create custom SQL queries in the OracleAS TopLink Mapping Workbench. For 2.0 CMP projects, the SQL is not written to the ejb-jar.xml
file.
To create custom SQL queries:
In the Navigator pane, select a descriptor.
Click the Queries tab in the Editor pane.
Click the Custom SQL tab.
Click the appropriate SQL function tab and type your own query object or SQL string to control these actions for a descriptor.
Note: The OracleAS TopLink Mapping Workbench does not validate the SQL code that you enter. The code is defined by the specific database type. |
Custom QueriesTo control the five custom query tabs, you can include your own query object or SQL string for a particular descriptor. The SQL string for each database is defined by the type of database. For example, the stored procedure to read an object may use the following string:Read_Employee(EMP_ID=>4653) The query manager requires the following string to read the object: Read_Employee(EMP_ID=>#EMP_ID)In this query, the hash character, #
, binds the argument EMP_ID
within the SQL string.
Use named queries to specify SQL, EJB QL, or OracleAS TopLink Expression queries to access the database. EJB QL is a declarative language that presents queries from an object-model perspective. Refer to the EJB specification and the Oracle Application Server TopLink Application Developer's Guide for detailed information.
To create a named query:
In the Navigator pane, select a descriptor.
Click the Queries tab in the Editor pane.
Click the Named Queries tab in the Queries tab. The Named Queries tab contains the following additional tabs:
Named Queries General tab
Named Queries Format tab
Named Queries Options tab
Click Add to create a new named query. The Add Named Query dialog box appears.
Select the query type (for EJB descriptors), enter the query name, and press Enter. The OracleAS TopLink Mapping Workbench adds the query to the Named Query tab.
Note: For OracleAS TopLink Reserved Finders, use the drop-down box to select a reserved name. OracleAS TopLink will generate the query at runtime. |
Click on the General tab to specify the query type and parameters.
Use this table to enter data in each field on the General tab.
Click on the Format tab to specify the named query and its format.
Use this table to enter data in each field on the Format tab.
Field | Description |
---|---|
Expression | Specify this named query uses an OracleAS TopLink expression. |
SQL | Specify this named query is a SQL query. |
EJB QL | Specify this named query is an EJB QL query. |
Query String | Entry the query. The OracleAS TopLink Mapping Workbench does not validate the query string.
Note: For Expressions, double-click the query string or click Edit to create or edit the query string. See "Building Expressions" for more information. |
Click on the Options tab to specify additional options for the named query.
Note: If the options on this panel are disabled, the Mapping Workbench uses the options specified in the parent. |
Use this table to enter data in each field on the Options:
Use this table to enter data in each field and click OK:
Refer to the Oracle Application Server TopLink Application Developer's Guide for additional information on named queries.
Use the Expression Builder to create OracleAS TopLink expressions for Named Queries.
To build an expression:
From the Named Queries Format tab (see Figure 4-10), click Edit (or double-click a query string). The Expression Builder dialog box appears.
Figure 4-13 calls out the following user-interface components:
Expression tree
Arguments
Click Add or Add Nested to create a new expression. OracleAS TopLink assigns a sequence number to each node and nested node.
Click Remove to remove an existing expression.
Select the node and use the Logical Operator drop-down list to specify the operator for the node (AND, OR, Not AND, or Not OR).
Choose the expression and use this table to enter data in each field:
Field | Description |
---|---|
First Argument | Click Edit and select the query key for the first argument. See "Adding Arguments" for more information. |
Operator | Specify how OracleAS TopLink should evaluate the expression. Valid operators include: Equal, Not Equal, Equal Ignore Case, Greater Than, Greater Than Equal, Less Than, Less Than Equal, Like, Not Like, Like Ignore Case, Is Null, and Not Null. |
Second Argument | Specify the second argument:
See "Adding Arguments" for more information. |
Click OK. The OracleAS TopLink Mapping Workbench adds the expression to Named Queries tab.
Each expression contains elements (arguments) to evaluate. Expressions using the Is Null or Not Null operators require only a single argument.
Use this procedure to add new arguments.
Select an existing expression or click Add (or Add Nested) to add a new expression to the named query.
For the First Argument, click Edit. The Choose Query Key dialog box appears.
Select the attribute, specify if the query allows a null value, and click OK.
Use the Operator drop-down list to specify how OracleAS TopLink should evaluate the expression.
For the Second Argument, select Literal, Query Key, or Parameter, and click Edit.
For Literal arguments, the Edit the Literal Type and Value dialog box appears. Choose the literal type (such as String or Integer) and value.
For Query Key arguments, the Choose Query Key dialog box appears (see Figure 4–14).
For Parameter arguments, use the drop-down list to select the specific parameter, as created on the Named Queries General tab (see Figure 4–9).
Repeat this procedure for each expression or sub-expression.
Example 4-1 Sample Expression
This expression:
AND 1.manager(Allows Null).lastName EQUAL "Jones" 2.OR 2.1.projects.name LIKE "BETA" 2.2.projects.id EQUAL "4" 3.OR 3.1.AND 3.1.1.address.country EQUAL "Canada" 3.1.2.salary GREATER THAN "25000" 3.2.AND 3.1.1.address.country EQUAL "United States" 3.1.2.salary GREATER THAN "37500"
will find employees who:
Have a manager with the last name Jones or have no manager, and
Work on projects with the name Beta or project ID 4, and
Live in Canada and have a salary of more than 25,000 or Live in the United States and have a salary of more than 37,500
The OracleAS TopLink Mapping Workbench uses query keys as an alias for a field name. With an alias, OracleAS TopLink expressions can use the Java names instead of DBMS-specific field names. See "Automatically-generating Query Keys" for additional information.
Use the Query Keys tab to create user-defined queries or to work with automatically generated query keys.
Use the Query keys tab to specify a query key for a descriptor.
Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.
To add a new query key, click Add.
To delete an existing query key, select the query key and click Remove.
To rename an existing query key, select the query key and click Rename.
Use the Field drop-down list to select the field in the table used by the query.
Use the EJB Info tab to display the EJB descriptor's information (from the ejb-jar.xml
file). This tab is available only for EJB descriptors.
To display EJB descriptor information:
In the Navigator pane, select an EJB descriptor.
Use this table to identify each field:
Field | Description |
---|---|
EJB Name | Base name. When using EJB 2.0, this is specified in the <ejb-name> element of the ejb-jar.xml file.
|
Primary Key Class | Primary key. When using EJB 2.0, this is specified in the <prim-key-class> element of the ejb-jar.xml file.
|
Local Interface | Local interface. When using EJB 2.0, this is specified in the <local> element of the ejb-jar.xml file.
|
Local Home Interface | Local home interface. When using EJB 2.0, this is specified in the <local-home> element of the ejb-jar.xml file.
|
Remote Interface | Remote interface. When using EJB 2.0, this is specified in the <remote> element of the ejb-jar.xml file.
|
Remote Home Interface | Remote interface. When using EJB 2.0, this is specified in the <home> element of the ejb-jar.xml file.
|
Note: When using EJB 2.0 persistence, these fields are for display only. |