|
An ORM Wizard is provided to you to generate persistent code and/or database either from database, class diagram or entity relationship diagrams. This chapter shows you how to activate the ORM Wizard and generate code and/or database by one of the three options provided by wizard.
In this chapter:
Mapping objects to relational database is a complicated and error pound task in the development. Acting as a bridge between object model, data model and relational database, the mappings between these models are automated. Apart from these mappings, the mapping between object models and persistent code is also supported. Hence, the persistent code can thus map to the relational database.
The synchronization between persistent code, object model, data model and relational is supported, which reduces the development time for handling these tedious programming jobs between them. Moreover, your document will always keep up-to-date. To support synchronization in-between persistent code and relational database, you are allowed to generate database and persistent code for your development project.
An ORM Wizard for the generation of persistent code and database. The wizard provides you with three options:
To activate the Wizard:
![]() |
|---|
| Figure 13.1 - To start the ORM Wizard |
For other SDE:
| SDE | Method |
|---|---|
| SDE for JBuilder | On the menu, click Tools > Modeling > ORM > Wizards.... |
| SDE for NetBeans | On the menu, click Modeling > ORM > Wizards.... |
| SDE for IntelliJ IDEA | On the menu, click Modeling > ORM > Wizards.... |
| SDE for JDeveloper | On the menu, click Model > ORM > Wizards.... |
| SDE for WebLogic Workshop | On the menu, click Modeling > ORM > Wizards.... |
![]() |
|---|
| Figure 13.2 - Select the programming language |
![]() |
|---|
| Figure 13.3 - Select the generate options |
![]() |
|---|
| Figure 13.4 - The workflow of generate code from database |
Upon selecting the option for Generate Code from Database, the wizard helps you generate persistent code from database tables according to the requirements you specified throughout the wizard.
Follow the steps of the Generate Code From Database wizard:
![]() |
|---|
| Figure 13.5 - Database Configuration for Java |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information chapter for information on how to configure the database Database Configuration for Java Project section.
![]() |
|---|
| Figure 13.6 - Database Configuration for C# |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for .Net Project section.
![]() |
|---|
| Figure 13.7 - Select the Tables |
The database is connected based on your options in the previous database configuration option pane and all database tables are reversed. You are asked to select the database tables which you want to generate persistent class to manipulate those tables. By default, all the database tables are selected for the generation of code shown in the list of Selected Tables. You can deselect the table by using the list of buttons between the list of Available Tables and Selected Tables.
Add the selected table from Available Tables to Selected Tables.
Remove the selected table from Selected Tables to Available Tables.
Add all tables from Available Tables to Selected Tables.
Remove all tables from Selected Tables to Available Tables.
![]() |
|---|
| Figure 13.8 - Class Detail Configuration |
After selecting tables, you will be directed to a Class Details Configuration pane. You are asked to define the Class Detail for generating code. The persistent classes will be generated based on the information defined here. You can edit the class details by double-clicking the field.
Enter the package name. A package will be created to store the generated persistent code. If the package name was not defined, you will be prompted by a dialog box warning you the classes will be generated in default package.
![]() |
|---|
| Figure 13.9 - Confirm generate code in default package |
You can edit the class name which will be used as the name of the generated persistent code for a corresponding table.
![]() |
|---|
| Figure 13.10 - Mapping classes |
You can edit the role name for a reference in the class.
![]() |
|---|
| Figure 13.11 - Mapping association |
You can deselect navigable for an association such that the reference for the target role will not be created.
![]() |
|---|
| Figure 13.12 - Edit the navigable of association |
You can edit the attribute name representing the column of the table.
![]() |
|---|
| Figure 13.13 - Mapping attributes |
Click
button, Custom Code Style Setting dialog box will be displayed. You can modify the prefix or suffix of the Class, Attribute and Role Name.
![]() |
|---|
| Figure 13.14 - Customer Code Style Setting dialog |
For the Type, select the type of Class detail, either Class, Attribute or Role Name (PK) that you want to apply code style.
For the Prefix/Suffix, select either Prefix or Suffix to be added or removed.
For the Add/Remove option, select the option for the action of code style to be applied.
For the Textbox, enter the word for either prefix or suffix.
For the Scope, select the scope of the code style to be applied to, either All or Selected.
Table shows the result of applying Code Style.
| Code Style | Before Applying | After Applying |
|---|---|---|
| Add Prefix (E.g. pre_) | Item | pre_Item |
| Remove Prefix (E.g. pre_) | pre_Item | Item |
| Add Suffix (E.g. _suf) | Item | Item_suf |
| Remove (E.g. _suf) | Item_suf | Item |
![]() |
|---|
| Figure 13.15 - Generate Java Code Setting |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for Java section in the Implementation chapter.
![]() |
|---|
| Figure 13.16 - Generate Code Setting for C# |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for C# section in the Implementation chapter.
![]() |
|---|
| Figure 13.17 - Generate ORM Code/Database dialog |
A class diagram and an entity relationship diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path.
![]() |
|---|
| Figure 13.18 - Generate code and database from ERD |
Upon selecting the option for Generate Code and Database from ERD, the wizard helps you generate persistent code and database from ERD with respect to the requirements you specified throughout the wizard.
Take the following ERD as an example:
![]() |
|---|
| Figure 13.19 - Entity Relationship Diagram (ERD) |
Follow the steps of the Generate Code and Database From ERD wizard:
![]() |
|---|
| Figure 13.20 - Class Details Configuration |
You are asked to define the Class Details for generating code. The persistent classes will be generated based on the information defined here. You can edit the class details by double-clicking the field.
Enter the package name. A package will be created to store the generated persistent code. If the package name was not defined, you will be prompted by a dialog box warning you the classes will be generated in default package.
![]() |
|---|
| Figure 13.21 - Confirm generate code in default package |
You can edit the class name which will be used as the name of the generated persistent code for a corresponding table.
![]() |
|---|
| Figure 13.22 - Mapping classes |
You can edit the role name for a reference in the class.
![]() |
|---|
| Figure 13.23 - Mapping associations |
You can deselect navigable for an association such that the reference for the target role will not be created.
![]() |
|---|
| Figure 13.34 - Select the navigable of associations |
You can edit the attribute name representing the column of the table.
![]() |
|---|
| Figure 13.35 - Mapping attributes |
Click
button, Custom Code Style Setting dialog box will be displayed. You can modify the prefix or suffix of the Class, Attribute and Role Name.
![]() |
|---|
| Figure 13.36 - Custom Code Style Setting dialog |
For the Type, select the type of Class detail, either Class, Attribute or Role Name (PK) that you want to apply code style.
For the Prefix/Suffix, select either Prefix or Suffix to be added or removed.
For the Add/Remove option, select the option for the action of code style to be applied.
For the Textbox, enter the word for either prefix or suffix.
For the Scope, select the scope of the code style to be applied to, either All or Selected.
Table shows the result of applying Code Style.
| Code Style | Before Applying | After Applying |
|---|---|---|
| Add Prefix (E.g. pre_) | Item | pre_Item |
| Remove Prefix (E.g. pre_) | pre_Item | Item |
| Add Suffix (E.g. _suf) | Item | Item_suf |
| Remove (E.g. _suf) | Item_suf | Item |
![]() |
|---|
| Figure 13.37 - Database configuration for Java |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for Java Project section.
![]() |
|---|
| Figure 13.38 - Database configuration for C# |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for .Net Project section.
![]() |
|---|
| Figure 13.39 - Generate code options for Java |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for Java section in the Implementation chapter.
![]() |
|---|
| Figure 13.40 - Generate code options for C# |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for C# section in the Implementation chapter.
![]() |
|---|
| Figure 13.41 - Generate ORM Code/Database dialog |
A class diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path and the generated database will be set up to the specified database configuration.
![]() |
|---|
| Figure 13.42 -Generate Code and Database from Class Diagram |
Upon selecting the option for Generate Code from Class Diagram, the wizard helps you generate persistent code and database from class diagram with respect to the requirements you specified throughout the wizard.
Take the following class diagram as an example:
![]() |
|---|
| Figure 13.43 - Class Diagram |
Follow the steps of the Generate Code and Database from Class Diagram wizard:
![]() |
|---|
| Figure 13.44 - Select the ORM Persistable Classes |
You are asked to select the classes on the class diagram which you want to generate persistent class to manipulate persistent data. By default, all the classes stereotyped as ORM-Persistable on the class diagram are selected for the generation of code and database shown in the list of Persistable Classes. You can deselect the persistable classes by using the list of buttons between the list of Non Persistable Classes and Persistable Classes.
Add the selected class from Non Persistable Classes to Persistable Classes.
Remove the selected class from Persistable Classes to Non Persistable Classes.
Add all classes from Non Persistable Classes to Persistable Classes.
Remove all classes from Persistable Classes to Non Persistable Classes.
| For the classes shown in the list of Persistable Classes, they will be stereotyped as ORM-Persistable on the class diagram after the wizard is finished. Meanwhile, for the classes shown in the list of Non Persistable Classes, they will not be stereotyped on the class diagram after the wizard is finished. |
![]() |
|---|
| Figure 13.45 - Select the primary key |
You are asked to select the primary key for each class being mapped to data model and relational database. You can either select an attribute as the primary key or let SDE generate the primary key automatically by using the drop-down menu. For more information, refer to the description of Mapping Primary key in the section of Mapping an Object Model to a Data Model in the Object Model chapter.
![]() |
|---|
| Figure 13.46 - Table Details Configuration |
You are asked to define the Table Details for generating database and code. The database and persistent classes will be generated based on the information defined here. You can edit the table details by double-clicking the field.
Enter the package name. A package will be created to store the generated persistent code. If the package name was not defined, you will be prompted by a dialog box warning you the classes will be generated in default package.
![]() |
|---|
| Figure 13.47 - Confirm generate classes in default package |
You can edit the table name which will be used as the name of the generated database table.
You can edit the column name represented by the class.
![]() |
|---|
| Figure 13.48 - Mapping columns |
Click
button, Custom Code Style Setting dialog box will be displayed. You can modify the prefix or suffix of the Table, Column, Primary Key and Foreign Key.
![]() |
|---|
| Figure 13.49 - Custom Code Style Setting |
For the Type, select the type of Table detail, either Table, Column, Primary Key or Foreign Key that you want to apply code style.
For the Prefix/Suffix, select either Prefix or Suffix to be added or removed.
For the Add/Remove option, select the option for the action of code style to be applied.
For the Textbox, enter the word for either prefix or suffix.
For the Scope, select the scope of the code style to be applied to, either All or Selected.
Table shows the result of applying Code Style.
| Code Style | Before Applying | After Applying |
|---|---|---|
| Add Prefix (E.g. pre_) | Item | pre_Item |
| Remove Prefix (E.g. pre_) | pre_Item | Item |
| Add Suffix (E.g. _suf) | Item | Item_suf |
| Remove (E.g. _suf) | Item_suf | Item |
![]() |
|---|
| Figure 13.50 - Database Configuration for Java |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for Java Project section
![]() |
|---|
| Figure 13.51 - Database configuration for C# |
You are asked to define the database configuration. Refer to the descriptions in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for .Net Project section.
![]() |
|---|
| Figure 13.52 - Generate code options for Java |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for Java section in the Implementation chapter.
![]() |
|---|
| Figure 13.53 - Genreate code options for C# |
You are asked to specify the code details. For information, refer to the description of Configuring Code Generation Setting for C# section in the Implementation chapter.
| Wizard for Generate Code and Database from Class Diagram option provides an option of generating code to you. By default, the Generate Code option is selected. If you do not want to generate code from class diagram, please deselect the Generate Code option. In this case, only database will be generated while persistent code will not be generated. |
![]() |
|---|
| Figure 13.54 - Generate ORM Code/Database dialog |
An entity relationship diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path and the generated database will be set up to the specified database configuration.
|
|
|||||||