chapt 1 odbms
DESCRIPTION
This is the lecture given on Object Oriented database.TRANSCRIPT
![Page 1: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/1.jpg)
DR. SUSHIL KULKARNI
OBJECT DATABASE SYSTEM
![Page 2: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/2.jpg)
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
![Page 3: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/3.jpg)
3
PROBLEMS
![Page 4: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/4.jpg)
4
ProblemsProblems
� Poor representation of ‘real world’ Entities.
- Relations are too dry, contains only state of a
relation.
- Relationships are not known.
� Example:
![Page 5: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/5.jpg)
5
Problems !Problems !
killed
d_no
dok
p_no
treats
d_no
since
p_no
doctor
d_no
telno city
dname
paddress
patient
p_no pname
![Page 6: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/6.jpg)
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.
![Page 7: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/7.jpg)
7
PROBLEMS !PROBLEMS !
� Reusability (inheritance) of a table is not possible.
Options are:
Object-oriented databases ?
Object-relational databases ?
![Page 8: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/8.jpg)
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 ExampleBegin with Example!!
![Page 9: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/9.jpg)
9
Begin with ExampleBegin with Example!!
![Page 10: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/10.jpg)
10
Map each class to a relation:
Staff(staffNo, fName, IName,
position, sex, DOB, salary)
Begin with ExampleBegin with Example!!
![Page 11: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/11.jpg)
11
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)
Begin with ExampleBegin with Example!!
![Page 12: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/12.jpg)
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 ExampleBegin with Example!!
![Page 13: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/13.jpg)
13
� The best solution of all above problems is in
Object Relational Database Management System.
� For example: In Oracle ,we can create an object Staffin 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:
ORDBMS ApproachORDBMS Approach
![Page 14: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/14.jpg)
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));
ExampleExample
![Page 15: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/15.jpg)
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);
ExampleExample
![Page 16: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/16.jpg)
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’);
ExampleExample
![Page 17: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/17.jpg)
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));
ExampleExample
![Page 18: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/18.jpg)
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 ModelsNew data Models
![Page 19: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/19.jpg)
19
OO AND ER MODEL OO AND ER MODEL
COMPARISIONCOMPARISION
N / AMethod
N / AOID
Primary KeyN / A
AttributesInstance Variable
Entity setClass
EntityObject
Entity definitionType
EE-- R MODELR MODELOO DATA MODELOO DATA MODEL
![Page 20: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/20.jpg)
20
OODBMSDBMS
ODBMSODBMS
Object Oriented
Features
Conventional DBMS Conventional DBMS
FeaturesFeatures
++
OO Concepts
OO Data model
OOPL
Data accessibility
Persistence
Back up & recovery
Transaction
Concurrency
Security
![Page 21: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/21.jpg)
21
OODBMSDBMS
ODBMS is the MS process methods applied for
DB data structure, which is complied with O
objects.
ODBMS = O * DB * MSODBMS = O * DB * MS
![Page 22: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/22.jpg)
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 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.
ODBMSODBMS
![Page 23: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/23.jpg)
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 system.
Object Database (ODBMS) for Java, written entirely in Java, and
compliant with the Java Data Objects (JDO) standard developed
By Sun.
ODBMSODBMS
![Page 24: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/24.jpg)
24
� 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.
AdvantagesAdvantages
![Page 25: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/25.jpg)
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 objects.
DisadvantagesDisadvantages
![Page 26: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/26.jpg)
26
ORORDBMSDBMS
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.
![Page 27: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/27.jpg)
27
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.
ORDBMSORDBMS
![Page 28: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/28.jpg)
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.
AdvantagesAdvantages
![Page 29: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/29.jpg)
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.
DisadvantagesDisadvantages
![Page 30: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/30.jpg)
30
OBJECT
![Page 31: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/31.jpg)
31
ObjectObject
� 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.
![Page 32: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/32.jpg)
3221
Object Attribute
( Instance Variables)
Attributes - contains current state of an object.
- Known as instance variables in OO environment.
![Page 33: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/33.jpg)
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.
![Page 34: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/34.jpg)
3426
Object : PERSON
State: Attribute ValueAttribute Name
9967770659Cell no.
22345643Home Tel no.
17/3/1986DOB
AditiFirst name
ShekharMiddle name
TatkareLast name
E12345PAN
These are the simple or primitive attributes
![Page 35: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/35.jpg)
35
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATIONREPRESENTATION
NAME s
ADDRESS s
DOB s
SEX s
AGE i
EMPLOYEE
Aditi S. Tatkare112, Malabar Hill ..17-March-1986F25
SHARED REPRESENTATION FOR ALL OBJECTS OF THE
CLASS EMPLOYEE
SHARED REPRESENTATION FOR ALL OBJECTS OF THE
CLASS EMPLOYEE
INSTANCE VARIABLESINSTANCE VARIABLES OBJECT INSTANCESOBJECT INSTANCES
![Page 36: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/36.jpg)
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.
![Page 37: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/37.jpg)
37
Method Components
sum=0
Method=sum
Sum = sum +1/x
Return (sum) Return the sum
![Page 38: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/38.jpg)
38
Depiction of an Object
![Page 39: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/39.jpg)
39
DATA TYPES
FORATTRIBUTES
![Page 40: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/40.jpg)
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.
![Page 41: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/41.jpg)
4126
Object : PERSON ( cont’d)
Attribute ValueAttribute Name
HR, AccountsDept *
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:
![Page 42: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/42.jpg)
4221
Abstract Data Type
�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.
�With abstract data typing, we can create a new data
type and manipulate the data as if it were primitive
data type.
![Page 43: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/43.jpg)
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.
![Page 44: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/44.jpg)
44
STRUCTURED TYPE
USING ORACLE
![Page 45: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/45.jpg)
45
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.
![Page 46: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/46.jpg)
46
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.
![Page 47: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/47.jpg)
47
EMP Structure
�Use DESC command to see the table structure.
SQL> DESC EMP
Name Null? Type
----------------------- -------- ------------
EMPID NOT NULL NUMBER
EMPLOYEE PERSON
![Page 48: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/48.jpg)
48
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,‘Aditi',‘Shekhar',‘Tatkare',
'17-may-1986','22345643',120000));
1 row created.
![Page 49: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/49.jpg)
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)
![Page 50: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/50.jpg)
50
METHODS
![Page 51: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/51.jpg)
5126
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.
![Page 52: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/52.jpg)
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.
![Page 53: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/53.jpg)
53
OID
![Page 54: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/54.jpg)
54
Object IdentityObject 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.
![Page 55: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/55.jpg)
55
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATIONREPRESENTATION
NAME Aditi S. Tatkare
ADDRESS 112, Malabar Hill.
DOB 17-March-1986
SEX F
AGE 25
EMPLOYEE OID X 20
STATE OF EMPLOYEE OBJECT INSTANCESTATE OF EMPLOYEE OBJECT INSTANCE
INSTANCE
VARIABLE
VALUES
INSTANCE
VARIABLE
VALUES
SYSTEM
GENERATED
SYSTEM
GENERATED
![Page 56: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/56.jpg)
56
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATIONREPRESENTATION
F_NAME s
M_NAME s
L_NAME s
NAME
DEFINING THREE ABSTRACT DATA TYPEDEFINING THREE ABSTRACT DATA TYPE
BLDG.NO i
STREET s
CITY s
STATE s
PIN i
ADDRESS
DAY i
MONTH i
YEAR i
DOB
![Page 57: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/57.jpg)
57
OBJECT SCHEMA: GRAPHICAL OBJECT SCHEMA: GRAPHICAL
REPRESENTATIONREPRESENTATION
NAME
ADDRESS
DOB
SEX
AGE
EMPLOYEE
OBJECT 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
![Page 58: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/58.jpg)
58
F_NAME Aditi
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 REPRESENTATIONOBJECT SCHEMA: GRAPHICAL REPRESENTATION
![Page 59: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/59.jpg)
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 !
![Page 60: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/60.jpg)
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.
![Page 61: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/61.jpg)
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
![Page 62: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/62.jpg)
62
INHERITANCE
![Page 63: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/63.jpg)
63
Inheritance
![Page 64: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/64.jpg)
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:
![Page 65: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/65.jpg)
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.
![Page 66: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/66.jpg)
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.
![Page 67: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/67.jpg)
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.
![Page 68: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/68.jpg)
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:
![Page 69: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/69.jpg)
69
Inheritance
SELECT TREAT(contact AS student_typ).major FROM
contacts;
TREAT(CONTACTASSTUDENT_TYP).MA
------------------------------
HISTORY
PHYSICS
![Page 70: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/70.jpg)
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
![Page 71: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/71.jpg)
71
COLLECTION
TYPE
![Page 72: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/72.jpg)
72
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.
![Page 73: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/73.jpg)
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.
![Page 74: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/74.jpg)
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.
![Page 75: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/75.jpg)
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.
![Page 76: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/76.jpg)
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
![Page 77: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/77.jpg)
77
1NF Version of Nested Relation
1NF version of books
flat-books
![Page 78: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/78.jpg)
78
4NF Decomposition of Nested Relation
� Remove awkwardness of flat-books by assuming that the following multivalued dependencies hold:
o title author
o title keyword
o title pub-name, pub-branch
� Decompose flat-doc into 4NF using the schemas:
o (title, author)
o (title, keyword)
o (title, pub-name, pub-branch)
![Page 79: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/79.jpg)
79
4NF Decomposition of Nested Relation
![Page 80: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/80.jpg)
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;
/
![Page 81: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/81.jpg)
81
Example: Nested Table Type
� Use BeerTableType in a Manfs relation that
stores the set of beers by each manufacturer in
one tuple for that manufacturer.
CREATE TABLE Manfs (
name CHAR(30),
addr CHAR(50),
beers beerTableType
);
![Page 82: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/82.jpg)
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 tuples of all
the nested tables for one attribute A are stored.
� Declare in CREATE TABLE by:
NESTED TABLE A STORE AS R
![Page 83: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/83.jpg)
83
Example: Storing Nested Tables
CREATE TABLE Manfs (
name CHAR(30),
addr CHAR(50),
beers beerTableType
)
NESTED TABLE beers STORE AS BeerTable;
![Page 84: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/84.jpg)
84
Another Example of Nested Relation
� Example:
dept = (dno, manager, employees, projects, locations)
employees = (ename, dependents)
projects = (pname, ploc)
locations = (dloc)
dependents = (dname, age)
![Page 85: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/85.jpg)
85
Another Example of Nested Relation
![Page 86: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/86.jpg)
86
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),...)
![Page 87: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/87.jpg)
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
![Page 88: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/88.jpg)
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: Aditi Govitrikar
Address: 77, Kambala Hill
Position: Manager
Tel_no: 2380 3336
Sex: F
DOB: 3-Jan-85
Bno: OID 1
MANAGER: OID6
![Page 89: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/89.jpg)
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
![Page 90: Chapt 1 odbms](https://reader034.vdocuments.mx/reader034/viewer/2022042505/54c680b24a795956088b456f/html5/thumbnails/90.jpg)
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