Part 7: Object Oriented Databases



Similar documents
Object-Oriented Databases

CSC 742 Database Management Systems

Normalization in OODB Design

2. Conceptual Modeling using the Entity-Relationship Model

Data Modeling. Database Systems: The Complete Book Ch ,

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Curriculum Map. Discipline: Computer Science Course: C++

Java (12 Weeks) Introduction to Java Programming Language

Lesson 8: Introduction to Databases E-R Data Modeling

Chapter 8 The Enhanced Entity- Relationship (EER) Model

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Lecture 6. SQL, Logical DB Design

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

El Dorado Union High School District Educational Services

Review: Participation Constraints

Databases and BigData

ER & EER to Relational Mapping. Chapter 9 1

IV. The (Extended) Entity-Relationship Model

DESIGN, IMPLEMENTATION, AND MANAGEMENT DO NOT COPY PETER ROB CARLOS CORONEL

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Principles of Database Management Systems. Overview. Principles of Data Layout. Topic for today. "Executive Summary": here.

The Entity-Relationship Model

Glossary of Object Oriented Terms

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

THE IMPACT OF INHERITANCE ON SECURITY IN OBJECT-ORIENTED DATABASE SYSTEMS

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Introduction to Object-Oriented and Object-Relational Database Systems

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Entity-Relationship Model. Purpose of E/R Model. Entity Sets

How To Create A Table In Sql (Ahem)

Complex Data and Object-Oriented. Databases

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

How To Improve Performance In A Database

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Implementation Aspects of OO-Languages

CSC 443 Data Base Management Systems. Basic SQL

Chapter 1: Introduction

Entity-Relationship Model

Conceptual Design Using the Entity-Relationship (ER) Model

Logical Schema Design: The Relational Data Model

Data Modeling Basics

III. Class and Object Diagrams

Chapter 2: Entity-Relationship Model

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

The C Programming Language course syllabus associate level

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Object-Based Databases

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

The Entity-Relationship Model

How To Design Software

Chapter 9: Object-Based Databases

The Sleepy Cat Database and Semantic Data Models in Java

3. Database Design Functional Dependency Introduction Value in design Initial state Aims

Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Object Oriented Databases (OODBs) Relational and OO data models. Advantages and Disadvantages of OO as compared with relational

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

CS352 Lecture - Object-Based Databases

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Overview RDBMS-ORDBMS- OODBMS

three Entity-Relationship Modeling chapter OVERVIEW CHAPTER

Lecture 12: Entity Relationship Modelling

The Entity-Relationship Model

OBJECTS AND DATABASES. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 21

OOP? What is OOP? Why? OOP in a nutshell. Stéphane Ducasse 2.1

Moving from CS 61A Scheme to CS 61B Java

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Modern Systems Analysis and Design

Normal Form vs. Non-First Normal Form

Theory of Relational Database Design and Normalization

Theory of Relational Database Design and Normalization

Part VI. Object-relational Data Models

Software Engineering. System Models. Based on Software Engineering, 7 th Edition by Ian Sommerville

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS


Chapter 6: Programming Languages

2. Basic Relational Data Model

Object-Oriented Data Modeling

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Functional Dependency and Normalization for Relational Databases

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

Semantic Analysis: Types and Type Checking

Foundations of Information Management

Information Systems Modelling Information Systems I: Databases

There are five fields or columns, with names and types as shown above.

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Graphical Systems Modeling with UML / SysML Class diagrams

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Transcription:

Part 7: Object Oriented Databases Junping Sun Database Systems 7-1 Database Model: Object Oriented Database Systems Data Model = Schema + Constraints + Relationships (Operations) A logical organization of the real world objects, constraints, and relationships among the objects. Object Oriented Data Model: It captures object-oriented concepts. Object Oriented Databases: A collection of objects whose behavior and states, and the relationships are defined in accordance with an object oriented data model. Object Oriented Database Management System: A database system which allows the definition and manipulation of object oriented databases. Junping Sun Database Systems 7-2 Page 1

