Dbva Designer Guide Chapter4
Dbva Designer Guide Chapter4
Introduction
An entity is an object in the business or system with well-defined characteristics which are represented by columns showing what information can be stored. In relational databases, an entity refers to a record structure, i.e. table. A data model provides the lower-level detail of a relational database of an application. It shows the physical database models and their relationships in an application. An entity relationship diagram can be used to describe the entities inside a system and their relationships with each other; the entity relationship diagram is also known as a data model. DB-VA supports visual modeling for data models, not only by creating a new data model, but also by transforming from an object model. As DB-VA automates object-relational mapping, DB-VA supports the generation of database, code and persistence layer for Java model API and .NET model API, which in turn streamlines the model-code-deploy software development process.
4-2
On the Diagram Navigator, right-click Entity Relationship Diagram > Create Entity Relationship Diagram.
Figure 4.2 - Create ERD by click on Diagram Navigator On the toolbar, click the New Entity Relationship Diagram icon.
Adding Entity
1. On the diagram toolbar, click the Entity shape icon.
Figure 4.3 - Create an Entity by using the Entity icon 2. Click a location in the diagram pane. DB-VA places an icon representing the entity element on the diagram. 3. Type a name for the Entity element. You can edit the name by double-clicking the name or by pressing the F2 button.
4-3
Figure 4.5 - Open specification by click on popup menu Entity Specification dialog box is displayed, you can modify the entity properties and constraints.
Adding Column
You can add a new column to the entity in one of the three ways: Right-click on an entity, select New Column.
Figure 4.7 - Add column by click on popup menu A new column is added, type the column name and type in the form of "column_name: type". You can also edit the column name by double-clicking the column name or by pressing the F2 button. Click on an entity, press the keyboard shortcut - Alt + Shift + C. Add column in Entity Specification dialog: 1. Right-click the entity element, click Open Specification. 2. Click the Columns tab, then click Add.
4-4
Column Specification dialog box is displayed, you can modify the column name and properties, such as type.
Figure 4.9 - To open the column specification The Column Specification dialog box is displayed, you can modify the column properties.
4-5
Adding Relationship
Relationship shows how the entities are related to each other. You can add a relationship to the entities in one of the two ways: Using Resource-Centric Interface 1. Click on an entity, a group of valid editing resources is displayed around the shape. 2. Mouse over the resource, select the desired resource, such as "One-to-One Relationship - > Entity".
Figure 4.11 - "One-to-one Relationship -> Entity" resource 3. Drag the resource to the related entity.
Figure 4.12 - Drag the resource to the related entity Using Toolbar icon 1. On the diagram toolbar, click the Relationship icon. 2. One-to-One Relationship One-to-Many Relationship
4-6
4-7
Figure 4.16 - Synchronize to ERD by click on popup menu On the class diagram, hold down the right-mouse button, move the mouse from left to right to form the gesture. A blue path is shown indicating the gesture.
Figure 4.17 - Synchronize to ERD by using Gesture An entity relationship diagram is generated and can be found under the Diagram Navigator.
4-8
Figure 4.19 - Entity Specification dialog Specify Primary Key in Column Specification dialog: 1. Right-click the column, click Open Specification... to open the Column Specification dialog box. 2. Check the Include in primary key option.
Note
If you assign a primary key to a column of an entity, DB-VA will automatically add a foreign key column to the related entities.
Figure 4.22 - Open relationship specification Relationship Specification dialog box is displayed. 2. 3. Check the option for Ordered. Select the index column from the drop-down menu of Index column, click OK.
Note
You can select Create Column from the drop-down menu to create a new index column for sorting.
4-10
Figure 4.24 - Open the column specification Column Specification of the primary key is displayed. 2. Select the ID generator from the drop-down menu of ID Generator, click OK to confirm setting.
Note
If the ID Generator is specified as either sequence, seqhilo or hilo, you have to enter the key for the sequence/table name.
Defining Discriminator
In generalization, the superclass distributes its commonalities to a group of similar subclasses. The subclass inherits all superclasss attributes and it may contain specific attributes. DB-VA combines the entities within the hierarchy into one single entity containing all the attributes and a discriminator column for using table per class hierarchy as the inheritance strategy. The discriminator contains a unique value which is used for identifying the entity which hierarchy it belongs to. DB-VA allows you to define the discriminator in the entity and the discriminator value in the classes.
4-11
Figure 4.26 - Create a column 2. Enter the name and type for the discriminator in the form of "discriminator_name: type".
Figure 4.27 - Enter the column name and data type 3. Right-click on the entity, select Open Specification....
Figure 4.28 - Open the column specification Entity Specification dialog box is displayed. 4. Select the desired column from the drop-down menu of Discriminator Column, click OK to confirm setting.
4-12
Figure 4.30 - Open the ORM Class Detail 2. Enter the discriminator value for identifying the sub-class.
4-13
Figure 4.32 - Entities with One-to-many relationship In the above case, the phonebook has a contact entry for each contact person. Each contact person may have more than one phone numbers. A one-to-many relationship between contact entry and contact phone can be built. 2. Right-click on the entity for the data column with cardinality of many, select Convert to Array Table from the popup menu.
Figure 4.33 - Convert to Array Table 3. A warning message will be displayed, showing that the listed constraints are not satisfied for converting to array table. Click Yes to let DB-VA to resolve the constraints automatically. Click No to cancel the conversion to array table.
Figure 4.34 - Warning message for no index column The conversion to Array Table is completed and the entity for the data column is stereotyped as Array Table.
4-14
Figure 4.36 - Add an attribute by click on popup menu 2. Enter the name and type for the attribute in the form of "attribute_name :type[]", the sign, "[ ]" indicates the attribute is an array.
Figure 4.37 - Enter the attribute name and data types Using Class Specification dialog box 1. Right-click on a class, click Open Specification.
Figure 4.38 - Open the class specification 1. The Class Specification dialog box is displayed Click Attribute Tab, click Add. Attribute Specification is displayed.
4-15
2.
Enter attribute name and type, select [] from the drop-down menu of Type modifier, then click OK to confirm setting.
Splitting Table
You can split an entity into two associated with a one-to-one identifying relationship. 1. You can activate the Split Table dialog box in one of the two ways: Using Pop-up Menu 1. Right-click an entity, select Split Table.
4-16
Using Resource-Centric Interface 1. Click on an entity, a group of valid editing resources are displayed around the entity. 2. Click the resource of "One-to-One Relationship - > Partial Table".
Figure 4.41 - Click on "One-to-one Relationship -> Partial Table" resource 2. Split Table dialog box is displayed.
Figure 4.42 - Split Table dialog 3. Edit the New Partial Table Name, select the columns from the list of Original to Partial, and click OK. An entity stereotyped as <<Partial>> is created.
4-17
Figure 4.46 - To open the Database Configuration Database Configuration dialog box will be displayed. To configure the database, refer to the descriptions of the Database Configuration section in the Working with DB Visual ARCHITECT chapter for more information. Note
In DB-VA for IDE, you are allowed to configure the database connection by using Modeling > ORM > Database Configuration to display the Database Configuration dialog box.
Note
DB-VA will only provide you the function of copying SQL if the default database connection is set.
Note
If there are multiple database settings, DB-VA will generate SQL statements for all these database servers.
Example: There are two database settings selected in the DB-VA environment.
4-18
2.
Right-click on the ERD, select Generate SQL... from the pop-up menu.
Figure 4.48 - Select generate SQL in popup menu 3. Generate SQL dialog box is displayed, select the database server from the drop-down menu of Database, the corresponding SQL statements will be displayed accordingly.
Figure 4.49 - Generate SQL dialog You are allowed to copy the SQL statements from the Generate SQL dialog box. Note
You can select Create Table(s), Drop Table(s), Select, Insert, Update and Delete from the Generate SQL dialog to directly copy the SQL statements to clipboard.
4-19
4-20
Multiple entities and connection lines on the ERD 1. Select several entities and relationships on the ERD, right-click on the diagram pane, select Copy SQL from the pop-up menu. As generate SQL with specifying a particular scope, SQL statements will be generated only for the components included in the specified scope. Example:
Figure 4.52 - Generate SQL for selected entities Connection lines on the ERD 1. Select connection line, right-click on the diagram pane, select Generate SQL... from the pop-up menu. As Generate SQL... with connection lines, SQL statements for Create Constraint(s) and Drop Constraints(s) will be generated. Example:
Figure 4.53 - Generate connection line's constraint Create Constraint : Drop Constraint :
alter table 'OrderLine' add index 'FK_OrderLine_1969' ('PurchaseOrderPO_NO'), add constraint 'FK_OrderLine_1969' foreign key ('PurchaseOrderPO_NO') references 'PurchaseOrder' ('PO_NO'); alter table 'OrderLine' drop foreign key 'FK_OrderLine_1969';
4-21
4-22