object oriented data base. traditional data models : hierarchical, network (since mid- 60’s),...

32
Object Oriented Data Base

Upload: leon-park

Post on 23-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Object Oriented Data Base

Page 2: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Traditional Data Models : Hierarchical, Network (since mid-60’s), Relational (since 1970 and commercially since 1982)Object Oriented (OO) Data Models since mid-90’sReasons for creation of Object Oriented Databases

Need for more complex applicationsNeed for additional data modeling featuresIncreased use of object-oriented programming languages

Commercial OO Database products – several in the 1990’s, but did not make much impact on mainstream data managementMAIN CLAIM: OO databases try to maintain a direct correspondence between real-world and database objects so that objects do not lose their integrity and identity and can easily be identified and operated uponObject: Two components: state (value) and behavior (operations).

Introduction

Page 3: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

3

OODBMS VendorsGemStone Systems, Inc. Hewlett-Packard, Inc. (OpenODB) IBEX Corporation, SA. Illustra (Informix, Inc.) Matisse Software, Inc. O2 Technology, Inc. Objectivity, Inc. Object Design, Inc. ONTOS, Inc. POET Software Corporation UniSQL Unisys Corporation (OSMOS) Versant Object Technology

Page 4: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

ODMG (Object Data Management Group)

• Provides a standard model for object databases (Object Model)

• Supports object definition via ODL• Supports object querying via OQL• Supports a binding with OOL (Three

langusges : C++, Java, SMALTALK).

Page 5: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

The Object Model of ODMGObjects and Literals

• The basic building blocks of the object model are– Objects – Literlas

• An object has four characteristics1. Identifier: unique system-wide identifier2. Name: unique within a particular database and/or program; it is

optional3. Lifetime: persistent vs transient4. Structure: specifies how object is constructed by the type constructor

and whether it is an atomic object

• A literal has a current value but not an identifier• Three types of literals

1. atomic: predefined; basic data type values (e.g., short, float, boolean, char)

2. structured: values that are constructed by type constructors (e.g., date, struct variables)

3. collection: a collection (e.g., array) of values or objects

Page 6: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

The Object Model of ODMG Interface and Class Definition

ODMG supports two concepts for specifying object types Interface & Class Both have behaviors (operations) and state (attributes and relationships)

Interface• An interface is a specification of

the abstract behavior of an object type

• State properties of an interface (i.e., its attributes and relationships) cannot be inherited from

• Objects cannot be instantiated from an interface

Class• A class is a specification of

abstract behavior and state of an object type

• A class is Instantiable• Supports “extends”

inheritance to allow both state and behavior inheritance among classes

• Multiple inheritance via “extends” is not allowed

Page 7: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Object Definition Language (ODL)

• ODL supports semantics constructs of ODMG• ODL is independent of any programming

language• ODL is used to create object specification

(classes and interfaces)• ODL is not used for database manipulation

Page 8: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

ODMG Interface Definition:ODL Examples

interface is ODMG’s keyword for class/type

interface Date:Object {enum weekday{sun,mon,tue,wed,thu,fri,sat};enum Month{jan,feb,mar,…,dec};unsigned short year();unsigned short month();unsigned short day();…boolean is_equal(in Date other_date);};

enumeration types (Enum),

Page 9: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

A Very Simple ClassODL Examples

• A very simple, straightforward class definition class Degree {

attribute string college;attribute string degree;attribute string year;

};

Page 10: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

A Class With Key and ExtentODL Examples

class Person (extent persons key ssn) {attribute struct Pname {string fname …} name;attribute string ssn;attribute date birthdate;…

short age();}

Page 11: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Inheritance via “:” – An Exampleinterface Shape {attribute struct point {…} reference_point;float perimeter ();…

};

class Triangle: Shape (extent triangles) {attribute short side_1;attribute short side_2;…

};

Page 12: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Object Query Language (OQL)

• OQL is DMG’s query language• OQL works closely with programming

languages such as C++• Embedded OQL statements return objects

that are compatible with the type system of the host language

• OQL’s syntax is similar to SQL with additional features for objects

Page 13: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Simple OQL Queries

• Basic syntax: select…from…where…SELECT d.nameFROM d in departmentsWHERE d.college = ‘Engineering’;

• An entry point to the database is needed for each query

• An extent name (e.g., departments in the above example) may serve as an entry point

Page 14: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

An Example of OQL View

• A view to include students in a department who have a minor:

define has_minor(dept_name) asselect sfrom s in studentswhere s.minor_in.dname=dept_name

• has_minor can now be used in queries

Page 15: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

An Example of an OQL Aggregate Operator

• To compute the average GPA of all seniors majoring in Business:

avg (select s.gpa from s in studentswhere s.class = ‘senior’ ands.majors_in.dname =‘Business’);

Page 16: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Binding with OOLExample : C++ Language Binding

• C++ language binding specifies how ODL constructs are mapped to C++ statements and include:– a C++ class library– a Data Manipulation Language (ODL/OML)– a set of constructs called physical pragmas (to

allow programmers some control over the physical storage concerns)

Page 17: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Class Library

• The class library added to C++ for the ODMG standards uses the prefix d_ for class declarations

• d_Ref<T> is defined for each database class T

• To utilize ODMG’s collection types, various templates are defined, e.g., d_Object<T> specifies the operations to be inherited by all objects

Page 18: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Template Classes