Structural Object Orientation It relates the notion of complex objects. The data model allows defining data structures for entities of any complexity. That is, objects whose attribute values are themselves objects rather than simple types, such as integers and strings, the is-a-part hierarchy. Example: The x and y coordinates represent a point. Two diagonal points represent a rectangle. The layout mask for an integrated circuit can be represented by a collection of rectangles. Junping Sun Database Systems 7-3 Operationally Object Orientation The data model includes operators to deal with complex objects in their entirety. Operationally object-orientation implies structural object-orientation. Junping Sun Database Systems 7-4 Page 2

Behaviorally Object Orientation It relates the notation of data encapsulation, the concepts of methods, and the notations of the is-a type hierarchy type and its associated concept of inheritance. The data model incorporates features for users to define object types and operators associated with the types. In this case, the instance can be used only by these calling operators. In an example, if a rectangle is an encapsulated object, the user can not modify its coordinates without going through predefined operators. Junping Sun Database Systems 7-5 Basic Concepts of Object Oriented Data Model Each set real world entity instances is modeled as a set of objects with associated class definition. Each object is associated with a unique object identifier. Each object has a set of instance attribute (instance variables, or properties), and methods (operators). The value of an attribute (property) can be an object, or a set of objects. An object can be a simple or atomic object, or a complex object. The concept allows arbitrarily complex object to be defined as an aggregation of other objects. The set of attribute values in an object represents the object status, the set of methods represent the object behavior(s). Junping Sun Database Systems 7-6 Page 3

Objects and Literals Objects and literals are basic building blocks of the object oriented data model. The main difference between the two is that: an object has both an object identifier and a state (or current value), whereas a literal has only a value but no object identifier. In either case, the value have a complex structure. The object state can change over time by modifying the object value. A literal is basically a constant value, possibly having a complex structure. An object is described by four characteristics: (1) identifier, (2) name, (3) lifetime, and (4) structure. Junping Sun Database Systems 7-7 Classes Class: A class is a specification of both the abstract behavior and abstract state of an object. All objects that share the same set of attributes (properties) or methods may be grouped into a class. A class represents a template for a set of similar objects. An object belongs to only one class as an instance of that class. A class is a also an object, and is an instance of a metaclass. A class can be defined as a specialization of one or more classes. A class defined as a specialization is called a subclass, and inherits attributes and methods from its superclass(es). A class can also overwrite or redefine the definitions of attributes and methods from its superclass(es). Class contains two aspects: an object factory and an object warehouse. The object factory can be used as a constructor to create new objects. The object warehouse allows the class to be attached to its extension, i.e., the set of objects that are instances of that class. Junping Sun Database Systems 7-8 Page 4

Complex Objects and Object Structures Simple Objects (Literals): Integers, characters, byte strings of any length, Boolean, and floats. Complex Object: It is build up from simpler object by applying type constructors to them. Type Constructors: They are used to build the values of complex objects from other objects. Complex Object Constructors: Atom - Simple object Tuples - A natural way of representing properties of entities. it is analogous to relational database tuple but not equivalent. Collection Types: Sets - A natural way of representing collections from the real world. Bag - A bag is similar to a set, except that is allows duplicate values to exist. List & Arrays - It captures orders of data in matrices and time-series data It is mainly for many scientific applications. Junping Sun Database Systems 7-9 Complex Object Type: Complex Object Type It is recursively defined as follows: 1. Let D be a name for a domain, then D is a (domain) type. 2. If T 1,, T n are (name of ) types and A 1,, A n are distinct attributes, then T = [A 1,, A n ] is a tuple type, where T z T i for 1 d i d n. 3. If T is a type, then T = {T} is a se of type, where T z T. 4. Recursion may not be allowed in some systems. Books = {Book} Book = {Author:, Title:,..., Reference: Books} Book = {Author:, Title:,, Reference: {Book}} Junping Sun Database Systems 7-10 Page 5

