Chapt 1 odbms
Upcoming SlideShare
Loading in...5
×
 

Chapt 1 odbms

on

  • 4,333 views

This is the lecture given on Object Oriented database.

This is the lecture given on Object Oriented database.

Statistics

Views

Total Views
4,333
Views on SlideShare
4,331
Embed Views
2

Actions

Likes
1
Downloads
154
Comments
0

1 Embed 2

http://www.slashdocs.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Chapt 1 odbms Chapt 1 odbms Presentation Transcript

    • OBJECT DATABASE SYSTEM DR. SUSHIL KULKARNI
    • Object Database System : ObjectivesProblems with RDBMSWhat is ODBMS and ORDBMS ?Advantages and DisadvantagesOO/ER model comparison and objectschemaObject type : Attributes and MethodsCollection 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 dnametelno 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 DatabaseFor the purposes of discussion, consider the inheritancehierarchy which has a super class:Staffand 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 relationStaff (staffNo, fName, IName, position, sex, DOB, salary, bonus, mgrStartDate, sales-Area, carAllowance, typingSpeed, typeFlag) 12
    • ORDBMS ApproachThe best solution of all above problems is inObject Relational Database Management System.For example: In Oracle ,we can create an object Staffin database and then we can create three differenttables namely Manager, Salepersonnel and Secretary,each refer to object created Staff as one of itsattribute.The whole process of designing the above database 13with syntax of Oracle 9i is explained here below:
    • ExampleCreation 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
    • ExampleThe object staff can be referenced in table Manager as oneof its attribute as shown below:CREATE TABLE manager( staff_detail staff, bonus number(5), mgrstartdate date); 15
    • ExampleLet us insert the values:INSERT INTO manager VALUES(staff(100,’ajay’,’arora’,’production manager’,’m’,’25-feb 1976’,15000 ), 2000,’12-dec-2002’); 16
    • ExampleSimilarly 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 ModelsIn response to the increasing complexity ofdatabase applications, two new data models haveemerged:Object-Oriented Data Model (OODM)Object-Relational Data Model (ORDM) 18
    • OO AND ER MODEL COMPARISIONOO DATA MODEL E- R MODELType Entity definitionObject EntityClass Entity setInstance Variable AttributesN/A Primary KeyOID N/AMethod N/A 19
    • ODBMS Object Oriented OO Concepts Features OO Data model OOPLODBMS + Data accessibility Persistence Back up & recovery TransactionConventional DBMSFeatures Concurrency Security 20
    • ODBMS ODBMS = O ** DB ** MS ODBMS = O DB MSODBMS is the MS process methods applied forDB data structure, which is complied with Oobjects. 21
    • ODBMSIntegrating database capabilities with objectprogramming language capabilities, the result is anobject-oriented database management system orODBMS.An ODBMS makes database objects appear asprogramming language objects in one or more existingprogramming languages.Object database management systems extend the objectprogramming language with transparently persistentdata, concurrency control, data recovery, associativequeries, and other database capabilities. 22
    • ODBMSFollowing is the one of the approach for designing anobject-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, andcompliant with the Java Data Objects (JDO) standard developed 23By Sun.
    • AdvantagesThe object-oriented data model allows the real world to bemodeled more closely.ODBMSs allow new data types to be built from existing types.More expressive query language then SQL.Applicability to advanced database applicationsThere are many areas where traditional DBMSs have not beenparticularly successful, such as, Computer-Aided Design (CAD),CASE, Office Information Systems (OIS), and MultimediaSystems. The enriched modeling capabilities of OODBMSs have 24made 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 DBdata structure, which is complied with O object and RRelational concepts. 26
    • ORDBMSThis system simply puts an object oriented front end on arelational database (RDBMS). When applications interfaceto this type of database, it will normally interface asthough the data is stored as objects.The system will convert the object information into datatables with rows and columns and handle the data thesame as a relational database. 27
    • AdvantagesThe object type can be reuse and share in different application.ORDBMS provides increased productivity both for thedeveloper and for the end user.It is just an extension of existing relational approach. 28
    • DisadvantagesComplexity increases and associated costs.Simplicity and purity of the relational model are lost.Because the ORDBMS converts data between an object orientedformat and RDBMS format, speed performance of the databaseis degraded substantially. This is due to the additional conversionwork the database must do. 29
    • OBJECT 30
    • ObjectUniquely identifiable entity that contains both theattributes that describe the state of a real-worldentity and the actions associated with it.Definition is similar to definition of an entity,however, object encapsulates both state andbehavior; 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 StateSet of values that object’s attributes have at agiven time.Can vary, although its OID remains the same.To change the object’s state, change the valuesof the object’s attributes. 33
    • Object : PERSONAttribute Name State: Attribute ValuePAN E12345Last name TatkareMiddle name ShekharFirst name AditiDOB 17/3/1986Home Tel no. 22345643Cell no. 9967770659Email 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 25INSTANCE VARIABLES INSTANCE VARIABLES OBJECT INSTANCES OBJECT INSTANCES 35
    • MethodsCode that performs a specific operation on object’sdata.Used to change the object’s attribute values or toreturn the value of selected object attributes.Represent real-world actions. 36
    • Method ComponentsMethod=sum sum=0 Sum = sum +1/xReturn (sum) Return the sum 37
    • Depiction of an Object 38
    • DATA TYPES FORATTRIBUTES 39
    • Data types for attributesTwo 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 TypeTo add address information for a person , we have toconsider separate attributes: Street Address, HouseNumber, City , State and Pin using primitive datatypes.With abstract data typing, we can create a new datatype and manipulate the data as if it were primitivedata type. 42 21
    • Operations on ADTDBMS allows to store and retrieve images usingCLOB and BLOB like an object of any other typesuch as number.One can define operations on an image data typesuch as compress, rotate, shrink and crop. ADT is the combination of an atomic data type andits 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 TableCreating Table with ADT Object DatatypeNow 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 EMPWe 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)------------------------------------------------------- 1001person(122,Sushil,Trymbak,Kulkarni, 29-jun- 1984,24144386,10000) 1002person(124,‘Aditi,‘Shekhar,‘Tatkare, 17-march-1986,22345643,120000) 49
    • METHODS 50
    • Modeling Object Behavior : MethodsMethod - Defines behavior of an object, as a set ofencapsulated operations.We can store methods in TYPE objects. We useMEMBER FUNCTION or MEMBER PROCEDURE inCREATE TYPE statement. Then we put thedefinition of the method in CREATE TYPE BODYstatement. 51 26
    • Create Method Data typeCREATE 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 IdentityObject identifier (OID) assigned to object when it iscreated 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 GENERATEDNAME Aditi S. Tatkare INSTANCE INSTANCEADDRESS 112, Malabar Hill. VARIABLE VARIABLEDOB 17-March-1986 VALUES VALUESSEX FAGE 25 55
    • OBJECT SCHEMA: GRAPHICAL REPRESENTATION DEFINING THREE ABSTRACT DATA TYPE DEFINING THREE ABSTRACT DATA TYPE NAME ADDRESS DOBF_NAME s BLDG.NO i DAY iM_NAME s STREET s MONTH iL_NAME s CITY s YEAR i STATE s PIN i 56
    • OBJECT SCHEMA: GRAPHICAL REPRESENTATIONOBJECT REPRESENTATION FOR INSTANCES OF THEOBJECT REPRESENTATION FOR INSTANCES OF THECLASS EMPLOYEE WITH ADT’SCLASS EMPLOYEE WITH ADT’SEMPLOYEE Data TypesNAME NAMEADDRESS ADDRESSDOB DOBSEX SEXAGE 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 Equality2 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 - ImplementationIn RDBMS, object identity is value-based: primarykey is used to provide uniqueness.Primary keys do not provide type of object identityrequired 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 OIDsThey 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
    • InheritanceThe definition of an object type determines whethersubtypes can be derived from that type.To permit subtypes, the object type must be definedas not final. This is done by including the NOTFINAL keyword in its type declaration.For example: 64
    • InheritanceCREATE 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;/ 65Type Created.
    • InheritanceCREATE 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
    • InheritanceCREATE TABLE contacts ( contact person_typ, contact_date DATE );INSERT INTO contactsVALUES (person_typ (12, Hemant Agashe, 99765432414), 24 Jun 2003 );1 row created.INSERT INTO contactsVALUES (student_typ(51, Sameer Bhende, 9967452317, 12, HISTORY),24 Jun 2003 );1 row created.INSERT INTO contactsVALUES (part_time_student_typ(52, Uday Chitale, 9978561234, 14,PHYSICS, 20), 24 Jun 2003 );1 row created. 67
    • InheritanceAttributes in general can be accessed using thedot notation. Attributes of a subtype of a row orcolumns declared type can be accessed with theTREAT function.For example: 68
    • InheritanceSELECT TREAT(contact AS student_typ).major FROM contacts;TREAT(CONTACTASSTUDENT_TYP).MA------------------------------HISTORYPHYSICS 69
    • InheritanceSQL> SELECT TREAT(contact AS student_typ).major , TREAT(contact AS person_typ).name FROM contacts;TREAT(CONTACTASSTUDENT_TYP).MA TREAT(CONTACTASPERSON_TYP).NAME------------------------------ ------------------------------ Hemant AgasheHISTORY Sameer BhendePHYSICS Uday Chitale 70
    • COLLECTION TYPE 71
    • Database Design For ORDBMSDatabase designer can get an opportunity to use richvariety 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 ORDBMSIf 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 ORDBMSIf 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 RelationsMotivation: 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 dataIntuitive 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 RelationsExample: library information systemEach book has o title, o a set of authors, o Publisher, and o a set of keywordsNon-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 TypeCREATE TYPE BeerType AS OBJECT ( name CHAR(20), kind CHAR(10), color CHAR(10));/CREATE TYPE BeerTableType AS TABLE OF BeerType;/ 80
    • Example: Nested Table TypeUse BeerTableType in a Manfs relation thatstores the set of beers by each manufacturer inone tuple for that manufacturer. CREATE TABLE Manfs ( name CHAR(30), addr CHAR(50), beers beerTableType ); 81
    • Storing Nested RelationsOracle doesn’t really store each nested table as a separaterelation --- it just makes it look that way.Rather, there is one relation R in which all the tuples of allthe nested tables for one attribute A are stored.Declare in CREATE TABLE by: NESTED TABLE A STORE AS R 82
    • Example: Storing Nested TablesCREATE TABLE Manfs ( name CHAR(30), addr CHAR(50), beers beerTableType)NESTED TABLE beers STORE AS BeerTable; 83
    • Another Example of Nested RelationExample: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 RDBMSComparison 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
    • RELATIONSHIPSRepresented using referenced attributesimplemented using OIDsBinary relations are represented using theircardinalities: (a) 1:1 relationships (b) 1:M relationships (c) M:N relationships 87
    • 1:1 RELATIONSHIPS BRANCH: OID1 MANAGER: OID6Bno: B3 sno:SG5Address: V.N. Road Name: Aditi GovitrikarTel_no: 22040256 Address: 77, Kambala HillStaff: {OID4, OID 5,…} Position: ManagerProperty:{OID2, OID 3,…} Tel_no: 2380 3336Manager: OID 6 Sex: F DOB: 3-Jan-85 Bno: OID 1 88
    • 1:M RELATIONSHIPS BRANCH :OID1 PROPERY_FOR RENT: OID2Bno: B3 pno:PG6Address : V.N. Road Address: 12,Cuff ParadeTel_no: 22040256 Type: FlatStaff: {OID4, OID 5,…} Sno: OID4Property:{OID2, OID 3,…} Bno: OID 1Manager: OID 6 PROPERY_FOR RENT: OID3 SALES_STAFF: OID4 pno:PG16 Address: 15,Cuff ParadeSno: SG14 Type: FlatName: Amir Khan Sno: OID4Address 14, Hughes Road Bno: OID 1Tel_no: 22214185Bno: OID 1 89Property:{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 lostTechniques 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 91Community: http://tech.groups.yahoo.com/group/dbmsnotes/