Chapter 9 Working with Object-Oriented Models


Mapping an association in a class diagram

O/R mapping on an association allows to define the role navigability of an association in the database. When an association role is not navigable, there is no need to design a mapping for the association since no information is transmitted between the classes. However, when an association role is navigable, you have to set up the structure for data transmission within the database. In relational databases, data transmission is implemented via foreign keys designed to relate a record in one table with a record in another.

The type of mapping for an association depends on the association multiplicity:

SQL queries

When the association roles are navigable, the following queries are automatically computed:

Query Action
Select (Role A) Retrieves related class A instances for the role A defined on class B
Insert (Role A) Associates an instance of class A with class B. It is computed only when the source association is an associative table
Delete (Role A) Deletes from class B the association with class A. This query is computed only when the source association is an associative table
Select (Role B) Retrieves related class B instances for the role B defined on class A
Insert (Role B) Associates an instance of class B with class A. This query is computed only when the source association is an associative table
Delete (Role B) Deletes from class A the association with class B. This query is computed only when the source association is an associative table

Each statement is automatically generated. If you modify a statement, it becomes user-defined and can no longer be automatically calculated, even when you update the mapping. You can tell that a statement is user-defined because the User-Defined tool is pressed in the toolbar. You can recover the computed expression by clicking the User-Defined tool. This removes any non-calculated expression from the tab.

Modify query template

The syntax of SQL queries follows a predefined template. You can customize the query syntax by modifying the SelectA, InsertA, UpdateA, DeleteA, SelectB, InsertB, UpdateB, and DeleteB entries in the Profile category of the object language or extended model definition.

For more information on customizing templates, see section Defining templates, in chapter Generation Reference Guide in the Advanced User Documentation .

 


Copyright (C) 2006. Sybase Inc. All rights reserved.