Example Example 1: CHILD = [CNAME:string, BIRTHDATE: date, SEX: string] Children = {CHILD} SKILL Skills = [SKTYPE:string, EXAMDATE:date] = {SKILL} EMPLOYEE = [ID:integer, NAME:string, ADDRESS:string,CHILDREN:Children, SKILLS:Skills] Example 2: PERSON ADDR = [PNAME:string, HOME_ADDR: ADDRESS, SPEAKS: LANGUAGES, WORKS_FOR: COMPANY] = [STREET:string, CITY:string, ZIP:integer] LANGUAGES = {string} COMPANY = {CNAME:string, LOCATION:ADDR} Junping Sun Database Systems 7-11 Structure of EMPLOYEE Format EMPLOYEE = (ID, NAME, ADDR, CHILDREN, SKILLS) EMPLOYEE = (ID, NAME, ADDR, (CNAME,BIRTHDATE, SEX), (TYPE, EXAMDATE)) EMPLOYEE ID NAME ADDR CHILDREN* SKILLS CNAME BIRTHDATE SEX TYPE EXAMDATE Junping Sun Database Systems 7-12 Page 6

Complex Objects Complex Objects Are Recursively Defined as Follows: 1. If D is a domain type and dom(d) is a set of distinct values associated with D, then every o dom(d) is an (atomic) object of type D. 2. If T = [A 1 :T 1,, A n :T n ] is a tuple and o i is an object of type T i, 1 d i d n, then [A 1 :o 1,, A n :o n ] is a (tuple) object (of type T). 3. If T = [T] is a set type and o 1,, o n are objects of type T, then {o 1,, o n } is a set of object (of type T ). Example: e1 = [ID:100, NAME:Joe, ADDR:LA, CHILDREN: {[CNAME:Mary, BIRTHDATE:120661, SEX:F], CNAME:Peter, BIRTHDATE:041470, SEX:M], CNAME:John, BIRTHDATE:082270, SEX:M]}, SKILLS: {[TYPE:drivelic, EXAMDATE:121255], [TYPE:phd_cs, EXAMDATE:021565]}] Junping Sun Database Systems 7-13 Person name address soc-id Example Student transcript CourseHistory class when grade Course name number home Faculty salary works-for Position place rank hired Department name college chairs Regime person date-range TimePeriod begin end length Junping Sun Database Systems 7-14 Page 7

Definition class class class Person superclass: attribute name : attribute address: attribute soc-id: Student superclass: attribute transcript: CourseHistory superclass: attribute class: attribute when: attribute grade: none string string string Person set of CourseHistory none Course date character Junping Sun Database Systems 7-15 Definition class class class Faculty superclass: attribute salary: attribute works-for: Position superclass: attribute place: attribute rank: attribute hired: Course superclass: attribute name: attribute number: attribute home: Person integer set of Position none Department string date none string integer Department Junping Sun Database Systems 7-16 Page 8

Definition class class class Department superclass: attribute name: attribute college: attribute chairs: Regime superclass: attribute person: attribute date-range: TimePeriod superclass: attribute being: attribute end: method length: none string string set of Regime none Faculty TimePeriod none date date begin u end o integer Junping Sun Database Systems 7-17 Nested Relation in Non-First Normal Form Junping Sun Database Systems 7-18 Page 9

