Sei sulla pagina 1di 78

OBJECT DATABASE SYSTEM

SUSHIL KULKARNI
Object Database System :
Objectives
◆ 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
◆ Poor representation of ‘real world’ Entities.

- Relations are too dry, contains only state of a


relation.
- Relationships are not known.

◆ Example:

4
Problems !

treats
killed
doctor patient

d_no d_no
d_no p_no
p_no p pname
dname
_no

telno city since


dok
paddress

5
PROBLEMS !
◆ 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.

◆ 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 !

◆ 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
◆ The best solution of all above problems is in

Object Relational Database Management System.

◆ 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 13

with syntax of Oracle 9i is explained here below:


Example
Creation of an object staff:
CREATE TYPE staff AS OBJECT(
staffno number(4) primary key,
fname varchar(20),
lname varchar(20),
position varchar(10),
sex varchar(1),
DOB date,
salary number(8,2)); 14
Example
The object staff can be referenced in table Manager as one
of its attribute as shown below:
CREATE TABLE manager(
staff_detail staff,
bonus number(5),
mgrstartdate date);

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 E- R MODEL
Type Entity definition
Object Entity
Class Entity set
Instance Variable Attributes
N/A Primary Key
OID N/A
Method N/A

19
ODBMS
Object Oriented OO Concepts
Features OO Data model
OOPL

ODBMS + Data accessibility


Persistence
Back up & recovery
Conventional DBMS Transaction
Features Concurrency
Security
20
ODBMS
ODBMS = O * DB * MS

ODBMS is the MS process methods applied for


DB data structure, which is complied with O
objects.

21
ODBMS
◆ 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
ODBMS
Following is the one of the approach for designing an
object-oriented database:
◆ The user will create classes, objects, inheritance and
so on.
◆ Database system will store and manage these objects
and classes.
◆ Translation layer is required to map the objects
created by user into objects of the database system.
Object Database (ODBMS) for Java, written entirely in Java, and
compliant with the Java Data Objects (JDO) standard developed
23
Advantages
◆ 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 24

made them suitable for these applications.


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

◆ Lack of support for views.


◆ No 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
◆ 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.

28
Disadvantages
◆ 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.

29
OBJECT
30
Object
◆ 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
◆ 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.

33
Object : PERSON
Attribute Name State: Attribute Value
PAN E12345
Last name Dixit
Middle name Ajay
First name Suhas
DOB 12/5/1959
Home Tel no. 24145643
Cell no. 9967770658
Email 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 s
ADDRESS s
Sameer A. Sathe
112, L.N.Street ..
DOB s
23-NOV-1970
SEX s
M
AGE i
30

INSTANCE VARIABLES OBJECT INSTANCES 35


Methods
◆ 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.

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

◆ Simple attribute are conventional attributes like


number, string ,which takes on literal values.
◆ They are also called primitive attributes.

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

*Represents an attribute represent one or more attributes.

26
41
Abstract Data Type
◆ Toadd address information for a person , we have to
consider separate attributes: Street Address, House
Number, City , State and Pin using primitive data
types.

◆ With abstract data typing, we can create a new data


type and manipulate the data as if it were primitive
data type.

21
42
Operations on ADT
◆ DBMS allows to store and retrieve images using
CLOB and BLOB like an object of any other type
such as number.

◆ One 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
STRUCTURED TYPE
USING ORACLE

44
Structured Type: Object Type
◆ 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
);
/
 Type created.
45
Create EMP Table

◆ 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

◆Use DESC command to see the table structure.


 
SQL> DESC EMP
Name Null? Type
----------------------- -------- ------------
EMPID NOT NULL NUMBER
EMPLOYEE PERSON

47
Insert into EMP

◆ 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

◆ 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
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
◆ 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 SYSTEM


GENERATED
NAME Sameer A. Sathe
ADDRESS 112, L.N.STREET..
INSTANCE
DOB 23-NOV-1970 VARIABLE
SEX M VALUES
AGE 30

55
OBJECT SCHEMA: GRAPHICAL
REPRESENTATION

DEFINING THREE ABSTRACT DATA TYPE

NAME ADDRESS DOB


F_NAME s BLDG.NO i DAY i
M_NAME s STREET s MONTH i
L_NAME s CITY s YEAR i
STATE s
PIN i

56
OBJECT SCHEMA: GRAPHICAL
REPRESENTATION

OBJECT REPRESENTATION FOR INSTANCES OF THE


CLASS EMPLOYEE WITH ADT’S

EMPLOYEE Data Types


NAME NAME
ADDRESS ADDRESS
DOB DOB
SEX SEX
AGE AGE

57
OBJECT SCHEMA: GRAPHICAL REPRESENTATION

NAME OID X 201


EMPLOYEE OID X 20
F_NAMESameer
NAME X 201
M_NAME A.
ADDRESS X 202
L_NAME Sathe
DOB X 203
SEX M
AGE 30

ADDRESS OID X 202


DOB OID X 203
BLDG.NO 112
DAY 23 STREET N.L.Street
MONTH 11 CITY Mumbai
YEAR 1970 STATE MAHA.
58

PIN 400018
Object Identity ≠ Object Equality
◆ 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
Object Identity - Implementation

◆ 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
Advantages of OIDs
◆ They are efficient.

◆ They are fast.

◆ They cannot be modified by the user.

◆ They are independent of content.

Value + OID = object


25
61
INHERITANCE

62
Inheritance

63
Inheritance
◆ 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:

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;
/ 65

Type Created.
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
◆ 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:

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
◆ 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.

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

◆ Not in 1NF

◆ Example:
dept = (dno, manager, employees, projects, locations)
employees = (ename, dependents)
projects = (pname, ploc)
locations = (dloc)
dependents = (dname, age)
75
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);
◆ Using RDBMS:
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
78
Community: http://tech.groups.yahoo.com/group/dbmsnotes/

Potrebbero piacerti anche