This is the lecture given on Object Oriented database.
Size: 909.97 KB
Language: en
Added: Sep 10, 2011
Slides: 91 pages
Slide Content
DR. SUSHIL KULKARNI
OBJECT DATABASE SYSTEM
2
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
3
PROBLEMS
4
Problems Problems
Poor representation of ‘real world’Entities.
-Relations are too dry, contains only state of a
relation.
-Relationships are not known.
Example:
5
Problems ! Problems !
killed
d_no
dok
p_no
treats
d_no
since
p_no
doctor
d_no
telno
citydname
paddress patient
p_no
pname
6
PROBLEMS ! 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.
7
PROBLEMS ! PROBLEMS !
Reusability (inheritance) of a table is not possibl e.
Options are:
Object-oriented databases ?
Object-relational databases ?
8
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.
Begin with Example Begin with Example
!!
9
Begin with Example Begin with Example
!!
10
Map each class to a relation: Staff(staffNo
, fName, IName,
position, sex, DOB, salary)
Begin with Example Begin with Example
!!
11
Map each subclass to a class and convert to relatio n
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)
Begin with Example Begin with Example
!!
12
Map the hierarchy to a single relation Staff (staffNo
, fName, IName, position, sex, DOB, salary, bonus,
mgrStartDate, sales-Area, carAllowance, typingSpeed, typeFlag)
Begin with Example Begin with Example
!!
13
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, Salepersonneland 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:
ORDBMS Approach ORDBMS Approach
14
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));
Example Example
15
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);
Example Example
16
Let us insert the values: INSERT INTO manager VALUES
(staff(100,’ajay’,’arora’,’production
manager’,’m’,’25-feb 1976’,15000 ),
2000,’12-dec-2002’);
Example Example
17
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));
Example Example
18
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)
New data Models New data Models
19
OO AND ER MODEL OO AND ER MODEL
COMPARISION COMPARISION
N / A
Method
N / A
OID
Primary Key
N / A
Attributes
Instance Variable
Entity set
Class
Entity
Object
Entity definition
Type
EE
--
R MODEL R MODEL
OO DATA MODEL OO DATA MODEL
20
OO
DBMSDBMS
ODBMS ODBMS
Object Oriented
Features Conventional DBMS Conventional DBMS Features Features
++
OO Concepts
OO Data model
OOPL
Data accessibility
Persistence
Back up & recovery
Transaction
Concurrency
Security
21
OO
DBMSDBMS
ODBMS is the
MS
process methods applied for
DB
data structure, which is complied with
O
objects.
ODBMS = O * DB * MS ODBMS = O * DB * MS
22
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 existin g
programming languages.
Object database management systems extend the objec t
programming language with transparently persistent
data, concurrency control, data recovery, associati ve
queries, and other database capabilities.
ODBMS ODBMS
23
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 sys tem. Object Database (ODBMS) for Java, written entirely in Java, and
compliant with the Java Data Objects (JDO) standard developed
By Sun.
ODBMS ODBMS
24
The object-oriented data model allows the 'real world' to be
modeled more closely.
ODBMSsallow 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 (C AD),
CASE, Office Information Systems (OIS), and Multimedia
Systems. The enriched modeling capabilities of OODBMSs have
made them suitable for these applications.
Advantages Advantages
25
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 objec ts.
Disadvantages Disadvantages
26
OROR
DBMSDBMS
ORDBMS is the
MS
process methods applied for
DB
data structure, which is complied with
O
object and
R
Relational concepts.
ORDBMS = ODBMS + RDBMS
= (O + R) * DB * MS.
ORDBMS = ODBMS + RDBMS ORDBMS = ODBMS + RDBMS
= (O + R) * DB * MS. = (O + R) * DB * MS.
27
This system simply puts an object oriented front en d on a
relational database (RDBMS). When applications inter face
to this type of database, it will normally interfac e 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.
ORDBMS ORDBMS
28
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.
Advantages Advantages
29
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.
Disadvantages Disadvantages
30
OBJECT
31
Object 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.
3221
Object Attribute
( Instance Variables)
Attributes
-contains current state of an object.
-Known as instance variables in OOenvironment.
33
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.
3426
Object : PERSON
State: Attribute Value Attribute Name [email protected] Email
9967770659 Cell no.
22345643 Home Tel no.
17/3/1986 DOB
Aditi First name
Shekhar Middle name
Tatkare Last name
E12345 PAN
These are the simple or primitive attributes
35
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATION REPRESENTATION
NAME s
ADDRESS s
DOB s
SEX s
AGE i
EMPLOYEE
AditiS. Tatkare
112, Malabar Hill ..
17-March-1986
F
25
SHARED REPRESENTATION FOR ALL OBJECTS OF THE
CLASS EMPLOYEE
SHARED REPRESENTATION FOR ALL OBJECTS OF THE
CLASS EMPLOYEE
INSTANCE VARIABLES
INSTANCE VARIABLES
OBJECT INSTANCES
OBJECT INSTANCES
36
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.
37
Method Components
sum=0
Method=sum
Sum = sum +1/x
Return (sum)
Return the sum
38
Depiction of an Object
39
DATA TYPES
FOR
ATTRIBUTES
4021
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.
4126
Object : PERSON ( cont’d)
Attribute Value Attribute Name
HR, Accounts Dept *
Street Address, House Number, City, State
Pin
Address *
*Represents an attribute represent one or more attributes.
Let us consider few attributes for Person object: Let us consider few attributes for Person object:
4221
Abstract Data Type
To add address information for a person , we have t o
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 primitiv e
data type.
4321
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.
44
STRUCTURED TYPE
USING ORACLE
45
Structured Type: Object Type
S
Structured type are type constructor . For example the
structured type for object person is given below using oracle: S
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.
46
Create EMP Table
S
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.
47
EMP Structure
S
Use DESC command to see the table structure.
SQL> DESC EMP
Name Null? Type
----------------------- -------- ------------
EMPID NOT NULL NUMBER
EMPLOYEE PERSON
48
Insert into EMP
S
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,‘Aditi',‘Shekhar',‘Tatkare',
'17-may-1986','22345643',120000));
1 row created.
49
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,‘Aditi',‘Shekhar',‘Tatkare',
'17-march-1986','22345643',120000)
50
METHODS
5126
Modeling Object Behavior :
Methods
Method
- Defines behavior of an object, as a set of
encapsulated operations.
We can store methods in TYPEobjects. We use
MEMBER FUNCTIONor MEMBER PROCEDUREin
CREATE TYPEstatement. Then we put the
definition of the method in CREATE TYPE BODY
statement.
52
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.
53
OID
54
Object Identity 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 i s,
its state).
–
Invisible to the user.
55
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATION REPRESENTATION
NAME Aditi S. Tatkare
ADDRESS 112, Malabar Hill.
DOB 17-March-1986
SEX F
AGE 25
EMPLOYEE OID X 20
STATE OF EMPLOYEE OBJECT INSTANCE
STATE OF EMPLOYEE OBJECT INSTANCE
INSTANCE
VARIABLE
VALUES
INSTANCE
VARIABLE
VALUES
SYSTEM
GENERATED
SYSTEM
GENERATED
56
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATION REPRESENTATION
F_NAME s
M_NAME s
L_NAME s
NAME
DEFINING THREE ABSTRACT DATA TYPE
DEFINING THREE ABSTRACT DATA TYPE
BLDG.NO i
STREET s
CITY s
STATE s
PIN i
ADDRESS
DAY i
MONTH i
YEAR i
DOB
57
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATION REPRESENTATION
NAME
ADDRESS
DOB
SEX
AGE
EMPLOYEEOBJECT REPRESENTATION FOR INSTANCES OF THE
CLASS EMPLOYEE WITH ADT’S
OBJECT REPRESENTATION FOR INSTANCES OF THE
CLASS EMPLOYEE WITH ADT’S
NAME
ADDRESS
DOB
SEX
AGE
Data Types
58
F_NAMEAditi
M_NAME S.
L_NAME Tatkare
NAME OID X 201
BLDG.NO 112
STREET Malabar Hill
CITY Mumbai
STATE MAHA.
PIN 400018
ADDRESS OID X 202
DAY 17
MONTH 3
YEAR 1987
DOB OID X 203
NAME X 201
ADDRESS X 202
DOB X 203
SEX F
AGE 25
EMPLOYEE OID X 20
OBJECT SCHEMA: GRAPHICAL REPRESENTATION OBJECT SCHEMA: GRAPHICAL REPRESENTATION
59
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 !
60
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.
6125
Advantages of OIDs
They are efficient.
They are fast.
They cannot be modified by the user.
They are independent of content.
Value + OID =
object
62
INHERITANCE
63
Inheritance
64
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:
65
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.
66
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.
67
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.
68
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:
69
Inheritance
SELECT TREAT(contact AS student_typ).major FROM
contacts;
TREAT(CONTACTASSTUDENT_TYP).MA
------------------------------
HISTORY
PHYSICS
70
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
71
COLLECTION
TYPE
72
Database Design For ORDBMS
Database designer can get an opportunity to use ric h
variety of data types for ORDBMS.
Creating Collection Data types:
• A
varray
is an ordered collection of elements.
• A
nestedtable
can have any number of elements.
73
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.
74
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 relations.
75
Nested Relations
Motivation:
o
Permit non-atomic domains (atomic ≡≡≡≡indivisible)
o
Example of non-atomic domain: set of integers,or set of
tuples
o
Allows more intuitive modeling for applications with
complex data
Intuitive definition:
o
allow relations whenever we allow atomic (scalar) values
—relations within relations
o
Retains mathematical foundation of relational model
o
Violates first normal form.
76
Example of Nested Relations
Example: library information system
Each book has
o
title,
o
a set of authors,
o
Publisher, and
o
a set of keywords
Non-1NF relation books
77
1NF Version of Nested Relation
1NF version of books
flat-books
78
4NF Decomposition of Nested Relation
Remove awkwardness of flat-booksby assuming that the
following multivalued dependencies hold:
o
title author
o
title keyword
o
title pub-name, pub-branch
Decompose flat-docinto 4NF using the schemas:
o
(title, author)
o
(title, keyword)
o
(title, pub-name, pub-branch)
79
4NF Decomposition of Nested Relation
80
Example: Nested Table Type
CREATE TYPE BeerType AS OBJECT (
name CHAR(20),
kind CHAR(10),
color CHAR(10)
);
/
CREATE TYPE BeerTableType AS
TABLE OF BeerType;
/
81
Example: Nested Table Type
Use
BeerTableType
in a
Manfs
relation that
stores the set of beers by each manufacturer in
one tuplefor that manufacturer.
CREATE TABLE Manfs
(
name CHAR(30),
addr CHAR(50),
beers beerTableType
);
82
Storing Nested Relations
Oracle doesn’t really store each nested table as a separate
relation ---it just makes it look that way.
Rather, there is one relation R in which all the tuplesof all
the nested tables for one attribute Aare stored.
Declare in CREATE TABLE by:
NESTED TABLE ASTORE AS R
83
Example: Storing Nested Tables
CREATE TABLE Manfs (
name CHAR(30),
addr CHAR(50),
beers beerTableType
)
NESTED TABLE beers STORE AS BeerTable;
86
ORDBMS Vs RDBMS
Comparison Between Object-Relational and Relational tables: S
Using ORDBMS:
CREATE TABLE emp
(empid number,
employee person);
S
Using RDBMS:
CREATE TABLE EMP
( empid number,...)
CREATE TABLE address
(addr_type varchar2(10),...)
CREATE TABLE phone
(ph_type varchar2(12),...)
87
Represented using referenced attributes
implemented using OIDs
Binary relations are represented using their
cardinalities:
(a) 1:1 relationships
(b) 1:M relationships
(c) M:N relationships
RELATIONSHIPS
88
1:1 RELATIONSHIPS
Bno: B3
Address: V.N. Road
Tel_no: 22040256
Staff: {OID4, OID 5,…}
Property:{OID2, OID 3,…}
Manager:
OID 6
BRANCH: OID1
sno:SG5
Name: AditiGovitrikar
Address: 77, KambalaHill
Position: Manager
Tel_no: 2380 3336
Sex: F
DOB: 3-Jan-85
Bno: OID 1
MANAGER: OID6
89
1:M RELATIONSHIPS
Bno: B3
Address : V.N. Road
Tel_no: 22040256
Staff: {
OID4
, OID 5,…}
Property:{
OID2
,
OID 3
,…}
Manager: OID 6
BRANCH :
OID1
pno:PG6
Address: 12,Cuff Parade
Type: Flat
Sno: OID4
Bno:
OID 1
PROPERY_FOR RENT:
OID2
pno:PG16
Address: 15,Cuff Parade
Type: Flat
Sno: OID4
Bno:
OID 1
PROPERY_FOR RENT:
OID3
Sno: SG14
Name: Amir Khan
Address 14, Hughes Road
Tel_no: 22214185
Bno:
OID 1
Property:{OID2, OID 3,…}
SALES_STAFF:
OID4
90
Branch instance OID1 references a Manager
instance OID6
If user deletes manager instance without
updating the branch instance accordingly,
referential integrity is lost
REFERENTIAL INTEGRITY
Techniques to handle referential integrity:
Do not allow the user to explicit delete objects
Allow user to delete/ modified objects when
they are no longer required