Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
The Employee
model uses three classes:
Employee
class has a name attribute and privately owned PhoneNumber
and Address
relationships.
PhoneNumber
class has attributes describing the phone number information and a relationship that describes the owner of the PhoneNumber.
Address
class has attributes describing the employee's mailing address.
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 theget 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.
|
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); }
You must generate an OracleAS TopLink descriptor for each Java class in the project.
To create descriptors from the class definition file:
From the Navigator pane, click the Employee
project.
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.
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).
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.
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.)
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
Figure B-12 identifies the following user-interface elements:
Package
Class/descriptors
Description of the illustration savebtn.gif
Save your changes. Click Save or choose File > Save from the menu.