Object Representation Representation of Objects: Each object is a triple (i,c,v) i is unique object identifier (the OID) c is a constructor v is the object value or state. An object value v is interpreted on the basis of the value of the constructor c in the tuple (i,c,v) that represents the object. If c = atom, the value v is an atomic value from domain D of basic values supported by the system. If c = set, the value v is a set of object identifiers {i 1, i 2,...,i n }, which are the identifiers (OIDs) for a set of objects that are typically of the same type. If c = tuple, the value v is is a tuple of the form <a 1 :i 1, a 2 :i 2,..., a n :i n >, where a i is an attribute name (instance variable name) and each i i is an object identifier (OID). If c = list, the value v is an ordered list of object identifiers [i 1, i 2,...,i n ] of the same type. If c = array, the value is an array of object identifiers. Note the object identifier i i means the OID for any type of object. Junping Sun Database Systems 7-19 Object Representation O 1 = ( i 1, atom, Houston) O 2 = ( i 2, atom, Bellaire) O 3 = ( i 3, atom, Sugarland) O 4 = ( i 4,atom, 5) O 5 = ( i 5, atom, Research) O 6 = ( i 6, atom, 22-May-78) O 7 = ( i 7, set, {i 1, i 2, i 3 } ) O 8 = ( i 8, tuple, <DNAME : i 5, DNUMBER : i 4, MGR : i 3, LOCATION : i 7, EMPLOYEE : i 10, PROJECT : i 11 > ) O 9 = ( i 9, tuple, <MANAGER : i 12, MANAGERSTARTDATE : i 6 > ) O 10 = ( i 10, set, {i 12, i 13, i 14 } ) O 11 = ( i 11, set, {i 15, i 16, i 17 } ) Junping Sun Database Systems 7-20 Page 10

Junping Sun Database Systems 7-21 The Tree Representation of the Schema Junping Sun Database Systems 7-22 Page 11

define type Employee tuple (name: string, ssn: string, birthdate: string, sex: char, dept: Department); define type Date tuple (year: integer, month: integer, day: integer); define type Department tuple (dname: string, dnumber: integer, mgr: tuple (manager: Employee, startdate: Date ), locations: set (string) employees: set (Employee), projects: set (Project) ); Junping Sun Database Systems 7-23 Object Identity: Object Identity Every object created has an identity unique to itself for its entire lifetime in the database system, whether or not there are ever other objects with similar or identical state or properties. An object has an existence that is independent of its value. With the concept of object identity: Two objects can identical (the same object). Two objects can be equal (same value or content). It supports object sharing and object updating. Example: A component shared by two objects can be updated without inconsistencies. Junping Sun Database Systems 7-24 Page 12

Object Identity and Object Identifier Object Identity: An OO database system provides a unique identity to each independent object. Object Identifier: The unique identity to each independent object is typically implemented via a unique, system generated object identifier, or OID. The value of an OID is not visible to the external user, but it is used internally by the system to identify each object uniquely and to create and manage inter-object references. Properties of OID: The main property required of an OID is that it be immutable, that is, the value of an OID for a particular object should not be changed. This preserves the identity of the real-world object being represented. It is also desirable that each OID be used only once; that is, even if an object is removed from the database, its OID should not be reassigned to another object. This two properties imply that the OID should not depend on any attribute values of the object, since the value of an attribute may be changed. Junping Sun Database Systems 7-25 Comparisons of OID and Key A key is unique within a relation in relational databases, whereas the object identifier is unique within entire system. By using OID one can define heterogeneous collections of objects which identify the objects belonging to different classes. A collection consists of a set of OIDs are independent from the class to which the objects belong. OIDs are implemented by the system, the applications programmers do not have to concern themselves with selecting appropriate keys for the various classes of objects. Better performance can be achieved, OIDs are implemented at lower level by the system. OID can not be modified and reused, but key in relational database can. Junping Sun Database Systems 7-26 Page 13

Identical Equality and Value Equality Two objects can be identical (the same object). Two objects can be value equal (same value or content). O 1 = ( i 1, tuple, { a 1 : i 4, a 2 : i 6 } ) O 2 = ( i 2, tuple, { a 1 : i 5, a 2 : i 6 } ) O 3 = ( i 1, tuple, { a 1 : i 4, a 2 : i 6 } ) O 4 = ( i 4, atom, 10) O 5 = ( i 5, atom, 10) O 6 = ( i 6, atom, 20) Object O 1 and O 2 are value equal. Object O 1 and O 3 are identical equal. Object O 4 and O 5 are value equal. Junping Sun Database Systems 7-27 Identity Equality Two objects O1 and O2 are identical, if they have the same identifiers, it corresponds to the equality of references or pointers of two objects (O1 = O2). O1: i1 O2 : i101 Name Age Address Address Age Name i4 John 32 34 Mary Street# Streetname City State Zip 1212 Main Walnut Creek CA 94596 O1.Address and O2.Address are identity equal or identical. Junping Sun Database Systems 7-28 Page 14

