Anda di halaman 1dari 40

Database Technology (CS 744 )

Database Technology

Concepts for Object-oriented Databases

Outline
Part I: OO DB
Concepts for Object-oriented Databases Object database standard & languages and design Object relational and extended relational databases Overview of database types and database applications

Part II
3/17/2012 Abrehet M. 2

Database Technology

Concepts for Object-oriented Databases

Outline(cont.)
Part II: Distributed Database System
Distributed DBMS Architecture Distributed Database Design Overview of Query Processing Query Decomposition and Data Localization Optimization of Distributed Queries

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

Why OODB?
Traditional database models and systems has shortcomings to develop complex DB application. Complex database applications:
Geographic Information Systems, Multimedia (audio, image, video)

It demands:
longer duration transactions, data types for storing images or large textual items, define non-standard application specific operations.

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

Introduction
Prerequisites are: Relational databases and SQL Object oriented programming

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

Introduction
OODB
DBMS persistence Storage management concurrency recovery querying OOPL types & classes complex objects object identity encapsulation class hierarchy Polymorphism
Abrehet M. 6

3/17/2012

Database Technology

Concepts for Object-oriented Databases

Introduction
Review of Object Oriented Programming Concepts Different object oriented database technologies

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

Object Oriented PL Concepts


Classes and objects Object identity Inheritance and class hierarchies Aggregation Encapsulation Polymorphism (overriding & overloading )

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

Classes and Objects


Similar objects form a class Class defines abstract behavior and abstract state
class Fraction { private: long Numerator; long Denominator; reduce(); public: Fraction (long n, long d) { Numerator = n; Denominator = d; reduce(); }

void print () { cout << Numerator << "/" << Denominator; }

}; // End of class definition


3/17/2012 Abrehet M. 9

Database Technology

Concepts for Object-oriented Databases

Classes and Objects


In OOPL -Objects instead of Variables. Objects-User defined complex data types Object has two components:
state (value)- attribute as in RM. behavior (operations)- Manipulating Data.
Fraction f1 (3, 4); Fraction f2 (1, 7); f1.plus(f2); f1.print ();

3/17/2012

Abrehet M.

10

Database Technology

Concepts for Object-oriented Databases

Objects
An object is described by four characteristics
Identifier: a system-wide unique id for an object Name: an object may also have a unique name in DB (optional) Lifetime: determines if the object is persistent or transient Structure: Construction of objects using type constructors

3/17/2012

Abrehet M.

11

Database Technology

Concepts for Object-oriented Databases

Objects
The state (current value) of a complex object may be constructed from other objects (or other values) by using certain type constructors
Can be represented by (i,c,v) i is an unique id c is a type constructor v is the object state
3/17/2012 Abrehet M. 12

Database Technology

Concepts for Object-oriented Databases

Objects
Constructors
Basic types: atom, tuple and set
atom- basic data types Set- a set of OIDs {i1 , i2, ..., in}, a tuple of the form <al:il, a2:i2, ..., an:in>,

Collection type: list, bag and array


List-ordered list [i1 , i2, ..., in] of OIDs of objects of the same type. Array-the state of the object is a single dimensional array of OIDs.

Same as list but bag can have duplicate elements.

3/17/2012

Abrehet M.

13

Database Technology

Concepts for Object-oriented Databases

Example

3/17/2012

Abrehet M.

14

Database Technology

Concepts for Object-oriented Databases

Objects
Complex objects:
01 = (i1 ,atom, 'Houston') O2 = (i2, atom, 'Bellaire') 03 = (i3, atom, 'Sugarland') 04 = (i4, atom, 5) 05 = (i5, atom, 'Research') 06 = (i6, atom, '1988-05-22') 07 = (i7, set, {i1, i2, i3}) 09 = (i9, tuple, <MANAGER:i12, MANAGER_START_DATE:i6)

3/17/2012

Abrehet M.

15

Database Technology

Concepts for Object-oriented Databases

Classes and Objects


Objects in an OOPL - transient objects. Objects OODB - persistent objects.
the objects persist beyond program termination can be retrieved and shared by other programs.

A combination OODB with OOPL provides persistent and shared object capabilities. Object structure of arbitrary complexity allows necessary information that describes the object.

3/17/2012

Abrehet M.

16

Database Technology

Concepts for Object-oriented Databases

Classes and Objects

3/17/2012

Abrehet M.

17

Database Technology

Concepts for Object-oriented Databases

