Defining the Domain Model

Domain Modeling with WebRatio Platform
1,785 views Published on Feb 04, 2014 | Time 15 min
Applies to: 7.2 or higher

In the lesson dedicated to the Domain Model Overview, you learned about the Entity-Relationship model and its main concepts: Entity, Attribute and Relationship. The representation of the Domain Model in WebRatio Platform is quite similar to the Entity-Relationship notation ad it is based on the same concepts. In this lesson we analyze how WebRatio Platform shows the Entity Relationship notation adopted for the Domain Model representation.

Transcript

Table of contents

Introduction

In this lesson we analyze how WebRatio Platform shows the Entity Relationship notation adopted for the Domain Model representation. Following lessons show some detailed content and explain the procedure to map the Domain Model into a relational database.

Domain Model in WebRatio

In the online lesson dedicated to the "Domain Model Overview", you learned about the Entity-Relationship model and its main concepts: "Entity", "Attribute", and "Relationship". The representation of the Domain Model in WebRatio Platform is quite similar to the Entity Relationship notation and is based on the same concepts.

Entity in WebRatio

WebRatio shows Entities by means of rectangles with the Entity name at the top. When you add an Entity in the Domain Model, by default WebRatio Platform adds one Attribute to the Entity, which is the Primary Key. The Primary Key is mandatory, and that’s why WebRatio Platform provides this shortcut. The default Key Attribute is named "oid" and is an integer. Of course, you can change the Primary Key and create your own.

Adding an Entity

Let’s see how to add an Entity in the Domain Model.

Select the "Entity" item in the left toolbar and click inside the work area. Next, type a meaningful name for the Entity, such as "Company". Otherwise you can change the name in the Properties View of the Entity.

Entity Properties in WebRatio

An Entity has a set of properties available in the "Properties View":

  • "Duration"
  • "Super Entity"
  • "Attribute Order"
  • "Derivation"

Duration

The "Duration" property indicates whether, at run-time, the instances of this Entity will be stored into a Persistent relational database or into a Volatile database.

In the case of Persistent Duration, the Entity must reference an object in the relational database. As you can see for the "Company" entity, these Entities are represented as green rectangles.

In the case of Volatile Duration, the mapping is not required and the instances are stored either in the Session Scope or in the Application Scope of the Web application. These Entities are represented with specific colors.

An example of Session Scope Entity is the Cart of an e-shopping website, while an example of Application Scope entity is a data dictionary, like one that contains glossary items.

Super Entity

The Entity-Relationship model permits the designer to specify hierarchies that share some common features. The basic generalization hierarchy (also called IS-A hierarchy) has one Super-Entity, the target of the Generalization, and one or more Sub-Entities. The Super Entity is automatically defined by WebRatio Platform based on the hierarchy structure, so you do not have to set up this property by hand.

An example of IS-A hierarchy is the "Company" entity and the "Italian Company" entity which IS-A Company because it shares all the common properties of this object, and adds some specific attributes.

How to Create IS-A Hierarchy

Let’s see how to create an IS-A hierarchy in WebRatio Platform. Suppose you want to use the example of companies and Italian companies. The starting Domain Model contains only the "Company" entity.

Add a new Entity by picking the Entity object from the toolbar and placing it inside the work area. Rename this new Entity as "Italian Company".

This new Entity will be a specialization of "Company" so it will be a subset of already existing companies. However, there is no reason the keep the "oid" attribute on the "Italian Company" since an Italian Company is already univocally identified by the company's oid. Remove it by selecting the Attribute with a mouse left-click and pressing the "Delete" button.

Now let’s specify the Generalization between the two Entities. Right-click on the "Italian Company" entity and choose the "Add Generalization" command. Next, click on the "Company" entity to define that the "Italian Company" entity is a specialization of the "Company" entity, which gets the role of Super Entity.

Attribute Order