Object Representation O1 = ( i1, tuple, <Name : i2, Age : i3, Address : i4>) O2 = ( i2, atom, "John" ) O3 = ( i3, atom, 32 ) O4 = ( i4, tuple, <Street # : i5, Streetname : i6, City : i7, State : i8, Zip : i9> ) O5 = ( i5, atom, "1212") O6 = ( i6, atom, "Main") O7 = ( i7, atom, "Walnut Creek" ) O8 = ( i8, atom, "CA" ) O9 = ( i9, atom, "94596" ) O101 = ( i101, tuple, <Name : i102, Age : i103, Address : i4]>) Junping Sun Database Systems 7-29 Shallow Equality (Simple Equality) Two objects O1 and O2 are shallow equal if their states or contents are identical, i.e. value (O1) = value (O2). This definition is not recursive (holds only for the first level of objects). O1 : i1 O2 : i2 Name Age Children Children Name Age i3 i4 John 32 * * Mary 32 i5 i6 Name Age Name Age Tom 10 Ann 5 O1.Children and O2.Children are shallow equal. Junping Sun Database Systems 7-30 Page 15

Deep Equality Two objects O1 and O2 are deep equal if the correspondent atomic object values are equal. (replacing the identifiers with values) O1 : i1 O2 : i3 O3 : i4 a b b a a b 1 i2 1 1 i5 c d c d 2 3 2 3 Objects O1 and O2 are deep equal, and also O1 and O2, and O2 and O3. Objects O1.b and O2.b are identical equal Objects O1 and O2 are shallow equal. Junping Sun Database Systems 7-31 Discussions on Object Equality Identical equality checks whether two objects are the same. Shallow equality which goes one level deep, checks the corresponding identifiers of the values of elements of the objects. Deep equality checks the contents of the corresponding base or atomic objects. Each object is (identical/shallow/deep) equal to itself : reflexive. If O1 is (identical/shallow/deep) equal to O2, then O2 is (identical/shallow/deep) equal to O1 : symmetric. If O1 is (identical/shallow/deep) equal to O2, and O2 is (identical/shallow/deep) equal to O3, then O1 is (identical/shallow/deep) equal to O3 : transitive. The strongest equality is identical, and shallow is stronger than deep. Two identical objects are always shallow equal and deep equal, Two shallow objects are always deep equal. Junping Sun Database Systems 7-32 Page 16

Composite Objects Composite Object: It is in general a heterogeneous collection of objects, that is, the components objects from a number of different classes. References: If the domain of an attribute is a non-primitive class, the value stored for the attribute is the object identifier(s) of the instance(s) of the domain. In this case, we say the object reference other objects. Weak Reference: It is the object reference under the object data model without the part-of semantics. Composite Reference: It is a weak reference augmented with the part-of relationship. Exclusive Composite Reference: It is a reference from an object X to another object Y is a part of only X; Shared Composite Reference: It is a reference from an object X to another object Y is a part of X and possibly other objects. Junping Sun Database Systems 7-33 Dependent v.s. Independent Composite Reference Dependent Composite Reference: It is a reference from X to Y such that the existence of Y depends on the existence of X. Deletion of an object will trigger recursive deletion of all objects referenced by the object through dependent composite reference (both exclusive and shared). Independent Composite Reference: It is a reference from X to Y such that the existence of Y does not depend on the existence of X. Summary of Four Types of Composite Reference: (1) Exclusive dependent composite reference (2) exclusive independent composite reference (3) shared dependent composite reference (4) shared independent composite reference Junping Sun Database Systems 7-34 Page 17

Structure for Object Instances OID: It is system-generated identifier for object, which is globally unique in the life-time of the OODBMS. Object Size: the size of the object in bytes. Number of Attributes: give the attribute count. Identifiers of Attributes: System-defined attributes include the version number of and update timestep for versioned objects. User-defined attributes include the attributes for which the object has explicitly specified values. Offsets: It consists of the offsets O i, in the value part of the object storage structure, of the values of the attributes. Values: The values can be the simple object values, or a reference to another object, the OID of the referenced object. Junping Sun Database Systems 7-35 Object Instance Representation Identifiers of Attributes Simple values or OIDs of Objects OID Object Size Number of Attributes Offsets values Object Identifier System-defined attributes User-defined attributes Junping Sun Database Systems 7-36 Page 18

Objects on a Disk Page Offsets Free Space Page header Objects Junping Sun Database Systems 7-37 Structure of Class Objects In most object-oriented database systems, classes are regards as objects, just as the instance of a class is object, or it is an instance of metaclass. A class object maintains the following information: 1. Class Attributes (shared by all instances of the class) 2. Class Methods (e.g. new) 3. Instance Attributes (names and structures) 4. Instance Methods (names and codes) 5. A reference to superclass 6. References to all instances All the information related to a class stored as a class object. Junping Sun Database Systems 7-38 Page 19

Schema of an Object-Oriented Database The Schema of an Object-Oriented Database Consists of System-defined classes and User-defined classes System-Defined Classes: The class Class: It contains attributes ClassName, Attributes, Superclasses, Subclasses, and Methods. ClassName is the name of the class Attributes is the set of attributes defined for or inherited into the class. The attributes Superclasses and Subclasses are the sets of superclasses and subclasses of the class. Methods is the set of methods defined for or inherited into the class. The class Attribute: The class Attribute has attributes, Class, Domain, and InheritedFrom. The attribute Class references the class to which the attribute belongs. Domain specifies the class to which the value of the attribute is bound. InheritedForm indicates the attribute of the superclass from which the attribute is inherited. Junping Sun Database Systems 7-39 Classes for Schema Class ClassName Attributes Superclasses Subclasses Methods Attribute Class Domain InheritedFrom Method Class MethodName Code InheritedFrom Junping Sun Database Systems 7-40 Page 20

Example Junping Sun Database Systems 7-41 OODB Schema in Possible Object Definition Language class Person (extent persons) key ssn) { attribute struct Pname {string fname, string mname, string lname} name; attribute string ssn; attribute date birthdate; attribute enum Gender {M, F} sex; attribute struct Address {short no, string street, short aptno, string city, string state, short zip} address; short age(); } Junping Sun Database Systems 7-42 Page 21

