Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Configuring a Project (ELUG)"

m (New page: <div style="float:right;border:1px solid #000000;padding:5px">__TOC__ Related Topics</div> This section describes how to create EclipseL...)
 
Line 1: Line 1:
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
 
<div style="float:right;border:1px solid #000000;padding:5px">__TOC__
[[Special:Whatlinkshere/Creating a Project (ELUG)|Related Topics]]</div>
+
[[Special:Whatlinkshere/Configuring a Project (ELUG)|Related Topics]]</div>
 
This section describes how to create EclipseLink projects.
 
This section describes how to create EclipseLink projects.
  

Revision as of 15:02, 19 November 2007

This section describes how to create EclipseLink projects.

For information on the various types of projects available, see EclipseLink Project Types.


Introduction to the Project Creation

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

We recommend using the Workbench to create projects and generate deployment XML or Java source versions of the project for use at run time. For more information, see How to Create a Project Using the 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 How to Create a Project Using Java and EclipseLink API Reference.

For information on how to create a project using Java, see How to Create a Project Using Java.


How to Create a Project Using the Workbench

When you create a project using 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 Workbench, you can export this information as a EclipseLink project XML file (that is, the deployment XML file) that is read in by the EclipseLink runtime. You can also export this information as a Java class. For more information, see Exporting Project Information.

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

  • Relational Database project icon
    Relational project
  • XML Project icon
    XML project
  • EIS project icon
    EIS project


Creating New Workbench Projects

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

To create a new Workbench project, use this procedure:

  1. New Project icon
    Click New on the toolbar and select Project. The Create New Workbench Project dialog box appears.You can also create a new project by choosing File > New > Project from the menu.
    Create New Workbench Project Dialog Box

    Create New Workbench Project Dialog Box

  2. Enter data in each field on the Create New Workbench Project dialog box, and then click OK.

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

Field Description
Name Enter the name of the 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 Introduction to 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 JCA adapter to use.See Introduction to 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 Introduction to XML Projects for more information.


For more project information, continue with the following:


How to Create a Project Using Java

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

  1. Implement a project class that extends the org.eclipse.persistence.sessions.Project class (see Specifying a EclipseLink Project in Code).
  2. Compile the project class.


Specifying a EclipseLink Project in Code

/**
* The class EmployeeProject is an example of an EclipseLink 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 org.eclipse.persistence.sessions.Project
*/
public class EmployeeProject extends org.eclipse.persistence.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 org.eclipse.persistence.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: Using Workbench provides a starting point for a custom project class. For more information, see How to Export Project Java Source Using Workbench.



Working with Projects

Using Workbench, you can perform the following project functions:

See Configuring a Project for additional information on working with Workbench projects.


How to Open Existing Projects

Use this procedure to open an existing project:

  1. Open Project button
    Click Open Project on the toolbar. The Choose a File dialog box appears. You can also open a project by choosing File > Open from the menu.

Note:The File menu option contains a list of recently opened projects. You can select one of these projects to open. See How to Use General Preferences for information on customizing this list.



See Also

#Working with Projects
Introduction to Projects


How to Save Projects

Workbench does not automatically save your project. Be sure to save your project often to avoid losing data.

To save your project(s), use this procedure:

  1. Save Selected Project button.
    Save All Projects button.
    Click Save or Save All to save your project(s).You can also save a project by choosing File > Save or File > Save All from the menu.
  2. If you close Workbench while there are currently unsaved changes, the Save Project dialog box appears.
    Save Projects Dialog Box
    Save Projects Dialog Box

  3. Select the project(s) to save and click OK.Click Select All to select all the available projects.

To save your project with a new name or location, see Saving Projects with a New Name or Location.


Saving Projects with a New Name or Location

To save your project with a different name or location, use this procedure:

  1. Save As button
    Choose File > Save As. The Save As dialog box appears.
    Save As Dialog Box
    Save As Dialog Box

  2. Select a name and location, then click Save.


Caution:Do not rename the .mwp file outside of Workbench. To rename a project, use the Save As option.



How to Generate the Project Status Report

Use the project status report to display a list of all warnings and errors in the Workbench project. This report is similar to the Problems window (see Using Workbench), but lets you easily copy and paste the errors into documents or messages. To generate the project status report, use this procedure:

  1. Project Status Report button
    Right-click the Problems label above the Problems window and select Problem Report. The Project Status Report dialog box appears, displaying the status of each Workbench project.You can also generate the project status report by selecting Tools > Problem Report from the menu.
    Problem Report Dialog Box
    Problem Report Dialog Box

See for information on each reported error.

To copy the report to another application, click Copy.

See Also

How to Generate the Project Status Report


Exporting Project Information

To use your project with the EclispeLink Foundation Library at run time, you must either generate deployment XML or export the project to Java source code.

For all project types, Workbench can generate and export the following project information:


Note:When exporting Java source and deployment XML, Workbench writes the database password (if applicable) using Java Cryptography Extension (JCE) encryption. For information on how to specify password encryption options, see Configuring Password Encryption.



How to Export Deployment XML Information Using Workbench

To export your deployment XML file (project.xml), use this procedure (see Creating EclipseLink Files for Deployment for detailed information):

  1. Export Deployment XML button
    Select the project and click Export Deployment XML.You can also right-click the project in the Navigator and choose Export > Project Deployment XML from the context menu or choose Selected > Export > Project Deployment XML from the menu.If you have not defined deployment and source code generation defaults (see Configuring a Project) Workbench prompts for a file name and directory.


Note: If your project contains errors, the project.xml may not be valid. See for information on each reported error.



How to Export Model Java Source Using Workbench

To generate the project model's Java source code, use this procedure:

  1. Right-click the project, package, or specific descriptor in the Navigator and choose Export > Export Model Java Source from the context menu. Workbench creates a .java file for each selected descriptor.You can also choose Workbench > Export > Export Model Java Source or Selected > Export > Model Java Source from the menu or click Generate Source Code on the Class tab. See Configuring Class Information for more information.
  2. Click Generate Source Code to generate the project's model Java source.

If you have not defined deployment and source code generation defaults (see Configuring a Project) Workbench prompts for a root directory.


Note: If your Workbench project uses UTF-8 character set, you must use a compatible JDK when compiling the exported Java source.


Back to the top