Previous Next
Designers Guide 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

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:

  1. On the menu, click Tools > Object-Relational Mapping (ORM) > Reverse Java Classes....
  2. Figure 5.1 - To reverse Java Classes

    The Reverse Java Classes dialog box is displayed.

    Figure 5.2 - Reverse Java Classes dialog
  3. 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.
  4. Figure 5.3 - The classes in the selected path are shown in the dialog
  5. Select the desired classes by using the list of buttons between the list of Available Classes and Selected Classes.
  6. Figure 5.4 - Select the classes for reverse
  7. Click OK. The selected classes are reverse engineered to class models which can be found under the Model tree.
  8. Figure 5.5 - The reversed classes model show in Model pane

     

To work on the reversed class models, simply add the reversed models to the class diagram:

 

  1. Create a new class diagram by using the New Class Diagram icon.
  2. Select the classes from the Model tree, drag the classes to the newly created class diagram.
  3. Figure 5.6 - Drag the classes to 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.

    Figure 5.7 - The reversed classes are shown on the Class Diagram

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:

  1. On the menu, click Tools > Object-Relational Mapping (ORM) > Reverse Hibernate....
  2. Figure 5.8 - Reverse Hibernat

    The Reverse Hibernate Model dialog box is displayed.

    Figure 5.9 - Reverse Hibernate Model dialog
  3. Select the path of the Hibernate xml files by using the button.
  4. 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.
  5. Figure 5.10 - Select the type of reverse engineering
  6. Click OK. The hibernate model are reverse engineered to class models and entities which can be found under the Model tree.
  7. Figure 5.11 - The reversed model is shown in Model pane

     

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.

 

  1. Create a new ORM diagram by using the New ORM Diagram icon.
  2. Add the reversed classes to the ORM diagram by dragging the class models from the Model tree to the ORM diagram.
  3. Figure 5.12 - Drag the Class Model to ORM Diagram
  4. Drag the entities from the Model tree to the ORM diagram to add the entities to the ORM diagram.
  5. Figure 5.13 - Drag the entities to ORM Diagram
  6. Right-click the ORM diagram, select View > Attribute Mapping from the pop-up menu.
  7. Figure 5.14 - Switch to Attribute mapping view

    The mapping between the attributes of class models and columns of entities are shown.

    Figure 5.15 - ORM Diagram in attribute mapping view

     

You can also check the reversed engineered database connection by the following steps:

 

  1. Click the Database Configuration icon, to open the Database Configuration dialog box.
  2. Figure 5.16 - Database Configuration dialog
  3. Select the connected database from the Database Configuration dialog box, the Database Setting is shown which shows the database configuration has been reversed successfully.
  4. Figure 5.17 - The database configuration 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.

Figure 5.18 - ORM Pane

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.

  1. Select the Class View of the ORM pane.
  2. Click the Classpath Configuration icon.
  3. Figure 5.19 - To open the classpath configuration

    The Select Classpaths dialog box is displayed.

    Figure 5.20 - Select Classpaths dialog
  4. Click Add... button to select the desired classpath.
  5. Figure 5.21 - Added classpath to the dialog

    All the available classes found from the specified classpath(s) are transformed and shown on the ORM pane.

    Figure 5.22 - The classes in the classpath will shown in ORM pane
  6. Create a new class diagram by using the New Class Diagram icon.
  7. Select the desired classes and drag to the class diagram.
  8. Figure 5.23 - Drag the classes to Class Diagram

    The classes are added to the class diagram such that you can further develop the model by using the visual modeling feature.

    Figure 5.24 - The reversed classes shown in Class Diagram

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.

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.

Figure 5.26 - Select the language of the project

Step 2: Database Configuration

You can configure the database connection for the desired database to be reversed.

  1. 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.
  2. Figure 5.27 - Database Configuration
  3. Click Next>, go to Step 3 of Reverse Database.

Step 3: Selecting Tables

All the available tables found from the connected database are listed.

  1. Select the tables that you want to reverse to Data Model.
  2. Click Finish.
  3. Figure 5.28 - The available tables in the database

     

An Entity Relationship Diagram is automatically generated and displayed. It can be found under the Diagram Navigator.

 

Figure 5.29 - The reversed ERD

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.

Figure 5.30 - ORM Pane

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.

  1. Select the Database View of the ORM pane.
  2. Figure 5.31 - Switch to Database View
  3. Click the Database Configuration icon.
  4. Figure 5.32 - To open the Database Configuration

    The Database Configuration dialog box is displayed.

    Figure 5.33 - Database Configuration dialog
  5. 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.
  6. Figure 5.34 - The reversed entity shown in ORM Pane
  7. Create a new entity relationship diagram by using the New Entity Relationship Diagram icon.
  8. Select the desired entities from the ORM pane, drag to the entity relationship diagram.
  9. Figure 5.35 - Drag the entities to ERD

The selected entities are added to the class diagram allowing you alter the database schema by visual modeling.


Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com