TOC Special:Whatlinkshere_Creating_a_Project_(ELUG)[Related Topics]
This section describes how to create EclipseLink projects. For information on the various types of projects available, see EclipseLink Project Types.
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.
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.
When you create a project using the 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 the Workbench, you can export this information as an 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.
The 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. The Workbench supports the following project types:
This section includes information on creating a new Workbench project. To create a new project from an existing persistence application, 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:
-
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._ [Figure 112-1]# Create New Workbench Project Dialog Box_
-
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 a relational project to a relational database. Use the Platform list to select the specific database platform.
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.
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).
For more project information, continue with the following:
-
Add mappings and descriptors (see Introduction to Descriptors and Introduction to Mappings).
To create a project using Java code, use this procedure:
-
Implement a project class that extends the
org.eclipse.persistence.sessions.Project
class (see the Specifying an EclipseLink Project in Code example). -
Compile the project class.
[Example 112-1]# Specifying an 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. |
Using Workbench, you can perform the following project functions:
See Configuring a Project for additional information on working with Workbench projects.
Use this procedure to open an existing project:
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
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:
-
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.
-
If you close Workbench while there are currently unsaved changes, the Save Project dialog box appears. [Figure 112-3]#Save Projects Dialog Box
-
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.
To save your project with a different name or location, use this procedure:
Caution:Do not rename the |
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:
-
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. [Figure 112-5]#Problem Report Dialog Box
-
See EclipseLink Workbench Error Reference (ELUG) for information on each reported error.
-
To copy the report to another application, click Copy.
To use your project with the EclipseLink 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:
-
Deployment information (see How to Export Deployment XML Information Using Workbench) (
project.xml
file) -
Model Java source (see ow to Export Model Java Source Using Workbench)
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. |
To export your deployment XML file (project.xml
), use this procedure
(see
Creating
EclipseLink Files for Deployment for detailed information):
-
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 |
To generate the project model’s Java source code, use this procedure:
-
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. -
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. |
Category:_EclipseLink_User’s_Guide[Category: EclipseLink User’s Guide] Category:_Release_1[Category: Release 1] Category:_Task[Category: Task]