Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Working with Descriptor Properties

Each descriptor in the OracleAS TopLink Mapping Workbench contains the following default tabs and specific properties.

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.

Setting Descriptor Information

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:

  1. Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.

  2. Click the Descriptor Info tab.

    Figure 4-1 Descriptor Info Tab

    Description of desinfo.gif follows
    Description of the illustration desinfo.gif

  3. 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.


Note:

Use the caching options to specify how descriptors refresh the objects in the cache during queries. This ensures that queries against the session will refresh the objects from the row data.

Setting Class 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:

  1. Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.

  2. Click the Class Info tab in the Editor pane.

  3. Select the appropriate tab:

Class 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:

Field Description
Name Name of the class. This field is for display only.
Superclass Click Browse and select a class and package.
Modifiers
Access Modifiers Specify if the class is accessible publicly or only within its own package. Non-public classes are not accessible to the OracleAS TopLink Mapping Workbench.
Other Modifiers Specify if the class is Final and/or Abstract. Final classes are not included in the superclass selection lists for other classes to extend.
Interfaces Implemented To add an interface, click Add and select the interface and package. To remove an interface, select the interface and click Remove.

Note: You must save your project after removing an interface


Attributes Tab

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.

Figure 4-3 Attributes – General Tab

Description of clinatt.gif follows
Description of the illustration clinatt.gif

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.

Figure 4-4 Attributes – Accessors Tab

Description of clinatta.gif follows
Description of the illustration clinatta.gif

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.

Methods Tab

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.


Specifying Queries and Named Finders

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:

  1. In the Navigator pane, select a descriptor.

  2. Click the Queries tab in the Editor pane.

  3. Select the appropriate tab:

    • Custom SQL Queries

    • Named Queries

Custom SQL 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:

  1. In the Navigator pane, select a descriptor.

  2. Click the Queries tab in the Editor pane.

  3. Click the Custom SQL tab.

    Figure 4-6 Queries Custom SQL Tab

    Description of qrsqltab.gif follows
    Description of the illustration qrsqltab.gif

  4. Click the appropriate SQL function tab and type your own query object or SQL string to control these actions for a descriptor.

Tab Description
Insert Generates the insertObject() method of the Session class.
Update Generates the updateObject() method of the Session class.

When customizing a descriptor's update string if the application uses optimistic locking, you must ensure that the row is not written if the version field has changed since the object was read. Also, the update string must increment the version field if the row is written. In addition, the update string must maintain the row count of the database.

Delete Generates the deleteObject() method of the Session class.
Read Generates the readObject() method of the Session class

Customizing a descriptor's read-object query works only for the version of the readObject() that takes a primary key expression as a parameter. If other expressions are used, OracleAS TopLink generates dynamic SQL. You can define additional named queries for other read-object queries.

Read All Generates the readAllObjects() method of the Session class.

Customizing a descriptor's read-all query works only for the version of the readAll() that takes the class as a parameter—not the version that takes the class and an expression. As a result, the query reads every single instance. You can define additional named queries for other read-all queries.



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.

Named Queries

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:

  1. In the Navigator pane, select a descriptor.

  2. Click the Queries tab in the Editor pane.

  3. 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

    Figure 4-7 Named Queries Tab

    Description of qrnmdfnd.gif follows
    Description of the illustration qrnmdfnd.gif

  4. Click Add to create a new named query. The Add Named Query dialog box appears.

  5. 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.

  6. Click on the General tab to specify the query type and parameters.

    Figure 4-9 Named Queries General Tab

    Description of qrnmdgen.gif follows
    Description of the illustration qrnmdgen.gif

  7. Use this table to enter data in each field on the General tab.

    Field Description
    Descriptor Alias Alias for the descriptor class. This field applies for EJB finders only.
    Name Name of the query. The prefix of the query name specifies the query type:
    • find – EJB 2.0

    • ejbSelect – EJB Select

    You cannot change the name of OracleAS TopLink Reserved Finders.

    Type Use the drop-down list to specify whether this is a ReadObject or ReadAll query.
    Parameters Click Add to add a parameter of a specific type to this query.

    Note: You cannot add parameters for EJB descriptors.


  8. Click on the Format tab to specify the named query and its format.

    Figure 4-10 Named Queries Format Tab

    Description of qrnmdfor.gif follows
    Description of the illustration qrnmdfor.gif

  9. 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.


  10. 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.

    Figure 4-11 Named Queries Options Tab

    Description of qrnmdopt.gif follows
    Description of the illustration qrnmdopt.gif

  11. Use this table to enter data in each field on the Options:

    Field Description
    Refresh Identity Map Results Specify the refreshIdentityMapResults() method to refresh the attributes of the object resulting from the query.
    Cache Statement Specify the cacheStatement() method for the query.
    • If undefined, the query uses the project's default settings (see "Working with Default Properties" on page 2-9).

    • If true, then Bind Parameters must be true as well.

    Bind Parameters Specify the bindAllParameters() method for the query.
    • If undefined, the query uses the project's default settings (see "Working with Default Properties" on page 2-9).

    Cache Usage Select if/how the query checks the cache before accessing the database.
    In Memory Query Indirection Specify how a query reacts when accessing un-instantiated indirection. Use this option to specify the InMemoryQueryIndirectionPolicy policy.


    Note:

    These options are not available for findOneByQuery and findManyByQuery.

  12. Click Advanced to specify additional named query options.

    Figure 4-12 Advanced Query Options

    Description of advqropt.gif follows
    Description of the illustration advqropt.gif

  13. Use this table to enter data in each field and click OK:

