Databases Reference
In-Depth Information
multiplicity is over 1, the relationship is defined by a collection type (set, list,
or bag). When it is an ordered relationship, the collection type has to be a
list. The ODMG data model does not support directly the minimum multi-
plicity, so when it is 1, this constraint has to be implemented in the con-
structor operation. Role-names are the names of each traversal path of the
relationship.
In Figure 7.6, the relationship between PhDProgram and Lecturer is a
many-to-many relationship defined without order. However, PhDProgram
and Student is a one-to-many relationship. If students are ordered accord-
ing to, for example, their register number, the relationship will have to be
defined with a list type.
ODMG supports the definition of two-way relationships. However, in
some cases, because of efficiency reasons, it may be convenient to implement
one-way relationships. Relationships in OODBMSs are currently imple-
mented as pointers. If queries traverse the relationships in just one direction,
then bidirectional relationships are redundant. For example, it could be con-
venient to establish a one-way relationship between Student and PhDPro-
gram (from PhDProgram to its Students). We generally will want to know
the registered students in a given Ph.D. program, but we will not know the
Ph.D. program of a specific student. If we can define such a one-way rela-
tionship in ODL, we have to define it as an attribute (see Figure 7.7). In
addition, we have to define two methods that implement the relationship;
the order will have to be implemented through the enrol_in method.
Class Student (extent students Key rnumber)
{ attribute short rnumber;
attribute string (20) degree;
attribute string (30) university;
void student (short N, string (20) D, string (30) U,
PhDProgram DP
);
void drop (
PhDProgram DP
); };
Class PhDProgram (extent PhDPrograms)
{ attribute string (30) name;
attribute struct Departments {char (10) MilanoD, char (10) RJCD};
Student
attribute list
<
>
enrols;
relationship set
Lecturer
involves inverse essays::Lecturer;
<
>
void PhDProgram ();
void drop ();
void enrol_in (in Student S, PhDProgram, DP);
void drop_enrol (in Student S, PhDProgram DP);
};
Figure 7.7
One-way relationships defined as attributes.
Search WWH ::




Custom Search