Oracle® Application Development Framework Developer's Guide
10g Release 3 (10.1.3) B25386-01 |
|
![]() Previous |
![]() Next |
The TopLink map (.mwp
file) contains the information required to represent database tables as Java classes. You can use the Create TopLink Map wizard or the Mapping editor to create this data, or manually code the file using Java and the TopLink API.
Use this information, or metadata, to pass configuration information into the run-time environment. The run-time environment uses the information in conjunction with the persistent entities (Java objects or EJB entity beans) and the code written with the TopLink API, to complete the application.
Descriptors
Descriptors describe how a Java class relates to a data source representation. They relate object classes to the data source at the data model level. For example, persistent class attributes may map to database columns.
TopLink uses descriptors to store the information that describes how an instance of a particular class can be represented in a data source (see Section 3.4, "Mapping Classes to Tables"). Most descriptor information can be defined by TopLink, then read from the project XML file at run time.
Persistent Classes
Any class that registers a descriptor with a TopLink database session is called a persistent class. TopLink does not require that persistent classes provide public accessor methods for any private or protected attributes stored in the database.
To automatically create Java classes from your database table, use the Create Java Objects from Tables wizard. With this wizard you can create the following:
Java class for each table
TopLink map
Mapped attributes for each tables' columns
Figure 3-4 Create Java Objects from Tables Wizard
After creating the initial Java classes and TopLink mappings, use the Mapping editor to customize the information. Refer to the Oracle JDeveloper online help for additional information.
After completing the Create Java Objects from Tables wizard JDeveloper creates a TopLink map and adds it to the project.
The wizard will also create TopLink descriptor and mappings for each Java attribute (as defined by the structure and relationships in the database).
After creating a Java class from a database table, you can modify the generated TopLink descriptor and mappings. This section includes information on the following:
The Create Java Objects from Tables wizard will associate the TopLink descriptor with a specific database table.
Use the Multitable Info tab in the Mapping editor (as shown in Figure 3-7) to associate an amendment method with a descriptor.
You can associate a static Java method to be called when a descriptor is loaded at run time. This method can amend the run-time descriptor instance through the descriptor Java code API. Use this method to make some advanced configuration options that may not be currently supported by the TopLink.
The Java method must have the following characteristics:
Be public static.
Take a single parameter of type oracle.toplink.descriptors.ClassDescriptor
.
Use the After Load tab in the Mapping editor (as shown in Figure 3-8) to associate an amendment method with a descriptor.
When using the Create Java Objects from Tables wizard, Oracle JDeveloper automatically generates the basic code for your Java classes.
Example 3-3 Sample Generated Java Class
package mypackage; import java.util.ArrayList; import java.util.List; public class Address { /**Map employeeCollection <-> mypackage.Employee * @associates <{mypackage.Employee}> */ private List employeeCollection; private Long addressId; private String pCode; ...