Object identity
In OOPL:
Each object gets a unique identifier: OID. OIDs need not be specified explicitly. This OID does not change during the whole lifetime of the object. (when the object's values change).

In OODB:
Used for objects (representation of real world object) not to lose their integrity and identity. as primary key in relational model
3/17/2012 Abrehet M. 18

Database Technology

Concepts for Object-oriented Databases

Inheritance
class Point {private: int x, y; public: Point (int px = 0, int py = 0) {x=px; y=py;} move (int dx, int dy) {x+=dx; y+=dy;} int draw (); } subclass class Rectangle: public Point {private: int height, width; public: Rectangle (int x, int y, int height, int width); int draw (); } A rectangle class has attributes x, y, width and height. It allows to develop the data types of a system incrementally.
3/17/2012 Abrehet M. 19

Database Technology

Concepts for Object-oriented Databases

OODB: Inheritance

3/17/2012

Abrehet M.

20

Database Technology

Concepts for Object-oriented Databases

Possible state in relation Model


Author AuthorName Bday Publication Title year AuthorName

Article

Title

year

Bpage

Epage

ISBN

Book

Title

year

ISBN

Price

3/17/2012

Abrehet M.

21

Database Technology

Concepts for Object-oriented Databases

Java implementation
public class Author { private long id; Private String name; Private Date birthday; privateSet<Publication> publications; Author() { } public Author(String name) {this.name = name; this.publications= new HashSet<Publication>();} ... }
3/17/2012

public class Publication { private String title; Private int year; Private List<Author> authors; Public Publication(String title) {this.title= title; this.authors= new ArrayList<Author>();} public String getTitle() {return this.title;} public void setTitle(String title) {this.title= title;} ... }
Abrehet M. 22

Database Technology

Concepts for Object-oriented Databases

Java implementation
public class Article extends Publication { private long Beginpage; private long Endpage; Article() { } ... } public class Book extends Publication { private float price; Book() { }

... }

3/17/2012

Abrehet M.

23

Database Technology

Concepts for Object-oriented Databases

Multiple & Selective Inheritance

3/17/2012

Abrehet M.

24

Database Technology

Concepts for Object-oriented Databases

Aggregation
Objects may consist of component objects
class Line { private: Point start, end; int linewidth; public: Line (int xs, int ys, int xe, int ye, int lw); int draw (); }

Line is an aggregation of initial point and endpoint(objects of Point class).


3/17/2012 Abrehet M. 25

Database Technology

Concepts for Object-oriented Databases

Encapsulation- information hiding


Methods are functions belonging to a class. Object state is only modified through public methods. In OODB objects will have :
visible attribute - directly accesses by query. hidden attribute - accessed by predefined operations (update).

3/17/2012

Abrehet M.

26

Database Technology

Concepts for Object-oriented Databases

Polymorphism
public class GeoObject { private String shape; float Area; Point ReferencePoint; public class Rectangle extends GeoObject { private float Width, Height; Rectangle() {Shape='rectangle' } Area(float W, float H) { Area=W*H;} ... }

... }

3/17/2012

Abrehet M.

27

Database Technology

Concepts for Object-oriented Databases

Polymorphism
public class Triangle extends GeoObject { private float height, base; Triangle() {Shape=triangle' }
Area(float B, float H) { Area=.;}

public class Circle extends GeoObject { private float radius; Circle() {Shape=Circle' }
Area(float radus) { Area=.;}

... }

... }

Area implementation differ for each subtype of GEOMETRCOBJECT


3/17/2012 Abrehet M. 28

Database Technology

Concepts for Object-oriented Databases

What is Object Oriented Database?


A database system that incorporates all the important object-oriented concepts Some additional features
Unique Object identifiers Persistent object handling

3/17/2012

Abrehet M.

29

Database Technology

Concepts for Object-oriented Databases

Advantages of OODBS
Designer can specify the structure of objects and their behavior (methods) Better interaction with object-oriented languages such as Java and C++ Definition of complex and user-defined types Encapsulation of operations and user-defined methods
3/17/2012 Abrehet M. 30

Database Technology

Concepts for Object-oriented Databases

Object Query Language (OQL)


Declarative query language Not computationally complete Syntax based on SQL (select, from, where) Additional flexibility (queries with user defined operators and types)

3/17/2012

Abrehet M.

31

Database Technology

Concepts for Object-oriented Databases

Example of OQL query


The following is a sample query what are the names of the black product?
Select distinct p.name From products p Where p.color = black

Valid in both SQL and OQL, but results are different.

3/17/2012

Abrehet M.

32

Database Technology

Concepts for Object-oriented Databases

Result of the query (SQL)


Original table
Product no P1 P2 P3 Name Ford Mustang Toyota Celica Mercedes SLK Color Black Green Black

Result

Name
Ford Mustang Mercedes SLK
3/17/2012

- The statement queries a relational database. => Returns a table with rows.
Abrehet M. 33

Database Technology

Concepts for Object-oriented Databases

Result of the query (OQL)


Original table
Product no P1 P2 P3 Name Ford Mustang Toyota Celica Mercedes SLK Color Black Green Black

Result String Ford Mustang String Mercedes SLK

- The statement queries a objectoriented database => Returns a collection of objects.


34

3/17/2012

Abrehet M.

Database Technology

Concepts for Object-oriented Databases

3/17/2012

Abrehet M.

35

Database Technology

Concepts for Object-oriented Databases

DB with object and relational access

3/17/2012

Abrehet M.

36

Database Technology

Concepts for Object-oriented Databases

Relational Databases
Data organised as tuples in relations. Link between data tuples.
primary and foreign keys

Relational model is very simple


only basic concepts references need to be simulated restricted type system no user-defined types

Lack of semantic modelling.


3/17/2012 Abrehet M. 37

Database Technology

Concepts for Object-oriented Databases

Object-Relational Impedance Mismatch

Object-oriented application development and relational data management results in clash of two incompatible models. Code to map between models is considerable overhead, costly and hard to maintain
3/17/2012 Abrehet M. 38

Database Technology

Concepts for Object-oriented Databases

OODB: object identity


Data represented as objects
object identity (unique ) attributes and methods references, relationships, associations

Extensible type hierarchy


user-defined types, abstract data types single or multiple inheritance overloading, overriding, late binding
3/17/2012 Abrehet M. 39

Database Technology

Concepts for Object-oriented Databases

Abstract Data Types (ADT)


Abstract data types define the behavior of data, but hide the implementation. Classes are suitable to define ADTs. Example: Stack
stacks for integer numbers stacks for floating point numbers

3/17/2012

Abrehet M.

40

Anda mungkin juga menyukai