This property defines the order of the Entity Attributes in case you want to sort them for better visual representation. Usually you don’t need to change the order as the default is the order in which you add the Attributes to the Entity.

Derivation

The "Derivation" property allows you to specify a derivation query for an Entity. This means that you can derive Entity instances making queries on existing Entities. This translates into database views, whose data is a subset of the Persistent Entity.

An example is the "Big Customer" entity. A big customer is a company that spent at least USD $1million buying your products. You will learn more about the Derivation in a dedicated online lesson.

Attribute in WebRatio

The Entity Attributes are listed inside the Entity itself and are marked with an icon that indicates their role. If the Attribute is one of the Key Attributes, a key symbol is added to the Attribute icon. You can set an Attribute as a Key in the Properties View. Other interesting properties are: "Type" and "Content type".

For each Attribute it is necessary to specify a "Data Type", which is the type of information to be stored. For example the "Birth Date" attribute of an "Employee" is of the type date.

Some data types have also the "Content Type" property, which helps to specify the type of content stored in that attribute. For example, the "Logo" attribute of a "Company" is of the type "blob", which is a file, and of the "Content Type" image.

To learn more about data types, click the help icon.

"Type" and "Content Type" are also used to decide how the Attribute value is shown to the user in the Web application. Finally some data types have an associated "pattern" used in order to format their values. For example, a date can be formatted in different ways depending on the country.

Adding an Attribute

To add an Attribute to an Entity, you can right-click on the selected Entity, choose the "Add", and then choose the "Attribute" option. Give a meaningful name to the "Attribute", such as "VAT".

It's also possible to manage all the Entity Attributes within a dialog. Right-click on the Entity and select the "Edit Entity" option. You will see a dialog listing all the Entity Attributes and a set of buttons that let you add, remove, reorder, or change the attributes. Add the desired attributes. Click the "OK" button.

Relationship in WebRatio

Before we see how to model Relationships, let's remember the online lesson dedicated to the "Domain Model Overview" and to the deep analysis of the Entity-Relationship model.

Until now, to illustrate our examples we have been using Chen's notation for Entity-Relationship modeling. In this notation rectangles represent Entity sets, diamonds represent Relationships, and both can have Attributes of their own, which are drawn as ovals.

In fact, there are various methods of representing ER Models. Another kind of representation is the Min-Max / ISO notation. Let’s consider the model showing a "Person" and a "Company" connected by a Relationship. You can see the model represented with both notations. Notice that the Min-Max notation also specifies the Minimum and Maximum Cardinality for each Relationship Role.

In WebRatio the representation of Relationship is similar to the Min-Max notation. The only difference is that the Minimum Cardinality is not specified, as it always equals 0.

It is not possible to connect two Entities with a different Duration (e.g. one persistent and one volatile).

Adding a Relationship

Let's add the Relationship between a Company and its Employees. To explicitly add a Relationship, you select from the left toolbar the "Relationship" item and then click on the two Entities you want to connect with the Relationship. Click first on the source of your Relationship and then on the target.

Once you have the Relationship you can change its name if you want. To change the name, type the desired name after you click on the Source Entity, or otherwise, pick the Relationship from the work area and change its name in the "Properties View".

Now let’s set the Relationship Cardinalities. By default each new Relationship is set to be "many-to-many", but in our case this is not the desired cardinality. An employee is associated with exactly one company, and each company can be associated with several employees. The Relationship is in fact "one-to-many" because it associates one company to multiple employees. To change the Cardinality, select the Relationship, move to the "Properties View", and change the "Direct" and "Inverse Maximum Cardinality" property. You can set the Cardinality directly on the Role's properties since each Relationship Role has its own set of properties. So, the Relationship Properties View summarizes the properties of both roles.

Next Step

After this lesson you should be able to build your own Domain Model. Once you complete your Domain Model, it will be time to synchronize everything to the database to also create the physical data structure layer. Take a look at the online lesson about "Domain Model synchronization" to learn more.