OBJECT DATABASE SYSTEM

SUSHIL KULKARNI

Object Database System : Objectives
x x x x

x x

Problems with RDBMS What is ODBMS and ORDBMS ? Advantages and Disadvantages OO/ER model comparison and object schema Object type : Attributes and Methods Collection types

2

PROBLEMS
3

Problems
x

Poor representation of ‘real world’ Entities. - Relations are too dry, contains only state of a relation. - Relationships are not known.

x

Example:

4

Problems !
doctor
treats killed

patient

d_no

dname

d_no d_no

p_no p_no

p _no

pname

telno

city

since dok
paddress

5

PROBLEMS !
x

Homogeneous data structure • All rows have the same number of attributes. • All values in a column are of the same type. • All attribute values are atomic.

x

Fixed length of data type, Limited data types • Can not store images, audio and video clips. • Spatial, temporal data can not be added.
6

PROBLEMS !
x

Reusability (inheritance) of a table is not possible.

Options are: Object-oriented databases ? Object-relational databases ?

7

Begin with Example!
Storing Objects in a Relational Database For the purposes of discussion, consider the inheritance hierarchy which has a super class: Staff and three subclasses: Manager, SalesPersonnel, Secretary.
8

Begin with Example!

9

Begin with Example!
Map each class to a relation:
Staff(staffNo, fName, IName, position, sex, DOB, salary)

10

Begin with Example!
Map each subclass to a class and convert to relation
Manager (staffNo, fName, IName, position, sex, DOB, salary, bonus, mgrStartDate) SalesPersonnel (staffNo, fName, IName, position, sex, DOB, salary, salesArea, carAllowance) Secretary (staffNo, fName, IName, position, sex, DOB, salary, typingSpeed)
11

Begin with Example!
Map the hierarchy to a single relation

Staff (staffNo, fName, IName, position, sex, DOB, salary, bonus, mgrStartDate, sales-Area, carAllowance, typingSpeed, typeFlag)

12

ORDBMS Approach
x

The best solution of all above problems is in Object Relational Database Management System.

x

For example: In Oracle ,we can create an object Staff in database and then we can create three different tables namely Manager, Salepersonnel and Secretary, each refer to object created Staff as one of its attribute. The whole process of designing the above database with syntax of Oracle 9i is explained here below:

x

13

Example
Creation of an object staff: CREATE TYPE staff AS OBJECT( staffno fname lname position sex DOB number(4) primary key, varchar(20), varchar(20), varchar(10), varchar(1), date,
14

salary number(8,2));

Example
The object staff can be referenced in table Manager as one of its attribute as shown below: CREATE TABLE manager( staff, number(5), date);

staff_detail bonus mgrstartdate

15

Example
Let us insert the values: INSERT INTO manager VALUES (staff(100,’ajay’,’arora’,’production manager’,’m’,’25-feb 1976’,15000 ), 2000,’12-dec-2002’);

16

Example
Similarly we create other tables as shown below:
CREATE TABLE salepersonnel(

staff_detail staff, salearea varchar(25), carallowance number(7)); CREATE TABLE secretary(

staff_detail staff, typingspeed number(3));
17

New data Models
In response to the increasing complexity of database applications, two 'new' data models have emerged: Object-Oriented Data Model (OODM) Object-Relational Data Model (ORDM)

18

OO AND ER MODEL COMPARISION
OO DATA MODEL Type Object Class Instance Variable N/A OID Method E- R MODEL Entity definition Entity Entity set Attributes Primary Key N/A N/A
19

ODBMS
Object Oriented Features OO Concepts OO Data model OOPL Data accessibility Persistence Back up & recovery Transaction Concurrency Security
20

ODBMS

+

Conventional DBMS Features

ODBMS
ODBMS = O * DB * MS

ODBMS is the MS process methods applied for DB data structure, which is complied with O objects.

21

ODBMS
x

Integrating database capabilities with object programming language capabilities, the result is an object-oriented database management system or ODBMS. An ODBMS makes database objects appear as programming language objects in one or more existing programming languages. Object database management systems extend the object programming language with transparently persistent data, concurrency control, data recovery, associative queries, and other database capabilities.
22

x

x

