1010/3/151 Lecture 9 on Object-Oriented Database To study object-oriented database as a 3 rd...

48
1010/3/15 1 Lecture 9 on Object-Oriented Database To study object-oriented database as a 3 rd generation post relational database, its powerful features of inheritance, encapsulation, polymorphism, object identity, stored object identity, class, and method, and object, and above all, how it differentiates with relational database.
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    230
  • download

    1

Transcript of 1010/3/151 Lecture 9 on Object-Oriented Database To study object-oriented database as a 3 rd...

1010/3/15 1

Lecture 9 on Object-Oriented Database

To study object-oriented database as a 3rd generation post relational database, its powerful features of inheritance, encapsulation, polymorphism, object identity, stored object identity, class, and method, and object, and above all, how it differentiates with relational database.

1010/3/15 2

Motivations for Object-Oriented Database Systems

• - Serious Deficiencies in Current Database Systems

• - Promise of Object-Oriented Paradigm for Application Development

• - Application Productivity Enhancement• - Offloading of Functions from Applications

to Database Systems. e.g. Putting programs inside database (encapsulation).

1010/3/15 3

Evolution of Database Systems- File systems e.g. ISAM, VSAM

- Hierarchical Database Systems (e.g. IMS, System 2000)

- CODASYL Database Systems (e.g. IDS, Total)

- Relational Database Systems (e.g. DB2, ORACLE, SYBASE, INFORMIX).

- Extended Relational Database (e.g. UniSQL)

- Object-Oriented Database (e.g. GemStone)

1010/3/15 4

Conventional Database Technology: Applications Perspective

- Developed for Traditional Business Data Processing

- Problematic for Many Non-Traditional Applications, e.g. Multimedia, Engineering, Design, Modeling/Analysis, Geographical, Moledular Biology, Statistical, etc.

- Application Developers must do what database systems do not do. e.g. time-consuming and error-prone, potentially repeadted for each application

1010/3/15 5

Conventional Database Technology: Serious Deficiencies

- Due to Data Model. e.g. Fixed Data Types (integer, real, string, date, time, money, BLOB).

- No Compound Data (complex nested data)

- No Procedural Data (programs)

- Single Value per Row/Column

- Cannot Support Memory Pointer - Chasing Applications (navigate data via memory pointers)

1010/3/15 6

Motivations for Object-Oriented Programming

- Software Productivity

- Development, Maintenance, and Evolution of Complex Software Systems.

- Encapsulation (Data and Program)

- Reuse (Inheritance)

1010/3/15 7

Object-Oriented Concepts

- Encapsulation

- Object = Data + Program

- Data = Values of Attributes (Row of a Table)

- Program(Method) = Operates on the Data

- Value of an Attribute can be an Object as well as a primitive value (number, string)

1010/3/15 8

Example: Object DefinitionSHAPE

attributes: Center-Point Point,

Bounding-Box Box,

Area Floatmethods: Display-Shape

POINT

attributes: X Float,

Y Float

BOX

attributes: X1 Float,

Y1 Float,

X2 Float,

Y2 Float

1010/3/15 9

Example: Stored RepresentationSHAPE object POINT object

Center-Point

Bounding-Box

Area

Display-Shape

XY

X1Y1X2Y2

BOX object

Display-Shape Code

1010/3/15 10

Reuse - Attributes and Methods Inherited by Other Objects

SHAPE

TRIANGLE

(Display-Shape)

RECTANGLE

(Display-Shape)

(Display-Shape)

1010/3/15 11

Organization of Objects

- Organization of Objects

- Objects (Instances) Are Grouped into a Class (Table)

- Class: Attributes (and Data Types) and

Methods

1010/3/15 12

Classes are organized in a class hieraarchy (DAG)- Reuse (Inheritance)SuperclassSubclassSingle vs. Multiple Inheritance

- IS-A Relationship

Instances of a subclasses are subsumed by (included in) its superclasses

SHAPE (superclass)

TRIANGLE

