Database Modeling with ORM
Part 2: A thorough and accurate conceptual model significantly increases the chance of an application's success
Object Role Modeling (ORM) is an excellent modeling methodology that you can use to construct a conceptual database model. This article is the second in a series of articles that introduce ORM.
Object Role Modeling is an approach to describing data in terms of objects and the roles they play. An elementary fact is a statement affirming that an object has a property or participates in a relationship with one or more other objects. ORM expresses these elementary facts in a natural language that is easily understood and verifiable by the domain experts. In addition, ORM source modeling is supported by Microsoft and can be implemented using Visio for Enterprise Architects.
The focus of the first article in this series (.NETDJ, Vol.1, issue 10) was working with domain experts to identify the various object types and fact types that need to be included in a conceptual model. It introduced the various common types of predicate arities, as well as the use of Visio to construct an ORM source model. This article continues the study of ORM source modeling using Visio. The process of developing a database model is iterative and involves the continual refinement and verification of the various fact types and object types that make up the model. This article introduces some of the concepts involved in the refinement process. It focuses on the concepts of primitive entity types, subtypes, derived fact types, and unique constraints. In addition, this article covers the process of using Visio to incorporate the concepts into an ORM model.
Primitive Entity Types, Subtypes, and Derived Fact Types
As you develop the database model using ORM you need to continually refine and verify the model. One of the tasks of model refinement is to ensure that the entity types defined in the model are in primitive form. Primitive entity types are mutually exclusive, which means the populations of the entity types do not overlap. As an example, you may be tempted to model the fact type verbalizations "a class begins at start time" and "a class is over at end time," as shown in Figure 1. In reality, the entity types "start time" and "end time" are not mutually exclusive. The primitive entity type "time" plays both roles, "start time" and "end time", in these fact types. Figure 2 shows the updated representation of the fact types.
As you examine your database model you may find that some of the entity types have common characteristics or that a fact type needs to be expanded to include similar entity types. For example, the fact type "a parking permit is issued for a car" is examined, and it is determined that this needs to be expanded to include motorcycles. Cars and motorcycles share many common characteristics. An atomic primitive entity type "vehicle" becomes a supertype in the model. The entity types "car" and "vehicle" become subtypes of the "vehicle" primitive entity type. Figure 3 demonstrates how subtypes are modeled using ORM. A solid arrow connects the subtype to the primitive entity supertype pointing toward the supertype.
In the initial stages of your database design, you may have identified entity types that are not primitive entity types but rather are the result of a derivation from primitive entity types. As an example, consider the fact type "class lasts for duration". You may be tempted to model the role "duration" as a primitive entity type. In reality, the fact type "class lasts for duration" is a derived fact type. It derives from the role "time" in the fact types "class begins at time" and "class ends at time". Figure 4 shows the ORM representation of the derived fact type "class lasts for duration". The asterisk appended to the predicate shape indicates that "duration" is a derived (through a query) entity type.
Modeling Subtypes and Derived Fact Types in Visio
The following activity demonstrates adding subtypes and derived fact types to a Visio ORM model. Note: You need Visio for Enterprise Architects in order to create an ORM source model.
Modeling Subtypes:
- Start up Visio. From the File menu, choose New > Database > ORM Source Model.
- If the Business Rules Editor (see Figure 5) is not visible at the bottom of the window, choose View > Business Rules from the Database menu.
- Double-click the first Object Type cell in the Business Rules Editor. Create a Vehicle entity object type. Repeat this procedure to create Car, Motorcycle, and Parking Permit entity object types. Note: Do not worry about the Physical Data or Reference Mode at this time.
- Select the Fact Types tab at the bottom of the Business Rules Editor. Press the F2 key to launch the Fact Editor window. Using the left Object dropdown list, choose Parking Permit. In the relationship text box enter "is issued for". Choose Vehicle from the right object dropdown list. Figure 6 shows the completed entries. Notice that the bottom of the widow contains the natural language syntax expression of the fact type. This natural language syntax plays an important role in verifying the model with the domain experts. Click OK to save the fact type and close the window.
- Click and drag the fact type from the Business Rules Editor onto the drawing surface. Drag the Car and Motorcycle object types onto the design surface and arrange them to the right of the Vehicle object type.
- From the object toolbox window, drag a Subtype Relationship arrow to the design surface. Attach the tail to the Car object type and the head to the Vehicle object type. Repeat this procedure to connect the Motorcycle object type to the Vehicle object type. The completed diagram should resemble Figure 3.
- Select the Car object type in the diagram. In the Business Rules Editor select the Data Base properties tab. Select Subtype from the Categories dropdown list. Notice that the Vehicle Object type is designated as the Primary supertype (see Figure 7).
Modeling a Derived Fact Type:
- Using the Business Rules Editor, create a class entity object type, a Time value type, and a Duration value type. Note: Do not worry about the Physical Data or Reference Mode at this time.
- Using the Fact Editor, create "Class starts at Time", "Class ends at Time", and "Class lasts for Duration" fact types.
- Click and drag the fact types from the business rules editor onto the drawing surface.
- Right-click the "starts at" predicate phrase on the design surface and choose Database Properties in the pop-up menu. In the Database Properties Editor, select Readings in the Categories list. Enter a role name of "StartTime" in the Role name text box (see Figure 8). Repeat this procedure to add a Role name of "EndTime" for the "ends at" predicate phrase.
- Right-click the "lasts for" predicate phrase on the design surface and choose Database Properties from the pop-up menu. In the Database Properties Editor, select Derived in the Categories list. Click on the Derived option button and enter a rule definition of "Class.EndTime – Class.StartTime" in the Rule text box (see Figure 9). Notice that an asterisk is appended to the predicate phrase on the design surface. The completed diagram should look similar to Figure 4.
Identifying Constraints
Enforcement of constraints is fundamental to designing the structure of relational data. Constraints limit the involvement of roles within the defined predicates. Remember that predicates are verb phrases defining the relationships between the various roles defined in the model. If you are designing a database system to track students enrolled at a computer-training center, a valid fact type could be "a student has a last name".
In addition to defining the fact type, you often need to define conditions for the fact type. These conditions usually take the form of constraints. For example, if you want to ensure that every student has a last name recorded, you need to define a mandatory constraint on the student role. Placing a solid dot on the role connector line in the ORM diagram indicates that the role is mandatory. The fact type verbalization changes to "each student has a last name", where the word "each" indicates the mandatory constraint. By examining the supporting data documents of the student tracking system you find that not only must each student have a last name, but each student can have only one last name. Placing an arrow above the last name role box in the predicate phrase restricts each student to having only one last name. Figure 10 shows the ORM visualization of the previous fact type with the unique constraint added.
In some instances a unique constraint spans two or more roles defined in the predicate. For example, a student can enroll in multiple classes and a class contains multiple students, but the same student cannot enroll in the same class more than once. This constrains the combination of student and class as unique. Figure 11 demonstrates the visualization of this type of constraint. Figure 12 shows a separate line drawn above each role in the predicate phrase. In this case, each student is associated with zero or one vehicle, and each vehicle is associated with exactly one student. Compare this with the constraint shown in Figure 10, which constrains each student to have only one last name but allows several students to have the same last name. The examples covered thus far have been for binary fact types. Figure 13 demonstrates the same types of constraints applied to a ternary fact type as well. In this case a unique constraint spans the room role and time role. In other words, two different classes cannot occupy the same room at the same time. A unique constraint also applies to the time and class roles. This restricts two different instances of the same class from occurring at the same time.
Using Visio to Add Constraints to the ORM Model
Follow these steps to add constraints to a Visio ORM model.
- Start up Visio. From the File menu, choose New > Database > ORM Source Model.
- If the Business Rules Editor (see Figure 5) is not visible at the bottom of the window, from the Database menu choose View > Business Rules.
- Double-click the first Object Type cell in the Business Rules Editor. Create Class, Student, and Room entity object types. Also create a Time value object type. Note: Don't worry about the Physical Data or Reference Mode at this time.
- Select the Fact Types tab at the bottom of the Business Rules Editor. Press the F2 key to launch the Fact Editor window. Choose Student from the left Object dropdown list. In the relationship text box enter "attends". Choose Class from the right object dropdown list.
- Click on the Constraints tab in the Fact Editor. Experiment with the various selections in the righthand constraint dropdowns. Notice how the various selections alter the fact type diagram and the verbalization at the bottom of the editor. After experimenting, choose the selections as shown in Figure 14, and click OK.
- Select the Fact Types tab at the bottom of the Business Rules Editor. Press the F2 key to launch the Fact Editor window. In the input style section, select the Guided option and choose Ternary from the dropdown list. Choose Class from the left Object dropdown list. In the relationship text box, enter "occurs at". Choose Time from the right object dropdown list. In the second row relationship text box enter "in". Choose Room from the object dropdown list.
- Click on the Constraints tab in the Fact Editor. Experiment with the various constraint selections. Notice how the various selections alter the fact type diagram and the verbalization at the bottom of the editor. After experimenting, choose the options as shown in Figure 15, and click OK.
Conclusion
ORM is an excellent aid for modeling the data and data relations that will comprise the back-end database structure of your application. The real strength of ORM is its ability to extract the business data requirements from the domain experts into a conceptual model that is easily understood and verifiable by those same domain experts. By spending time creating a thorough and accurate conceptual model, an application's chance of success as it progresses to the logical and physical stages significantly increases.
The process of developing the database model involves the refinement and verification of the various fact types and object types that make up the model. This article introduced some of the concepts involved in the refinement process. It focused on the concepts of primitive entity types, subtypes, derived fact types, and unique constraints. In addition, this article covered the process of using Visio to incorporate the concepts into an ORM model. A future article will continue the study of ORM source modeling using Visio. It will cover additional types of constraints commonly enforced in many database models. In addition, it will examine the process of verifying the ORM model with the domain experts using the fact verbalizer and population checks.
Author Bio
Dan Clark is the chief enterprise architect at Intellimark, a full-service IT consulting company located in Mechanicsburg, Pennsylvania. He is a Microsoft Certified Trainer, Microsoft Certified Solution Developer, Microsoft Certified Database Administrator, and a Microsoft Most Valuable Professional. Dan is also the author of An Introduction to Object-Oriented Programming with Visual Basic .NET, published by Apress.
drc_books@yahoo.com
All Rights Reserved
Copyright © 2004 SYS-CON Media, Inc.
E-mail:
info@sys-con.com