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
 

Enabling Your Java Classes

The Employee model uses three classes:

You must enable the Employee, PhoneNumber, and Address classes (provided in the examples.session.threetier.model package) for this tutorial, as "Generating the Class Definitions" describes.

Table B–5 shows how the classes relate to the database tables.

Table B-5 Employee Classes and Database Tables

Column Class Attribute Database Type Java Type
EMPLOYEE Employee

EMP_ID id NUMERIC(15) BigDecimal
NAME name CHAR(40) String
ADDRESS_ID address NUMERIC(15) Address
not applicable phoneNumbers not applicable Vector
ADDRESS Address

ADDRESS_ID id NUMERIC(15) BigDecimal
COUNTRY country VARCHAR(80) String
STREET street VARCHAR(80) String
CITY city VARCHAR(80) String
PROVINCE province VARCHAR(80) String
P_CODE postalCode VARCHAR(20) String
PHONE PhoneNumber

AREA_CODE areaCode CHAR(3) String
P_NUMBER number CHAR(7) String
EMP_ID owner NUMERIC(15) Employee
TYPE type VARCHAR(15) String


Note:

Supplying each of the class members in OracleAS TopLink-enabled classes with accessor methods is good programming practice. This tutorial provides the get and set methods for each attribute. For example, the Employee class should have an addPhoneNumber() method to allow a new PhoneNumber to store a reference to its parent.

Example B-1 Accessor Method

The following code example illustrates providing accessor methods.

// addPhoneNumber method of the Employee class allows the phoneNumber to set a reference to the Employee that owns it.
public void addPhoneNumber(PhoneNumber phoneNumber)
{
    getPhoneNumbers().addElement(phoneNumber);
    phoneNumber.setOwner(this);
}

Generating the Class Definitions

You must generate an OracleAS TopLink descriptor for each Java class in the project.

To create descriptors from the class definition file:

  1. From the Navigator pane, click the Employee project.

  2. Add or Refresh Classes button.
    Description of the illustration addclbt.gif

    Click the Add or Refresh Classes button or choose Selected > Add or Refresh Classes from the menu. The Select Classes dialog box appears.

    You can also create descriptors by right-clicking on the project in the Navigator pane and selecting Add or Refresh Classes from the pop-up menu.

    Figure B-9 Select Classes

    Description of select.gif follows
    Description of the illustration select.gif

  3. Plus sign icon.
    Description of the illustration plus.gif

    Locate the examples.sessions.threetier.model package. Click the plus sign to expand that package (or double-click the name to expand the package).

  4. Add button.
    Description of the illustration arrow.gif

    Highlight the Address class and click the button. OracleAS TopLink copies the Address class to the Selected Classes pane.

  5. Add button.
    Description of the illustration arrow.gif

    Repeat Step 4 for Employee and PhoneNumber classes in that package. (Or, highlight both classes using Shift+click or Ctrl+click as necessary, and click once to import all the remaining classes.)

  6. Click OK to import the classes. OracleAS TopLink creates a descriptor for each class and an unmapped mapping for each attribute. The descriptors and their attributes appear in the Navigator pane.


    Note:

    If an error occurs, check that the given classes are included in the classpath and that JDK has been installed correctly.

    Figure B-12 OracleAS TopLink Mapping Workbench with Employee Project

    Description of mwemp1.gif follows
    Description of the illustration mwemp1.gif

    Figure B-12 identifies the following user-interface elements:

    1. Package

    2. Class/descriptors

  7. Save button.
    Description of the illustration savebtn.gif

    Save your changes. Click Save or choose File > Save from the menu.