Definition of Faculty Class in Possible ODL class Faculty extends Person ( extent faculty ) { attribute string rank; attribute float salary; attribute string office; attribute string phone; relationship Department worksin inverse Department::has_faculty; relationship set<gradstudent> advises inverse GradStudent::advisor; relationship set<gradstudent> on_committee_of inverse GradStudent::committee; void give_raise ( in float raise ) void promote ( in string new_rank ); }; Junping Sun Database Systems 7-43 Definition of Grade Class in Possible ODL class Grade ( extent grades ) { attribute enum GradeValues { A, B, C, D, F, I, P } grade; relationship Section section inverse Section::students; relationship Student student inverse Student::Completed_secitons; }; Junping Sun Database Systems 7-44 Page 22

Definition of Student Class in Possible ODL class Student extends Person ( extent students ) { attribute string class; attribute Department minors_in; relationship Department majors_in inverse Department::has_majors; relationship set<grade> completed_sections inverse Grade::student; relationship set<currsection> registered_in inverse Curr_Section::registered_students; void change_major ( in string dname ) raises ( dname_not_valid ); float gpa(); void register ( in short secno) raises ( section_not_valid ); void assign_grade ( in short secno; in GradeValue grade ) raises (section_not_valid, grade_not_valid ); } Junping Sun Database Systems 7-45 Definitions of Degree and GradStudent Classes in ODL class Degree { attribute string college; attribute string degree; attribute string year; }; class GradStudent extends Student ( extents grad_students ) { attribute set<degree> degrees; relationship Faculty advisor inverse Faculty::advises; relationship set<faculty> committee inverse Faculty::on_commiittee_of; void assign_advisor ( in string lname; in string fname ) raises ( faculty_not_valid ); void assign_committee_member ( in string lname; in string fname ) raises ( faculty_not_valid ); }; Junping Sun Database Systems 7-46 Page 23

