Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Project Creation Overview

You can create a project using TopLink Workbench or Java code.

Oracle recommends using TopLink Workbench to create projects and generate deployment XML or Java source versions of the project for use at run time. For more information, see "Using TopLink Workbench".

Alternatively, you can create projects in Java code. For an EIS project that uses a record type other than XML, you must use Java code. For more information, see "Using Java" and Oracle TopLink API Reference.

You can use TopLink to create a project:

- If you have both an object and data model: see "Creating a Project for an Existing Object and Data Model".

- If you have an object model but no data model yet: see "Creating a Project From an Existing Object Model".

- If you have a data model but no object model yet: "Creating a Project From an Existing Data Model".

- If you have an XML schema (XSD) document but no object model yet: see "Creating an XML Project From an XML Schema".

  If you have both XSD and object model classes, you can create an XML project using the procedure described in "Using TopLink Workbench".

- If you have a non-OC4J CMP project, you can create a project by migrating your application to OC4J and TopLink persistence: see "Creating a Project by Migrating an EAR to OC4J".

- If you are deploying an EJB 2.0 CMP application to OC4J, you can create a project (including all mappings and data model) automatically at deployment time: see "Creating a Project From an OC4J EJB 2.0 CMP EAR at Deployment Time".

## Using TopLink Workbench

When you create a project using TopLink Workbench, all project information is stored in the project file ( .`mwp` file). This file references additional XML data files that contain the information about how the Java classes map to database tables or XML elements.

Using TopLink Workbench, you can export this information as a TopLink project XML file (that is, the deployment XML file) that is read in by the TopLink runtime. You can also export this information as a Java class. For more information, see "Exporting Project Information".

TopLink Workbench displays projects and their contents in the Navigator window. When you select a project, its attributes are displayed in the Editor window. See "Using the Navigator" for more information. TopLink Workbench supports the following project types:

- Relational project

- XML project

- EIS project

### Creating New TopLink Workbench Projects

This section includes information on creating a new TopLink Workbench project. To create a new project from an existing persistence application (such as OC4J), see "Integrating TopLink With an Application Server ``". To create a new project from JAXB, see "TopLink Support for Java Architecture for XML Binding (JAXB)".

To create a new TopLink Workbench project, use this procedure:

1. Click New on the toolbar and select Project. The Create New TopLink Workbench Project dialog box appears.

   You can also create a new project by choosing File > New > Project from the menu.

   Figure 21-1 Create New TopLink Workbench Project Dialog Box

   Description of "Figure 21-1 Create New TopLink Workbench Project Dialog Box"

Use the following information to enter data in each field of this dialog box:

Field | Description
--- | ---
Name | Enter the name of the TopLink Workbench project. This project name will also become the name of the `.mwp` file.
Data Source | Use these options to specify the type of project to create, and its data source.
Database | Select Database to create an relational project to a relational database. Use the Platform list to select the specific database platform. See "Relational Projects" for more information.
EIS | Select EIS to create an EIS project to a nonrelational data source using XML records. Use the Platform list to specify the J2C adapter to use. See "EIS Projects" for more information.
XML | Select XML to create a nontransactional, nonpersistent XML project to an XML schema. Alternatively, you can generate both an XML project and object model classes (see "Creating an XML Project From an XML Schema"). See "XML Projects" for more information.

For more project information, continue with the following:

- Configure the project (see Chapter 22, "Configuring a Project").

- Add mappings and descriptors (see Chapter 26, "Understanding Descriptors" and Chapter 33, "Understanding Mappings").

- Export the project for use with the TopLink runtime (see "Exporting Project Information").

## Using Java

To create a project using Java code, use this procedure:

1. Implement a project class that extends the `oracle.toplink.sessions.Project` class (see Example 21-1).

2. Compile the project class.

Example 21-1 Specifying a TopLink Project in Code

    /**
    * The class EmployeeProject is an example of an Oracle TopLink project defined in Java code. The individual parts of the project - the Login and the descriptors, are built inside of methods that are called by the constructor. Note that EmployeeProject extends the class oracle.toplink.sessions.Project
    */
    public class EmployeeProject extends oracle.toplink.sessions.Project {

    /**
    * Supply a zero-argument constructor that initializes all aspects of the project. Make sure that the login and all the descriptors are initialized and added to the project. Project-level properties, such as the name of the project, should be specified here
    */
    public EmployeeProject() {
      setName("EmployeeProject");
      applyLogin();

      addDescriptor(buildAddressDescriptor());
      addDescriptor(buildEmployeeDescriptor());
      addDescriptor(buildPhoneNumberDescriptor());
    }
    // Data source information
    public void applyLogin() {
      DatabaseLogin login = new DatabaseLogin();

      // use platform appropriate for underlying database
      login.usePlatform(
        new oracle.toplink.platform.database.oracle.Oracle9Platform());
      login.setDriverClassName("oracle.jdbc.OracleDriver");
      login.setConnectionString("jdbc:oracle:thin:@HOST:PORT:SID");
      login.setUserName("USER NAME");
      login.setEncryptedPassword("PASSWORD, ENCRYPTED");

      // Configuration Properties
        setDatasourceLogin(login);
    }

    /**
    * Descriptors are built by defining table info, setting properties (caching, etc.) and by adding mappings to the descriptor
    */

    // SECTION: DESCRIPTOR
    public ClassDescriptor buildAddressDescriptor() {
      RelationalDescriptor descriptor = new RelationalDescriptor();

      // specify the class to be made persistent
      descriptor.setJavaClass(examples.servletjsp.model.Address.class);

      // specify the tables to be used and primary key
      descriptor.addTableName("ADDRESS");
      descriptor.addPrimaryKeyFieldName("ADDRESS.ADDRESS_ID");

      // Descriptor Properties
      descriptor.useSoftCacheWeakIdentityMap();
      descriptor.setIdentityMapSize(100)
      descriptor.useRemoteSoftCacheWeakIdentityMap()
      descriptor.setRemoteIdentityMapSize(100)
      descriptor.setSequenceNumberFieldName("ADDRESS.ADDRESS_ID")
      descriptor.setSequenceNumberName("ADD_SEQ");
      descriptor.setAlias("Address");

      // Mappings
      DirectToFieldMapping cityMapping = new DirectToFieldMapping();
      cityMapping.setAttributeName("city");
      cityMapping.setFieldName("ADDRESS.CITY");
      descriptor.addMapping(cityMapping);

      // … Additional mappings are added to the descriptor using the addMapping() method

    return descriptor;}

Note: Use TopLink Workbench to create a Java project class from an existing project. This provides a starting point for a custom project class. For more information, see "Exporting Project Java Source".