OBJECT DATABASE SYSTEM


       DR. 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_no             pname
                  dname



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
                     Transaction
Conventional DBMS
Features             Concurrency
                     Security
                                          20
ODBMS
        ODBMS = O ** DB ** MS
        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


By Sun.
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
   ORDBMS = ODBMS + RDBMS
          = (O + R) ** DB ** MS.
          = (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.




                                                    32
                                                    21
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               Tatkare
Middle name             Shekhar
First name              Aditi
DOB                     17/3/1986
Home Tel no.            22345643
Cell no.                9967770659
Email                   aditi@gmail.com




           These are the simple or primitive attributes   34
                                                          26
OBJECT SCHEMA: GRAPHICAL
        REPRESENTATION

   SHARED REPRESENTATION FOR ALL OBJECTS OF THE
   SHARED REPRESENTATION FOR ALL OBJECTS OF THE
   CLASS EMPLOYEE
   CLASS EMPLOYEE


      EMPLOYEE
    NAME       s
    ADDRESS    s
                       Aditi S. Tatkare
    DOB        s
                       112, Malabar Hill ..
                       17-March-1986
    SEX        s
                       F
    AGE         i
                       25

INSTANCE VARIABLES
 INSTANCE VARIABLES       OBJECT INSTANCES
                          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.




                                                40
                                                21
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.




                                                               41
                                                               26
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.


                                                       42
                                                       21
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.
                                                     43
                                                     21
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,‘Aditi',‘Shekhar',‘Tatkare',
            '17-may-1986','22345643',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,‘Aditi',‘Shekhar',‘Tatkare',
            '17-march-1986','22345643',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.
                                                 51
                                                 26
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
        STATE OF EMPLOYEE OBJECT INSTANCE



       EMPLOYEE OID X 20              SYSTEM
                                      SYSTEM
                                      GENERATED
                                      GENERATED
NAME    Aditi S. Tatkare
                                       INSTANCE
                                        INSTANCE
ADDRESS 112, Malabar Hill.             VARIABLE
                                        VARIABLE
DOB    17-March-1986
                                       VALUES
                                       VALUES
SEX     F
AGE     25


                                                   55
OBJECT SCHEMA: GRAPHICAL
        REPRESENTATION

      DEFINING THREE ABSTRACT DATA TYPE
      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
OBJECT REPRESENTATION FOR INSTANCES OF THE
CLASS EMPLOYEE WITH ADT’S
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_NAME Aditi
 NAME       X 201
                       M_NAME S.
 ADDRESS   X 202
                       L_NAME Tatkare
 DOB       X 203
 SEX       F
 AGE       25

                     ADDRESS OID X 202
   DOB OID X 203
                     BLDG.NO    112
   DAY  17           STREET    Malabar Hill
   MONTH 3           CITY       Mumbai
   YEAR 1987         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
                                       61
                                       25
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 relations.



                                                  74
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.
                                                              75
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




                                      76
1NF Version of Nested Relation
        1NF version of books




             flat-books
                                 77
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)

                                                          78
4NF Decomposition of Nested Relation




                                   79
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;
/
                                   80
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
   );


                                                  81
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




                                                                 82
Example: Storing Nested Tables

CREATE TABLE Manfs (
     name CHAR(30),
     addr        CHAR(50),
     beers beerTableType
)
NESTED TABLE beers STORE AS BeerTable;




                                         83
Another Example of Nested Relation


Example:
dept = (dno, manager, employees, projects, locations)
employees = (ename, dependents)
projects = (pname, ploc)
locations = (dloc)
dependents = (dname, age)



                                                   84
Another Example of Nested Relation




                                     85
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),...)                          86
RELATIONSHIPS

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



                                               87
1:1 RELATIONSHIPS

     BRANCH: OID1               MANAGER: OID6
Bno: B3                     sno:SG5
Address: V.N. Road          Name: Aditi Govitrikar
Tel_no: 22040256            Address: 77, Kambala Hill
Staff: {OID4, OID 5,…}      Position: Manager
Property:{OID2, OID 3,…}    Tel_no: 2380 3336
Manager: OID 6              Sex: F
                            DOB: 3-Jan-85
                            Bno: OID 1               88