(subclass)RECTANGLE (subclass)

1010/3/15 13

Object-Oriented Programming and Database Systems

- Object-Oriented concepts form a sound basis for Object-Oriented data model.

- Object-Oriented data model can remove data model-related definciencies of conventional database systems.

1010/3/16 14

Definition of an Object-Oriented Database System

- must support object-oriented data model

- must be a database system

- not merely persistent storage system for object-oriented programming language (C++, Smalltalk, etc.)

- query language, transaction management, access authorization, etc.

- each object must have an OID (object identity) with a system generated unique address

- each object may have Stored-OID, an OID used as a pointer, referring to another object

1010/3/15 15

- Encapsulation

- object = data + program

- data = values of attributes

- program = methods that operates on the state

- value of an object is also a object

- Organization of objects

- objects are grouped into a class

a class has attributes and methods

an object may be nested

an object has a unique identified

- classes are organized in a class hierarchy

- Reuse

- in a class hierarchy, a subclass inherits attributes and methods from one or more superclasses.

1010/3/15 16

Procedure Data

Name

Job

Salary

Hobby

WorksFor

Retirement - Benefits

Personality - Profile

Employee

Attributes

Methods

Complex Nested Objects- Successive refinement of complex

data modeling

Name

Job

Salary

Hobby

WorksFor

NameNumPlayers

NameLocationBudget

StateCity

EmployeeActivity

Company StateCity

1010/3/15 18

Multiple inheritance and IS-A Relationship

NameMajorGPAHome

NameCoursesSalaryHobbyRank

Hours-Worked

Grad-Student

Student Faculty

1010/3/15 19

- Uniform framework for supporting arbitrary data types

- Traditional primitive data types

- integer, string, boolean, time, date, memory, BLOB

- User-defined arbitrary abstract data types

- company, employee, memo, etc.

- Dynamic addition of new data types

- Dynamic composition of new data types from existing data types

Object-Oriented Data Model

1010/3/15 20

Classification and instantiation

The objects belonging to a class are collectively described by a class definition.

This class structure, encompassing both properties and behaviour, is the natural unit of abstraction in object-oriented systems.

Instantiation is the inverse of classification and concerns the generation of distinct objects of a class.

1010/3/15 21

class Hotel

attributes

name: String;

address: String;

owner: Company;

manager: Set (Person);

facilities: Set of string;

methods

Create (…);

