Types in ODL

Types in ODL

ODL gives the database designer a type system similar to that found in C or other usual programming languages. A type system is built from a basis of types that are described by themselves and certain recursive rules whereby complicated types are built from simpler types. In ODL, the basis comprises:

1. Atomic types: integer, float, character, character string, boolean, and enumerations. The latter are lists of names declared to be abstract values. We saw an instance of an enumeration in line (5) of  "Relationships in ODL / Inverse Relationships" Figure (a), where the names are color and blackAndWhite.

2. Class names, such as Movie, or Star, which stand for types that are actually structures, with elements for each of the attributes and relationships of that class.

These basic types are combined into structured types using the following type constructors:

1. Set.  If T is any type, then Set indicates the type whose values are finite sets of elements of type T. Examples using the set type-constructor take place in lines (6), (ll), and (15) of  "Relationships in ODL / Inverse Relationships" Figure (a).

2. Bag.  If T is any type, then Bag indicates the type whose values are finite bags or multisets of elements of type T. A bag allows an element to appear more than once. For instance, {1,2,1} is a bag but not a set, because 1 appears more than once.

3. List.  If T is any type, then List indicates the type whose values are finite lists of zero or more elements of type T. As a special case, the type string is a shorthand for the type List.

4. Array.  If T is a type and i is an integer, then Array indicates the type whose elements are arrays of i elements of type T. For instance, Array indicates character strings of length 10.

5. Dictionary.  If T and S are types, then Dictionary indicates a type whose values are finite sets of pairs. Each pair comprises a value of the key type T and a value of the range type S. The dictionary may not include two pairs with the same key value. Most probably, the dictionary is implemented in a way that makes it very effective, given a value t of the key type T, to find the related value of the range type S.

6. Structures.  If T1, T2, .. . ,Tn  are types, and F1, F2,. . . , Fn, are names of fields, then

Types in ODL

Struct N {T1 F1, T2 F2, . . . , Tn Fn}

indicates the type named N whose elements are structures with n fields. The ith field is named Fi  and has type Ti. For instance, line (10) of "Relationships in ODL / Inverse Relationships" Figure (a) showed a structure type named Addr, with two fields . Both fields are of type string and have names street and city, respectively.

The first five types - set, bag, list, array, and dictionary - are called collection types. There are different rules about which types may be associated with attributes and which with relationships.

●  The type of a relationship is either a class type or a (single use of a) collection type constructor applied to a class type.

●  The type of an attribute is built starting with an atomic type or types. Class types may also be used, but normally these will be classes that are used as "structures", much as the Addr structure was used in "Attributes in ODL" Example (b). We usually prefer to connect classes with relationships, because relationships are two-way, which makes queries about the database easier to express. On the contrary, we can go from an object to its attributes, but not vice-versa. After beginning with atomic or class types, we may then apply the structure and collection type constructors as we wish, as many times as we wish.

Example : Some of the possible types of attributes are:

1. Integer

2. Struct N {string field l, integer field2}

3. List.

4. Array.

Example (1) is an atomic type; (2) is a structure of atomic types, (3) a collection of an atomic type, and (4) a collection of structures built from atomic types.

Now assume, the class names Movie and Star are available basic types. Then we may construct relationship types such as Movie or Bag.  On the other hand, the following are illegal as relationship types:

1.  Struct N {Movie fieldl, Star field2}. Relationship types cannot involve structures.
2.  Set. Relationship types cannot involve atomic types.
3.  Set>. Relationship types cannot involve two applications of collection types.