1:M RELATIONSHIPS
          BRANCH :OID1        PROPERY_FOR RENT: OID2

Bno: B3                       pno:PG6

Address : V.N. Road           Address: 12,Cuff Parade

Tel_no: 22040256              Type: Flat

Staff: {OID4, OID 5,…}        Sno: OID4

Property:{OID2, OID 3,…}      Bno: OID 1

Manager: OID 6                PROPERY_FOR RENT: OID3

      SALES_STAFF: OID4       pno:PG16
                              Address: 15,Cuff Parade
Sno: SG14
                              Type: Flat
Name: Amir Khan
                              Sno: OID4
Address 14, Hughes Road
                              Bno: OID 1
Tel_no: 22214185
Bno: OID 1
                                                        89

Property:{OID2, OID 3,…}
REFERENTIAL INTEGRITY

    Branch instance OID1 references a Manager
    instance OID6
    If user deletes manager instance without
    updating the branch instance accordingly,
    referential integrity is lost
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
                                                       90
Email: sushiltry@yahoo.co.in
                                                           91
Community: http://tech.groups.yahoo.com/group/dbmsnotes/

Chapt 1 odbms

  • 1.
    OBJECT DATABASE SYSTEM DR. SUSHIL KULKARNI
  • 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 2
  • 3.
  • 4.
    Problems Poor representationof ‘real world’ Entities. - Relations are too dry, contains only state of a relation. - Relationships are not known. Example: 4
  • 5.
    Problems ! treats killed doctor patient d_no d_no d_no p_no p_no p_no pname dname telno city since dok paddress 5
  • 6.
    PROBLEMS ! Homogeneous datastructure • 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
  • 7.
    PROBLEMS ! Reusability (inheritance)of a table is not possible. Options are: Object-oriented databases ? Object-relational databases ? 7
  • 8.
    Begin with Example! StoringObjects 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
  • 9.
  • 10.
    Begin with Example! Mapeach class to a relation: Staff(staffNo, fName, IName, position, sex, DOB, salary) 10
  • 11.
    Begin with Example! Mapeach 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
  • 12.
    Begin with Example! Mapthe hierarchy to a single relation Staff (staffNo, fName, IName, position, sex, DOB, salary, bonus, mgrStartDate, sales-Area, carAllowance, typingSpeed, typeFlag) 12
  • 13.
    ORDBMS Approach The bestsolution 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:
  • 14.
    Example Creation of anobject 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
  • 15.
    Example The object staffcan 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
  • 16.
    Example Let us insertthe values: INSERT INTO manager VALUES (staff(100,’ajay’,’arora’,’production manager’,’m’,’25-feb 1976’,15000 ), 2000,’12-dec-2002’); 16
  • 17.
    Example Similarly we createother 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
  • 18.
    New data Models Inresponse to the increasing complexity of database applications, two 'new' data models have emerged: Object-Oriented Data Model (OODM) Object-Relational Data Model (ORDM) 18
  • 19.
    OO AND ERMODEL 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
  • 20.
    ODBMS ObjectOriented OO Concepts Features OO Data model OOPL ODBMS + Data accessibility Persistence Back up & recovery Transaction Conventional DBMS Features Concurrency Security 20
  • 21.
    ODBMS ODBMS = O ** DB ** MS ODBMS = O DB MS ODBMS is the MS process methods applied for DB data structure, which is complied with O objects. 21
  • 22.
    ODBMS Integrating database capabilitieswith 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
  • 23.
    ODBMS Following is theone 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 By Sun.
  • 24.
    Advantages The object-oriented datamodel 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.
  • 25.
    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
  • 26.
    ORDBMS ORDBMS = ODBMS + RDBMS ORDBMS = ODBMS + RDBMS = (O + R) ** DB ** MS. = (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
  • 27.
    ORDBMS This system simplyputs 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
  • 28.
    Advantages The object typecan 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
  • 29.
    Disadvantages Complexity increases andassociated 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
  • 30.
  • 31.
    Object Uniquely identifiable entitythat 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
  • 32.
    Object Attribute ( Instance Variables) Attributes - contains current state of an object. - Known as instance variables in OO environment. 32 21
  • 33.
    Object State Set ofvalues 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
  • 34.
    Object : PERSON AttributeName State: Attribute Value PAN E12345 Last name Tatkare Middle name Shekhar First name Aditi DOB 17/3/1986 Home Tel no. 22345643 Cell no. 9967770659 Email aditi@gmail.com These are the simple or primitive attributes 34 26
  • 35.
    OBJECT SCHEMA: GRAPHICAL REPRESENTATION SHARED REPRESENTATION FOR ALL OBJECTS OF THE SHARED REPRESENTATION FOR ALL OBJECTS OF THE CLASS EMPLOYEE CLASS EMPLOYEE EMPLOYEE NAME s ADDRESS s Aditi S. Tatkare DOB s 112, Malabar Hill .. 17-March-1986 SEX s F AGE i 25 INSTANCE VARIABLES INSTANCE VARIABLES OBJECT INSTANCES OBJECT INSTANCES 35
  • 36.
    Methods Code that performsa 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
  • 37.
    Method Components Method=sum sum=0 Sum = sum +1/x Return (sum) Return the sum 37
  • 38.
    Depiction of anObject 38
  • 39.
    DATA TYPES FOR ATTRIBUTES 39
  • 40.
    Data types forattributes 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. 40 21
  • 41.
    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. 41 26
  • 42.
    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. 42 21
  • 43.
    Operations on ADT DBMSallows 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. 43 21
  • 44.
    STRUCTURED TYPE USING ORACLE 44
  • 45.
    Structured Type: ObjectType 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
  • 46.
    Create EMP Table CreatingTable with ADT Object Datatype Now we will create EMP table for employees. CREATE TABLE EMP ( EMPID Number primary key, EMPLOYEE PERSON); Table created. 46
  • 47.
    EMP Structure Use DESC command to see the table structure. SQL> DESC EMP Name Null? Type ----------------------- -------- ------------ EMPID NOT NULL NUMBER EMPLOYEE PERSON 47
  • 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. 48
  • 49.
    Select statement onEMP 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) 49
  • 50.
  • 51.
    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. 51 26
  • 52.
    Create Method Datatype 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
  • 53.
    OID 53
  • 54.
    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
  • 55.
    OBJECT SCHEMA: GRAPHICAL REPRESENTATION STATE OF EMPLOYEE OBJECT INSTANCE STATE OF EMPLOYEE OBJECT INSTANCE EMPLOYEE OID X 20 SYSTEM SYSTEM GENERATED GENERATED NAME Aditi S. Tatkare INSTANCE INSTANCE ADDRESS 112, Malabar Hill. VARIABLE VARIABLE DOB 17-March-1986 VALUES VALUES SEX F AGE 25 55
  • 56.
    OBJECT SCHEMA: GRAPHICAL REPRESENTATION DEFINING THREE ABSTRACT DATA TYPE 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
  • 57.
    OBJECT SCHEMA: GRAPHICAL REPRESENTATION OBJECT REPRESENTATION FOR INSTANCES OF THE OBJECT REPRESENTATION FOR INSTANCES OF THE CLASS EMPLOYEE WITH ADT’S CLASS EMPLOYEE WITH ADT’S EMPLOYEE Data Types NAME NAME ADDRESS ADDRESS DOB DOB SEX SEX AGE AGE 57
  • 58.
    OBJECT SCHEMA: GRAPHICALREPRESENTATION NAME OID X 201 EMPLOYEE OID X 20 F_NAME Aditi NAME X 201 M_NAME S. ADDRESS X 202 L_NAME Tatkare DOB X 203 SEX F AGE 25 ADDRESS OID X 202 DOB OID X 203 BLDG.NO 112 DAY 17 STREET Malabar Hill MONTH 3 CITY Mumbai YEAR 1987 STATE MAHA. 58 PIN 400018
  • 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 ! 59
  • 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. 60
  • 61.
    Advantages of OIDs Theyare efficient. They are fast. They cannot be modified by the user. They are independent of content. Value + OID = object 61 25
  • 62.
  • 63.
  • 64.
    Inheritance The definition ofan 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
  • 65.
    Inheritance CREATE TYPE person_typAS 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.
  • 66.
    Inheritance CREATE TYPE employee_typUNDER 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
  • 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. 67
  • 68.
    Inheritance Attributes in generalcan 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
  • 69.
    Inheritance SELECT TREAT(contact ASstudent_typ).major FROM contacts; TREAT(CONTACTASSTUDENT_TYP).MA ------------------------------ HISTORY PHYSICS 69
  • 70.
    Inheritance SQL> SELECT TREAT(contactAS 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
  • 71.
    COLLECTION TYPE 71
  • 72.
    Database Design ForORDBMS 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
  • 73.
    Database Design ForORDBMS 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
  • 74.
    Database Design ForORDBMS 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. 74
  • 75.
    Nested Relations Motivation: oPermit 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. 75
  • 76.
    Example of NestedRelations 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 76
  • 77.
    1NF Version ofNested Relation 1NF version of books flat-books 77
  • 78.
    4NF Decomposition ofNested 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) 78
  • 79.
    4NF Decomposition ofNested Relation 79
  • 80.
    Example: Nested TableType CREATE TYPE BeerType AS OBJECT ( name CHAR(20), kind CHAR(10), color CHAR(10) ); / CREATE TYPE BeerTableType AS TABLE OF BeerType; / 80
  • 81.
    Example: Nested TableType 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 ); 81
  • 82.
    Storing Nested Relations Oracledoesn’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 82
  • 83.
    Example: Storing NestedTables CREATE TABLE Manfs ( name CHAR(30), addr CHAR(50), beers beerTableType ) NESTED TABLE beers STORE AS BeerTable; 83
  • 84.
    Another Example ofNested Relation Example: dept = (dno, manager, employees, projects, locations) employees = (ename, dependents) projects = (pname, ploc) locations = (dloc) dependents = (dname, age) 84
  • 85.
    Another Example ofNested Relation 85
  • 86.
    ORDBMS Vs RDBMS ComparisonBetween 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),...) 86
  • 87.
    RELATIONSHIPS Represented using referencedattributes implemented using OIDs Binary relations are represented using their cardinalities: (a) 1:1 relationships (b) 1:M relationships (c) M:N relationships 87
  • 88.
    1:1 RELATIONSHIPS BRANCH: OID1 MANAGER: OID6 Bno: B3 sno:SG5 Address: V.N. Road Name: Aditi Govitrikar Tel_no: 22040256 Address: 77, Kambala Hill Staff: {OID4, OID 5,…} Position: Manager Property:{OID2, OID 3,…} Tel_no: 2380 3336 Manager: OID 6 Sex: F DOB: 3-Jan-85 Bno: OID 1 88
  • 89.
    1:M RELATIONSHIPS BRANCH :OID1 PROPERY_FOR RENT: OID2 Bno: B3 pno:PG6 Address : V.N. Road Address: 12,Cuff Parade Tel_no: 22040256 Type: Flat Staff: {OID4, OID 5,…} Sno: OID4 Property:{OID2, OID 3,…} Bno: OID 1 Manager: OID 6 PROPERY_FOR RENT: OID3 SALES_STAFF: OID4 pno:PG16 Address: 15,Cuff Parade Sno: SG14 Type: Flat Name: Amir Khan Sno: OID4 Address 14, Hughes Road Bno: OID 1 Tel_no: 22214185 Bno: OID 1 89 Property:{OID2, OID 3,…}
  • 90.
    REFERENTIAL INTEGRITY Branch instance OID1 references a Manager instance OID6 If user deletes manager instance without updating the branch instance accordingly, referential integrity is lost 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 90
  • 91.
    Email: sushiltry@yahoo.co.in 91 Community: http://tech.groups.yahoo.com/group/dbmsnotes/