Field Description
Maintain Cache Specify maintainCache() for the named query.
Use Wrapper Policy Specify the setWrapperPolicy() for the named query.
Prepare SQL Once Specify the setShouldPrepare() for the named query. By default, OracleAS TopLink optimizes queries to generate their SQL only once. You may need to disable this option for certain types of queries that require dynamic SQL based on their arguments, such as:
  • Expressions that use equal where the argument value could be null. This may cause problems on databases that require IS NULL, instead of = NULL.

  • Expressions that use in and use parameter binding. This will cause problems as the in values must be bound individually.

Cache Query Results Specify the cacheQueryResults() for the query. OracleAS TopLink can maintains an internal cache of the objects previously returned by a read query.
Refresh Remote Identity Map Results Specify the refreshRemoteIdentityMapResult() method for the query. OracleAS TopLink can refresh the attributes of the object(s) resulting from the query. With cascading, OracleAS TopLink will also refresh the private parts of the object(s).
Pessimistic Locking Specify the pessimistic locking policy for the query.
Distinct State Specify if OracleAS TopLink prints the DISTINCT clause, if a distinct has been set.
Query Timeout Specify if the query will time out (or abort) after a specified number of seconds.
Maximum Rows Specify if the query will limit the results to a specified number of rows. Use this to option for queries that could return an excessive number of objects.

Refer to the Oracle Application Server TopLink Application Developer's Guide for additional information on named queries.

Building Expressions

Use the Expression Builder to create OracleAS TopLink expressions for Named Queries.

To build an expression:

  1. 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 Expression Builder

    Description of expbld.gif follows
    Description of the illustration expbld.gif

    Figure 4-13 calls out the following user-interface components:

    1. Expression tree

    2. Arguments

  2. 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.

  3. 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).

  4. 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:
    • Literal — Click Edit and choose a literal type and value.

    • Query Key — Click Edit and select the query key.

    • Parameter — Choose a previously created parameter argument.

    See "Adding Arguments" for more information.


  5. Click OK. The OracleAS TopLink Mapping Workbench adds the expression to Named Queries tab.

Adding Arguments

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.

  1. Select an existing expression or click Add (or Add Nested) to add a new expression to the named query.

  2. For the First Argument, click Edit. The Choose Query Key dialog box appears.

    Figure 4-14 Choose Query Key

    Description of choseqk.gif follows
    Description of the illustration choseqk.gif

  3. Select the attribute, specify if the query allows a null value, and click OK.

  4. Use the Operator drop-down list to specify how OracleAS TopLink should evaluate the expression.

  5. 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

Query Keys

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.

Specifying Query Keys

Use the Query keys tab to specify a query key for a descriptor.

To specify query keys:

  1. Select a descriptor in the Navigator pane. Its properties appear in the Editor pane.

  2. Click the Query Keys tab in the Editor pane.

  3. 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.

  4. Use the Field drop-down list to select the field in the table used by the query.

Displaying EJB descriptor Information

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:

  1. In the Navigator pane, select an EJB descriptor.

  2. Click the EJB Info tab in the Editor pane.

  3. 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.