ODBMS
Following is the one of the approach for designing an object-oriented database: The user will create classes, objects, inheritance and so on. x Database system will store and manage these objects and classes. x Translation layer is required to map the objects created by user into objects of the database system.
x

Object Database (ODBMS) for Java, written entirely in Java, and compliant with the Java Data Objects (JDO) standard developed
23

Advantages
x

The object-oriented data model allows the 'real world' to be modeled more closely. ODBMSs allow new data types to be built from existing types. More expressive query language then SQL. Applicability to advanced database applications There are many areas where traditional DBMSs have not been particularly successful, such as, Computer-Aided Design (CAD), CASE, Office Information Systems (OIS), and Multimedia Systems. The enriched modeling capabilities of OODBMSs have made them suitable for these applications.
24

x

x

x

Disadvantages
x

No universally agreed data model for an ODBMS, and most models lack a theoretical foundation. comparison to RDBMSs, the use of ODBMS is still relatively limited. is no standard object-oriented query language.

x In

x There
`

x Lack x No

of support for views.

adequate security mechanisms for accessing objects.
25

ORDBMS
ORDBMS = ODBMS + RDBMS = (O + R) * DB * MS. ORDBMS is the MS process methods applied for DB data structure, which is complied with O object and R Relational concepts.

26

ORDBMS
This system simply puts an object oriented front end on a relational database (RDBMS). When applications interface to this type of database, it will normally interface as though the data is stored as objects. The system will convert the object information into data tables with rows and columns and handle the data the same as a relational database.

27

Advantages
x

The object type can be reuse and share in different application. ORDBMS provides increased productivity both for the developer and for the end user. It is just an extension of existing relational approach.

x

x

28

Disadvantages
x

Complexity increases and associated costs. Simplicity and purity of the relational model are lost. Because the ORDBMS converts data between an object oriented format and RDBMS format, speed performance of the database is degraded substantially. This is due to the additional conversion work the database must do.

x

x

29

OBJECT
30

Object
x

Uniquely identifiable entity that contains both the attributes that describe the state of a real-world entity and the actions associated with it. Definition is similar to definition of an entity, however, object encapsulates both state and behavior; an entity only models state.

31

Object Attribute ( Instance Variables)
Attributes - contains current state of an object. - Known as instance variables in OO environment.

21 32

Object State
x

Set of values that object’s attributes have at a given time. Can vary, although its OID remains the same. To change the object’s state, change the values of the object’s attributes.

x x

33

Object : PERSON
Attribute Name PAN Last name Middle name First name DOB Home Tel no. Cell no. Email State: Attribute Value E12345 Dixit Ajay Suhas 12/5/1959 24145643 9967770658 suhas@in.com

These are the simple or primitive attributes
26 34

OBJECT SCHEMA: GRAPHICAL REPRESENTATION
SHARED REPRESENTATION FOR ALL OBJECTS OF THE CLASS EMPLOYEE

EMPLOYEE NAME ADDRESS DOB SEX AGE s s s s i

Sameer A. Sathe 112, L.N.Street .. 23-NOV-1970 M 30
OBJECT INSTANCES
35

INSTANCE VARIABLES

Methods
x

Code that performs a specific operation on object’s data. Used to change the object’s attribute values or to return the value of selected object attributes. Represent real-world actions.

x

x

36

Method Components

Method=sum

sum=0

Sum = sum +1/x

Return (sum)

Return the sum

37

Depiction of an Object

38

DATA TYPES FOR
ATTRIBUTES
39

Data types for attributes
Two types of attributes: Simple & Abstract
x

Simple attribute are conventional attributes like number, string ,which takes on literal values. They are also called primitive attributes.

x

21 40

Object : PERSON ( cont’d)
Let us consider few attributes for Person object:
Attribute Name Address * Dept * Attribute Value Street Address, House Number, City, State Pin HR, Accounts

*Represents an attribute represent one or more attributes.

26 41

Abstract Data Type
x To

add address information for a person , we have to consider separate attributes: Street Address, House Number, City , State and Pin using primitive data types. abstract data typing, we can create a new data type and manipulate the data as if it were primitive data type.

x With

21 42

Operations on ADT
x DBMS

allows to store and retrieve images using CLOB and BLOB like an object of any other type such as number. can define operations on an image data type such as compress, rotate, shrink and crop. ADT is the combination of an atomic data type and its associated methods.
21 43

x One

x

STRUCTURED TYPE USING ORACLE

44

Structured Type: Object Type
x

Structured type are type constructor . For example the structured type for object person is given below using oracle: Creating Object
CREATE TYPE person AS OBJECT ( PIN number, First_name varchar2(15), Middle_name varchar2(15), Last_name varchar2(15), dob date, Tel_no varchar2(10), salary number, MEMBER FUNCTION raise_sal RETURN NUMBER );

x

/  Type created.

45

Create EMP Table
x

Creating Table with ADT Object Datatype Now we will create EMP table for employees. CREATE TABLE EMP ( EMPID Number primary key, EMPLOYEE PERSON); Table created.

46

EMP Structure

xUse DESC command to see the table structure.   SQL> DESC EMP Name EMPID EMPLOYEE Null? Type ----------------------- -------- -----------NOT NULL NUMBER PERSON

47

Insert into EMP
x

We will now populate our table.

SQL> INSERT INTO EMP(empid, employee) VALUES(1001, person(122,'Sushil','Trymbak','Kulkarni', '29-jun- 1984','24144386',10000));
1 row created.

SQL> INSERT INTO EMP1 (empid, employee) VALUES(1002, person(124,'Suhas','Ramchandra','Dixit', '13-may-1988','24124886',120000)); 1 row created.

48

Select statement on EMP
We can select the records with simple SQL statement. E.g.

SELECT * FROM EMP / EMPID ---------EMPLOYEE(PIN, FIRST_NAME, MIDDLE_NAME, LAST_NAME, DOB, TEL_NO, SALARY)

------------------------------------------------------1001 person(122,'Sushil','Trymbak','Kulkarni', '29-jun- 1984','24144386',10000) 1002 person(124,'Suhas','Ramchandra','Dixit', '13-may-1988','24124886',120000)
49

METHODS
50

Modeling Object Behavior : Methods

x

Method - Defines behavior of an object, as a set of encapsulated operations. We can store methods in TYPE objects. We use MEMBER FUNCTION or MEMBER PROCEDURE in CREATE TYPE statement. Then we put the definition of the method in CREATE TYPE BODY statement.
26 51

x

Create Method Data type
CREATE TYPE BODY person AS MEMBER FUNCTION raise_sal RETURN NUMBER IS BEGIN RETURN salary * 1.1; END; END; / Type body created.

THIS DEFINITION OF FUNCTION IS TO BE WRITTEN AFTHER PERSON TYPE IS CREATED.
52

OID
53

Object Identity
x

Object identifier (OID) assigned to object when it is created that is:
– – – – –

System-generated. Unique to that object. Invariant. Independent of the values of its attributes (that is, its state). Invisible to the user.
54

OBJECT SCHEMA: GRAPHICAL REPRESENTATION
STATE OF EMPLOYEE OBJECT INSTANCE

EMPLOYEE OID X 20 NAME Sameer A. Sathe ADDRESS 112, L.N.STREET.. DOB 23-NOV-1970 SEX M AGE 30

SYSTEM GENERATED

INSTANCE VARIABLE VALUES

55

OBJECT SCHEMA: GRAPHICAL REPRESENTATION
DEFINING THREE ABSTRACT DATA TYPE

NAME F_NAME s M_NAME s L_NAME s

ADDRESS BLDG.NO STREET CITY STATE PIN i s s s i

DOB DAY i MONTH i YEAR i

56

OBJECT SCHEMA: GRAPHICAL REPRESENTATION
OBJECT REPRESENTATION FOR INSTANCES OF THE CLASS EMPLOYEE WITH ADT’S

EMPLOYEE NAME ADDRESS DOB SEX AGE

Data Types NAME ADDRESS DOB SEX AGE

57

OBJECT SCHEMA: GRAPHICAL REPRESENTATION
NAME OID X 201

EMPLOYEE OID X 20 NAME ADDRESS DOB SEX AGE X 201 X 202 X 203 M 30

Sameer M_NAME A. L_NAME Sathe
F_NAME

DOB OID X 203 DAY 23 MONTH 11 YEAR 1970

ADDRESS OID X 202 BLDG.NO STREET CITY STATE PIN 112 N.L.Street Mumbai MAHA. 400018

58

Object Identity ≠ Object Equality
x

2 objects are identical if they have the same OID (o1 == 02) 2 objects are equal if they have the same value (o1 = 02) (o1 == 02) ⇒ (o1 = 02) (o1 = 02) ⇒ (o1 == 02) NON !
59

x

Object Identity - Implementation
x

In RDBMS, object identity is value-based: primary key is used to provide uniqueness. Primary keys do not provide type of object identity required in OO systems: – key only unique within a relation, not across entire system. – key generally chosen from attributes of relation, making it dependent on object state.
60

x

Advantages of OIDs
x

They are efficient. They are fast. They cannot be modified by the user. They are independent of content.

x

x

x

Value + OID = object
25 61

INHERITANCE
62

Inheritance

63

Inheritance
x

The definition of an object type determines whether subtypes can be derived from that type. To permit subtypes, the object type must be defined as not final. This is done by including the NOT FINAL keyword in its type declaration. For example:

x

x

64

Inheritance
CREATE TYPE person_typ AS OBJECT ( pid NUMBER, name VARCHAR2(30), phone VARCHAR2(20)) NOT FINAL; / Type Created. CREATE TYPE student_typ UNDER person_typ ( dept_id NUMBER, major VARCHAR2(30)) NOT FINAL; / Type Created.

65

Inheritance
CREATE TYPE employee_typ UNDER person_typ ( emp_id NUMBER, mgr VARCHAR2(30)); / Type Created. CREATE TYPE part_time_student_typ UNDER student_typ ( number_hours NUMBER); / Type Created.

66

Inheritance
CREATE TABLE contacts ( contact person_typ, contact_date DATE ); INSERT INTO contacts VALUES (person_typ (12, 'Hemant Agashe', '99765432414'), '24 Jun 2003' ); 1 row created. INSERT INTO contacts VALUES (student_typ(51, 'Sameer Bhende', '9967452317', 12, 'HISTORY'),'24 Jun 2003' ); 1 row created. INSERT INTO contacts VALUES (part_time_student_typ(52, 'Uday Chitale', '9978561234', 14,'PHYSICS', 20), '24 Jun 2003' ); 1 row created.
67

Inheritance
x

Attributes in general can be accessed using the dot notation. Attributes of a subtype of a row or column's declared type can be accessed with the TREAT function. For example:

x

68

Inheritance
SELECT TREAT(contact AS student_typ).major FROM contacts; TREAT(CONTACTASSTUDENT_TYP).MA -----------------------------HISTORY PHYSICS

69

Inheritance

SQL> SELECT TREAT(contact AS student_typ).major , TREAT(contact AS person_typ).name FROM contacts; TREAT(CONTACTASSTUDENT_TYP).MA TREAT(CONTACTASPERSON_TYP).NAME ------------------------------ -----------------------------Hemant Agashe HISTORY Sameer Bhende PHYSICS Uday Chitale

70

COLLECTION TYPE
71

Database Design For ORDBMS
x

Database designer can get an opportunity to use rich variety of data types for ORDBMS. Creating Collection Data types: • A varray is an ordered collection of elements. • A nested table can have any number of elements.

x

72

Database Design For ORDBMS

If you need • to store only a fixed number of items, or • to loop through the elements in order, or • to retrieve and manipulate the entire collection as a value, then use a varray.

73

Database Design For ORDBMS

If you need • to run efficient queries on a collection, • handle arbitrary numbers of elements, or • do mass insert/update/delete operations, then use nested tables.

74

The Nested Relational Data Model
x

Not in 1NF Example: dept = (dno, manager, employees, projects, locations) employees = (ename, dependents) projects = (pname, ploc) locations = (dloc) dependents = (dname, age)
75

x

The Nested Relational Data Model

76

ORDBMS Vs RDBMS
Comparison Between Object-Relational and Relational tables: Using ORDBMS: CREATE TABLE emp (empid number, employee person); x Using RDBMS:
x CREATE TABLE EMP ( empid number,...) CREATE TABLE address (addr_type varchar2(10),...) CREATE TABLE phone (ph_type varchar2(12),...)

77

Email: sushiltry@yahoo.co.in, Mob: 9967770658 Community: http://tech.groups.yahoo.com/group/dbmsnotes/

78

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.