ReserveRoom (room#: integer; guest: Person; arrive_date, depart_date: Date Type)

end Hotel

1010/3/15 22

Name The Royal Oak

Address Bayview Road, Tralee

Owner (Company instance)

Manager Set (Person instance)

Facilities (swimming_pool, Sauna)

Name

HeadquartersTelephone

Trust house

Dublin

01-123567

Name

AddressDOB

23 Main, st

John Lee

28/8/53

Hotel Instance

Company Instance

Person Instance

Name

AddressDOB

1 Market st

Mary Kim

10/1/56

1010/3/16 23

Examples of Stored_OID pointers

Class Hotel

Name Address Owner Manager Facilities

Class Person

Name Address DOB

John Lee 23 Main St 28/8/53

Mary Kim 1 Market St 10/1/56

OID

OID

xxx

yyy

zzz Royal Oak Bayview Road (swimming pool, Sauna)

Class Defining Object

OID

aaa

Hired_by

Stored OID

Stored OID

1010/3/15 24

The Role of Inheritanceclass Vehicle

attributes

reg_no, make, model: string;

colour: Colour Type;

mileage: integer;

fueltype: (leaded, unleaded, diesel);

year: integer;

methods

New_vehicle (…)

end Vehicle

1010/3/15 25

Inheritance represents IS_A relationship

class Unlead_Car

inherit Car

attributes

size: (compact, medium, large);

extras: set (option Type);

method

If not leaded_car

then call new ( ) on unleaded_car;

end Unlead_Car

1010/3/15 26

Constraints are checked for validity following execution of methods of the classclass Car

inherit Vehicle

attributes

fueltype: (leader, unleaded);{re-defined}

{additional properties of cars}

size: (compact, medium, large);

extras: set (option Type);

constraints

if year > 1985 then fueltype = unleaded’

end Car

1010/3/15 27

Trigger specifies a condition and action to be taken when condition met

class Inventory_Item;

attributes

item: Part;

qty_in_stock, reorder_level, reqd_level: integer;

method

add (qty);

remove (qty);

issue_order (qty);

triggers

if qty_in_stock < reorder_level

then issue_order (reqd_level - qty_in_stock);

1010/3/15 28

Rule of multiple inheritanceName conflicts from inheritance are either managed

automatically by the system, or the user can specify a conflict resolution. For example, in UniSQL, the user can specify which name of subclass to inherit

Create Class bed_and_breakfast as subclass of accommodations, eatery

(rooms set_of (private_room),Owner string)Inherit name of accommodations;

1010/3/15 29

Object-oriented database definition in general

Each object belongs to a family, or class, of similar objects. A class is a template (containing code and data) that describes the common characteristics of a set of objects. The object-oriented methodologies simplify database updates and provide faster access to stored data such that programmer simply references the object without writing code to read object from disk into memory.

1010/3/15 30

PolymorphismIn object-oriented programming, polymorphism refers to the ability of a

single program entity to refer at run-time to instances of a variety of types or classes. A simple form of polymorphism is overloading, which permits the use of the same name for more than one entity in a program, ambiguities being resolved by the system by examination of the context of each occurrence of the name. For example, one may use the name add for operations to add two integers, tow real numbers, or even two character strings. An add operation on variables v1 and v2 is invoked by the call:

add (v1, v2)

• and the system decides which function to apply by examining the types of v1 and v2.

1010/3/15 31

Example of polymorphismSame function call with different output format:

Case 1:• Call Show_all_instance( ) on class full_time_student;

Output: Student# Student_name Student_address ……. ………

……….Case 2:

• Call Show_all_instance ( ) on class department;

Output: Dept# Dept_name Staff……… ……… ……

1010/3/15 32

Comparison betweem Relational and OODB

1. Data types and operations:

RDB - attributes of normalized relations are non-decomposable simple data types and their operations restricted to retrieving and updating tuples identified by attribute values.

OODB - an object-oriented database stores class definitions and instantiations of these classes that need not be simple data types but can refer to other classes, and may even be passed as a parameter to an operator. OODB can define its operation.

1010/3/15 33

2. Data integrity

RDB - incapable of expressing integrity constraints with greater semantics content than straight forward referential integrity.

OODB - a class defines a data abstraction including operation specification (methods) applied to instance of class. High degree of data independence can be achieved by defining database in such abstraction. Also an operation on an object can be invoked by a procedure in a class, which can incorporate consistency checks.

1010/3/15 34

3. Uniqueness

RDB - an entity must distinguish it from all other entities.

OODB - all objects (class instantiations) have a unique identity.

4. Schema evolution

RDB - RDBMS offers very limited for the expansion of existing schema (data structure).

OODB - The tight complying between applications and data in the object-oriented models offers considerably more scope for schema evolution through the extension and the effective reuse of application code.

1010/3/16 35

Map EER model & data operation into OODB schemaStep 1 Entity Class: each entity maps into a class.

Step 2 Cardinality Association and inverse association constraintsEach cardinality maps into a pair of association attributes

Step 3 isa Inheritance constraintsEach isa maps into a superclass object and subclass object inheritance

Step 4 Aggregation “Part Of” data semantics constraintCreate aggregation class when component class(es) existDelete component classes before deleting aggregation class

Step 5 Disjoint Generalization MethodWhen inserting a subclass data, ensure it does not exist in a mutually exclusive

subclass

1010/3/15 36

Case Study I: A medical research GroupA medical research group maintains a database of all published papers

relating to certain kinds of virus.

Each paper is published in a particular issue of a journal identified by the name of the journal, the volume number and the number of the issue.

A paper may have one or more authors and may be concerned with viruses.

The abstract of the paper is recorded, together with the name of each author and the name of the institution at which the research was carried out.

Each paper contains references to other papers.

Papers published by the research group are stored with contract_no, amount, start_date, finish_date.

1010/3/15 37

Typical operations performed by users of the database are:

• Enter a new paper with all its associated information.

• List the details of all papers concerning a specified virus.

• List the papers of a specified author.

• List the papers associated with a specified research contract.

1010/3/15 38

EER model for the Research Institute

INSTITUTE AUTHOR

PAPERINTERNAL

PAPER

VIRUSCONTRACT

FUNDEDBY

IS_A

CONCERNS

WRITESPRODUCES

REFERSTO

N

N

N NN

MM

M

1

1

Author_nameNationalityDate_of_birth

Instutute_nameAddressType

NameTitleIssue#Year

Virus_nameDescription

Contract#AmountSart_dateEnd_date

NameRef#

Name

1010/3/15 39

The mapped Object-Oriented Schema

class Paper

Attributes

name: string

title: string;

issue#: integer;

year: integer

produce_by: Institute

inverse is Institute_produce;

writen_by: Set (Author)

inverse is Author.write;

concerns: Set (Virus)

inverse is Virus.covered_by;

refers_to: Set (Paper);

Method

Display name, title, issue#, year, produced_by.Institute, written_by.Author, concerns.Virus, refers_to.paper;

end Paper

1010/3/15 40

class Internal_Paper

inherit Paper

attributes

associated_contract: Contract

inverse is Contract.reports;

end Internal_Paper

class Virus

attributes

name, description: string;

covered_by: Set (Paper)

inverse is Paper.concerns;

method

Display name, covered_by.paper;

end Virus

1010/3/15 41

class Contract

attributes

contract#, amount: integer;

start, end: date;

reports: Set (Internal_Paper)

inverse is internal_paper.associated_contract;

method

Display contract#, reports.Internal_Paper;

end Contract

1010/3/16 42

class Authorattributes

name: string;nationality: NationalityType;date_of_birth: date;write: set (papers)

inverse paper.written-by;method

Display name, write.papers;end Authorclass Institute

attributes

name, address: string;

type: InstituteType;

produce: set (papers)

inverse paper.produce-by;

end Institute

1010/3/15 43

Case Study II: map Aggregation into OO Schema

grade

Student

n

Instructor section Coursem n

m

Section#

Inst-nameInst-address

Course#Course-loc

Student#Student-name

1010/3/15 44

Mapped into OODBClass Section Attributes Section#: integer teach: Course taught-by: instructorMethod If Course and Instructor exist then create Section; If deleting Section then delete Course and Instructor;

Class Course:::

Class Instructor:::::

1010/3/15 45

Lecture summary

Object-oriented database is much powerful than relational database with respect of productivity. However, its features may not be as user friendly as relational database. Therefore, it is not as popular as relational database, and its major applications are limited to multi-media and large software development.

1010/3/15 46

Review Question

What are the difference in implementing many-to-many cardinality in Relational schema and in Object-Oriented schema? Which one is more efficient and why?

What are the difference in implementing Stored Procedure in Relational database and Method in Object-Oriented database? Which one has more limitation to access database and why?

1010/3/15 47

Tutorial Question An Extended Entity Relationship model has been designed for the database. Show the object-

oriented database schema for the implementation of the EER model design of enrollment record.

Student

GraduateStudent

enrol

Prereq

Student#student_namesex

Student#degree_to_be

Coursecourse_titlelocation

SS#Inst_nameInst_addr

Section#lecture_hour

CoursePrerequisiteprereq_title

Prerequisite

n

m

n

Instructor section Coursem n

1

yeargrade

Studenthelper

Student#Tutored_class

C

1010/3/15 48

Reading Assignment

Chapter 20 Object and Object-Relational Database of “Fundamentals of Database Systems” Fifth edition by Elmasri & Navathe, Peason, 2007.