Chapter 5 - Reverse Engineering Classes and Databases
Chapter 5 - Reverse Engineering Classes and Databases
DB Visual ARCHITECT (DB-VA) allows you not only to reverse engineer the existing classes, including Java classes and Hibernate models into object models, but also to reverse engineer the existing database into data models. This chapter shows you how to reverse engineer the existing classes and database by the reverse facility and the ORM pane.
In this chapter:
- Introduction
- Reverse Engineering Classes
- Reverse Engineering Database
- Using ORM Pane for Reverse Engineering
Introduction
Apart from generating persistent classes and database, DB-VA also supports reverse engineering the existing classes and database into object models and data models respectively.
By supporting reverse engineering, object and data models will be generated which assists you in re-designing the application by visual modeling. The following sections show you how to reverse engineer existing classes and database to object and data models respectively.
Reverse Engineering Classes
DB-VA allows you to reverse engineer the existing classes, including Java classes and Hibernate models into object models. The reversed object models are stereotyped with ORM-Persistable. You can thus further model your application with the reversed models and generate the persistent classes and persistence layer after modification.
Reverse Engineering Java Classes to Object Model
DB-VA allows you to reverse engineer the Java classes into object model with ORM-Persistable stereotyped.
To reverse engineer Java classes:
- On the menu, click Tools > Object-Relational Mapping (ORM) > Reverse Java Classes....
The Reverse Java Classes dialog box is displayed.
- Click Add... to select the classpath of the Java classes to be reversed. The classpath can be a folder, zip file or jar file. After finished selecting the classpath, the classpath is added to the list of Select Classpaths, and the classes identified from the classpath are shown in the list of Available Classes.
- Select the desired classes by using the list of buttons between the list of Available Classes and Selected Classes.
- Click OK. The selected classes are reverse engineered to class models which can be found under the Model tree.
To work on the reversed class models, simply add the reversed models to the class diagram:
- Create a new class diagram by using the New Class Diagram icon.
- Select the classes from the Model tree, drag the classes to the newly created class diagram.
The classes are added to the class diagram accordingly. The classes shown on the class diagram are stereotyped as ORM Persistable; meaning that the Java classes are reversed engineered to ORM Persistable classes supporting the object relational mapping.
Reverse Engineering Hibernate Model to Object Model
DB-VA not only allows you to reverse engineer the Java classes, but also the hibernate model to object model with ORM-Persistable stereotyped. DB-VA also reverse engineer the database configuration as the database setting is defined in the hibernate model.
To reverse engineer Hibernate model:
- On the menu, click Tools > Object-Relational Mapping (ORM) > Reverse Hibernate....
The Reverse Hibernate Model dialog box is displayed.
- Select the path of the Hibernate xml files by using the
button.
- Select the type of reverse engineering to be performed from the drop-down menu of Reverse, either Configuration and Mapping, Configuration only or Mapping only.
- Click OK. The hibernate model are reverse engineered to class models and entities which can be found under the Model tree.
After reverse engineered the hibernate model, you can use an ORM diagram to view the mapping between the reversed classes and entities. For more information on ORM diagram, refer to the description of Showing Mapping between Object and Data Models by ORM Diagram section.
- Create a new ORM diagram by using the New ORM Diagram icon.
- Add the reversed classes to the ORM diagram by dragging the class models from the Model tree to the ORM diagram.
- Drag the entities from the Model tree to the ORM diagram to add the entities to the ORM diagram.
- Right-click the ORM diagram, select View > Attribute Mapping from the pop-up menu.
The mapping between the attributes of class models and columns of entities are shown.
You can also check the reversed engineered database connection by the following steps:
- Click the Database Configuration icon, to open the Database Configuration dialog box.
- Select the connected database from the Database Configuration dialog box, the Database Setting is shown which shows the database configuration has been reversed successfully.
Using ORM Pane
DB-VA provides you an ORM pane to generate persistent model and entity from an existing object model in Java classes and database respectively. Using the ORM pane, the existing object model and database will be transformed to ORM-Persistable class and entity; you can further develop the ORM-Persistable classes and entities by adding the desired classes and entities to the class diagram and entity relationship diagram respectively.
The ORM pane provides two views, including Class View and Database View. The class view allows you to transform the existing object model to class model while the database view allows you to transform the existing database to entity.
Reverse Engineering Java Classes by Class View
As the class view of the ORM pane supports the transformation of the existing object model into ORM-Persistable class, you are allowed to further your development based on the transformed object model.
- Select the Class View of the ORM pane.
- Click the Classpath Configuration icon.
The Select Classpaths dialog box is displayed.
- Click Add... button to select the desired classpath.
All the available classes found from the specified classpath(s) are transformed and shown on the ORM pane.
- Create a new class diagram by using the New Class Diagram icon.
- Select the desired classes and drag to the class diagram.
The classes are added to the class diagram such that you can further develop the model by using the visual modeling feature.
Reverse Engineering Relational Database
DB-VA supports reverse engineering the existing database to data models. As DB-VA automates object-relational mapping, object model can thus be generated from the data model reverse engineered from the existing database.
Using Reverse Database Facility
You can create an Entity Relationship Diagram by reverse engineering an existing relational database.
- On the menu, click Tools > Object-Relational Mapping (ORM) > Reverse Database....
The Database to Data Model dialog box is displayed.
Step 1: Select Language
Select the language of the project from the drop-down menu, either Java, C#, PHP or Enterprise Object Framework, and then click Next > to proceed to Step 2.
Step 2: Database Configuration
You can configure the database connection for the desired database to be reversed.
- You are asked to define the database configuration. To configure the database settings, refer to the descriptions of the Database Configuration section in the Working with DB Visual ARCHITECT chapter.
- Click Next>, go to Step 3 of Reverse Database.
Step 3: Selecting Tables
All the available tables found from the connected database are listed.
- Select the tables that you want to reverse to Data Model.
- Click Finish.
An Entity Relationship Diagram is automatically generated and displayed. It can be found under the Diagram Navigator.
Using ORM Pane
DB-VA provides you an ORM pane to generate persistent model and entity from an existing object model in Java classes and database respectively. Using the ORM pane, the existing object model and database will be transformed to ORM-Persistable class and entity; you can further develop the ORM-Persistable classes and entities by adding the desired classes and entities to the class diagram and entity relationship diagram respectively.
The ORM pane provides two views, including Class View and Database View. The class view allows you to transform the existing object model to class model while the database view allows you to transform the existing database to entity.
Reverse Engineering Database by Database View
As the database view of the ORM pane supports the transformation of the existing database into entity, you are allowed to alter the database schema by modeling with the entity relationship diagram and exporting to the existing database.
- Select the Database View of the ORM pane.
- Click the Database Configuration icon.
The Database Configuration dialog box is displayed.
- Configure the database connection by using the Database Configuration dialog box, refer to the descriptions of the Database Configuration section in the Working with DB Visual ARCHITECT chapter for more information. If the database is successfully connected, the tables of the connected database are transformed into entities and shown on the ORM pane.
- Create a new entity relationship diagram by using the New Entity Relationship Diagram icon.
- Select the desired entities from the ORM pane, drag to the entity relationship diagram.
The selected entities are added to the class diagram allowing you alter the database schema by visual modeling.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|