Definition of Department Class in Possible ODL class Department ( extent departments key dname ) { attribute string dname; attribute string dphone; attribute string doffice; attribute string college; attribute Faculty chair; relationship set<faculty> has_faculty inverse Faculty::works_in; relationship set<student> has_majors inverse Student::majors_in; relationship set<course> offers inverse Course::offered_by; }; Junping Sun Database Systems 7-47 Definition of Course Class in Possible ODL class Course ( extent courses key cno ) { attribute string cname; attirbute string cno; attribute string description; relationship set<section> has_sections inverse Section::of_course; relationship Department offered_by inverse Department::offers; }; Junping Sun Database Systems 7-48 Page 24

Definitions of Section and CurrSection Classes in ODL class Section ( extent sections ) { attribute short secno; attribute string year; attribute enum Quarter {Fall, Winter, Spring, Summer} qtr; relationship set<grade> students inverse Grade::section; relationship Course of_course inverse Course:: has_sections; }; class CurrSection extends Section ( extent current_sections ) { relationship set<student> registered_student inverse Student::registered_in; void registerr_student ( in string ssn ) raises ( student_not_valid, section_not_valid, section_full ); } Junping Sun Database Systems 7-49 Junping Sun Database Systems 7-50 Page 25

Mapping an EER Schema to an ODB Schema Step 1: Create an ODL class for each EER entity type or subclass (subtype). The defined class type should include all the attributes defined as atomic data type or complex type predefined in terms of tuple constructor. Define multivalued attributes by using the set, bag, or list constructors. Define composite attributes by tuple constructor (struct declaration in ODL). Declare an extent for each class, and specify any key attributes as keys of the extent if the facility in ODL is available. Junping Sun Database Systems 7-51 Step 2: Mapping an EER Schema to an ODB Schema Add relationship properties or reference attributes for each binary relationship in to the defined class(es) that participate in the relationship. These may be created in either one or both directions. If a binary relationship is represented by references in both directions, declare the references to be properties relationship properties that are inverses of one another if the facility in ODL is available. Declare the relationship as single-valued on the side such that the cardinality ratio of the relationship is 1:1 or N:1 direction, and as collection type (set, bag, list,..) on the side 1:N or M:N direction. For attribute belonging to a relationship, use tuple constructor as the following format: <reference as relationship property, relationship attribute> Junping Sun Database Systems 7-52 Page 26

Mapping an EER Schema to an ODB Schema Step 3: Include appropriate operations for each class. Constraint checking should be incorporated in both object constructor, destructor, and others. Step 4: An defined class that corresponds to a subclass in the EER schema inherits (via extend) the type and methods of its superclass in the schema in ODL. Step 5: Weak entity can be mapped in the same way as regular entity types. Alternatively, weak entity can be included as composite multivalued attributes in the owner entity if the weak entity does not participate in any relationships except the identifying relationship. The multivalued composite attribute for weak entity can be defined by collection types such as: set, bag, list, Junping Sun Database Systems 7-53 Step 6: Mapping an EER Schema to an ODB Schema An n-ary relationship with degree n > 2 can be mapped into a separated class, with appropriate references to each participating classes. These references are based on the mapping a 1:N relationship from each class that participating entity type to the class that represents the n-ary relationship. An M:N binary relationship may also use this option, especially, if it contains the relationship attribute. Junping Sun Database Systems 7-54 Page 27