• A template class is provided for each type of ODMG collections:– d_Set<T>– d_List<T>– d_Bag<t>– d_Varray<t>– d_Dictionary<T>

• Thus a programmer can declare:d_Set<d_Ref<Student>>

Page 19: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Data Types of Attributes

• The data types of ODMG database attributes are also available to the C++ programmers via the d _ prefix, e.g., d_Short, d_Long, d_Float

• Certain structured literals are also available, e.g., d_Date, d_Time, d_Intreval

Page 20: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

Object Database Design• For several years, entity-relationship diagrams were the

predominant model ing technique for database design.• OOD Design used Unified Modeling Language (UML) method,

instead of traditional entity-relationship (ER)• The basic similarities between ER and class diagrams are

– entities (classes) are drawn as boxes– binary relationships (associations) are drawn as

connecting lines– n-ary associations (relationships) are drawn as diamonds.

• The main dif­f erences between UML and ER diagrams occur in the details. In UML the multiplicity of an association is shown as simple numerical notation instead of as a cryptic icon

Page 21: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

21

• Object Definition--encapsulation.– Object Name– Properties– Methods

CustomerCustomerIDAddressPhone

AddCustomerDropCustomer

Class name

Properties

Methods

CommercialContactVolumeDiscount

ComputeDiscount

GovernmentContactBalanceDue

BillLateFeesAddCustomer

Inheritance

Polymorphism

Entity: Something in the real world that we wish to describe or track.

Class: Description of an entity, that includes its attributes (properties) and behavior (methods).

Object: One instance of a class with specific data.

Property: A characteristic or descriptor of a class or entity.

Method: A function that is performed by the class.

Association: A relationship between two or more classes.

Page 22: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

22

Class Diagram• Class/Entity (box)• Association/Relationship– Lines– Minimum• 0: optional• 1: required

– Maximum• Arrows• 1, M

Customer

Order

Item

1 … 1

0 … *

0 … *

1 … *

.

.

Page 23: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

23

Sample Association Rules (Multiplicity)

• An order must have exactly 1 customer,– 1 … 1 Minimum of 1– 1 … 1 Maximum of 1

• And at least one item.– 1 … * Minimum of 1– 1 … * Maximum many

• An item can show up on no orders or many orders.– 0 … * Optional (0)– 0 … * Maximum many

Customer

Sale

Item

1 … 1

0 … *

0 … *

1 … *

Page 24: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

24

N-ary Association ExampleEmployeeName...

ComponentCompIDTypeName

ProductProductIDTypeName

EmployeeID Name …11 J oe J ones …12 Maria Rio …

ProductID Type NameA3222 X32 CorvetteA5411 B17 Camaro

EmployeeID CompId ProductID11 563 A322211 872 A322211 563 A541111 872 A541112 563 A322212 882 A322212 888 A322212 883 A5411

CompID Type Name563 W32 Wheel872 M15 Mirror882 H32 Door hinge883 H33 Trunk hinge888 T54 Trunk handle

*

* *Assembly

AssemblyEmployeeIDCompIDProductID

Multiplicity is defined as the number of items that could appear if the other N-1 objectsare fixed. Almost always “many.”

1

1

1

Page 25: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

25

Association Details: Aggregation

SaleSaleDateEmployee

ItemDescriptionCost

* *contains

Aggregation: the Sale consists of a set of Items being sold.

Page 26: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

26

Association Details: Composition

Bicycle

SizeModel Type…

Wheels

RimsSpokes…

1 2built from

Composition: aggregation where the components become the new object.

Crank

ItemIDWeight

Stem

ItemIDWeightSize

1

1

1

1

Bicycle

SizeModel Type…

Wheels

Crank

StemTwo ways to display composition.

Page 27: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

27

Association Details: Generalization

AnimalDateBornNameGenderColorListPrice

MammalLitterSizeTailLengthClaws

FishFreshWaterScaleCondition

SpiderVenomousHabitat

{disjoint}

Page 28: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

28

Inheritance

• Class Definition--encapsulation– Class Name– Properties– Methods

• Inheritance Relationships– Generic classes– Focus on dif­ferences– Polymorphism– Most existing DBMS do not

handle inheritance

AccountsAccountIDCustomerIDDateOpenedCurrentBalanceOpenAccountCloseAccount

Class name

Properties

Methods

Savings AccountsInterestRate

PayInterest

Checking AccountsMinimumBalanceOverdrafts

BillOverdraftFeesCloseAccount

Inheritance

Polymorphism

Page 29: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

29

Multiple Parents

Vehicle

Human PoweredMotorized On-Road Of­f-Road

Car Bicycle

or

Page 30: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

30

Association Details: Reflexive Relationship

Employee manager0…1

worker *

manages

A reflexive relationship is an association from one class back to itself.In this example, an employee can also be a manager of other employees.

Page 31: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

31

Computed Attributes

Denote computed values with a preceding slash (/).

EmployeeNameDateOfBirth/AgePhone…

{Age = Today - DateOfBirth}

Page 32: Object Oriented Data Base. Traditional Data Models : Hierarchical, Network (since mid- 60’s), Relational (since 1970 and commercially since 1982) Object

32

Objects in a Relational Database

CustomerIDAddressPhone

Customer

CustomerIDContactVolumeDiscount

CommercialCustomer

CustomerIDContactBalanceDue

GovernmentCustomer

• Separate inherited classes.• Link by primary key.• Adding a new customer

requires new rows in each table.

• Definitely need cascade delete.