0% found this document useful (0 votes)
27 views

Chapter 5-OODB

i uploaded give me whata i wanna in my life

Uploaded by

felmitesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Chapter 5-OODB

i uploaded give me whata i wanna in my life

Uploaded by

felmitesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 66

Chapter 5

.
Object Oriented DBMS

1
Objectives
• OODBMS definitions
• Object Oriented Concepts (Abstraction, Encapsulation & Information hiding)
• Object Identity
• OO Database Design and Implementation
•OO Data modeling and E-R diagramming
•Objects and Attributes
• Drawbacks of relational DBMS
•Storing object in relational database systems
2
Types of DBMS Models

3 3
Cont’d…
• In a Hierarchical database model:-the data is organized in a
tree-like structure. Data is Stored Hierarchically (top down or
bottom up) format.
• The network database model:- allows each child to have
multiple parents. More complex relationships such as the orders,
many-to-many relationship.
• Relational Database model: its most widely used DBMS model,
it easiest, and based on normalizing data in the rows and
columns of the tables.
Its data is stored in fixed structures and manipulated using SQL
4
5.1.OODBMS definitions

What is meant by OODBMS?


• An object-oriented database management system (OODBMS) applies concepts of object-
oriented programming, and applies them to the management of persistent objects on behalf of
multiple users, with capabilities for security, integrity, recovery and contention management.
• An OODBMS, sometimes shortened to ODBMS for object database management system, is a
database management system (DBMS) that supports the modelling and creation of data as
objects.
• In object oriented database , information is represented in the form of an objects.
• OO databases are exactly same as OOP languages. If we can combine the features of relation
model(transaction, concurrency, recovery) to OO databases, the resultant model is as Object
oriented database mode.
• In OODBMS, every entity is considered as object and represented in a table.
Similar objects are classified to classes and subclasses and relationship between two object is
maintained using concept of inverse reference.
What is the use of OODBMS?
• Extensibility. OODBMSs allow new data types to be built from existing types.
• The ability to factor out common properties of several classes and form them into a super-class
that can be shared with sub-classes can greatly reduce redundancy within system is regarded
as one of the main advantages of object orientation.
5
Cont’d…

Some of the feature of OODBMS Figure 5.1 :make up of an object


1.Complexity:OODBMS has the ability to oriented database
represent the complex internal structure(of
object) with multilevel complexity.
2. Inheritance: creating a new object from an
existing object in such a way that new object
inherits all characteristics of an existing object.
3.Encapsulation: it is a data hiding concepts
in OOPL which binds the data and functions
together w/c can manipulate data and not
visible to outside world.
4.Persistency: OODBMS allows to create
persistent object(object remains in memory
even after execution). This feature
automatically solve the problem of recovery
and concurrency.

What are challenges in ORDBMS 6


implementation? Reading assignment
Cont’d…
• An object-oriented database is a collection of object-oriented
programming and relational database. Figure 5.2

7
5.2. Object Oriented Concepts (Abstraction, Encapsulation, and Information hiding)

• Abstraction – encapsulation and information hiding


• Abstraction is the process of identifying the essential aspects of an entity (Object) by ignoring an irrelevant
properties.
• Abstract Data Type (ADT): interface part (operation), implementation part (data structure)
Abstract Data Type (ADT):
 Describes a set of similar objects
 Differs from conventional data types
• Operations are user-defined
• Uses encapsulation
 Definitions needed for creation
• Name , Data representation and Abstract data type operations and constraints
• Encapsulation
• An object has data structure and operations
• It also known as data hiding, is the mechanism whereby the implementation details of a class are kept hidden
from the user.
• Hiding of ADT internals (implementation) is called encapsulation.
• It describes bundling data and methods that work on that data within one unit, like a class in Java.
• Information hiding
• Internal details
• separate the external aspects of an object from its internal details, which are hidden from the outside world.
• Data independence
• We often use encapsulation concept to hide an object's internal representation or state from the outside.
This is called information hiding. 8
• It is a method used in object-oriented programming to hide information within computer code.
What is an ODBMS?

• It is a database management system (DBMS) that supports the modelling and creation of data as objects.
• The objects in OODBMS is the possibility of user-constructed types.
• An object created in a project or application saves into a database as is.
• Object-oriented databases directly deal with data as complete objects.
• All the information comes in one instantly available object package instead of multiple tables.
• Database that stores data elements as objects. It uses object-oriented concepts.
• Object - like an entity in and E-R Diagram.
 Why use ODBMS?
• It use a complex data and a wider variety of data types compared to MySQL data types. Easy to save and
retrieve data quickly.
• Complex data or relationship requirements
 Lack of unique, natural identification
 Large numbers of many to many relationships
 Access using traversals. Graph/Tree structure.
 Frequent use of type codes such as those found in the relational schema
10
Who Uses ODBMS?
• Typical Applications or uses for ODBMS:
• Computer-aided design (CAD)
• Computer-aided software engineering (CASE)
• Multimedia databases
• Images, video, games, etc.
• Office automation systems (OIS)
• Expert database systems
Approaches for ODBMS
• Relational DB model. It extended to use object-oriented concepts. (Object-relational DB)
• DB is Relational
• Programming language is object-oriented

• Object-oriented DB model.
• Application and database use same object-oriented model.
• Uses persistent programming languages.
11
Object-Oriented Concepts, Object
OO Concepts: Objects
• Abstract representation of a real-world entity
• Unique identity
• Embedded properties
• Ability to interact with other objects and self
• Attributes
• Called instance variables
• Domain
• Object state
• Object values at any given time
• Object is an entity containing:
• Variables/Attributes – Object Data
• Relationships – References to other objects
• Methods – Object Functions
• Messages – Accessing Methods
13
Cont’d…
 The basic building blocks of the object model are:
 Objects -
 Literals- a literal has a current value but not an identifier. Three types of
literals. Atomic, structured and collection.

Objects are described by four characteristics


1. Identifier : unique system wide identifier.
2. Name : is used to refer the objects. It is optional
3. Life time
4. Structure: specifies how the object is constructed by using type constructors. It also
Specifies whether the object is atomic or collection type .

14
Object-Oriented Concepts, Class & Encapsulation
Object(ObjCP) and Attributes:
• Class encapsulates the data structure and

operations of the object.


• Internals are hidden from the user.
• User only knows available methods and
• how to call them.

15
Object-Oriented Concepts, Inheritance & Polymorphism
• Inheritance - A class (subclass) can inherit the characteristic of another class
(superclass).
Example: Employee has inherited attributes and methods from Person.

• Polymorphism - Each subclass object can respond differently to same


message by overriding the superclass method.

16
5.3. Object Identity
Object-Oriented Concepts, Object Identifier
• Object Identifier (OID) – The unique OID is maintained by the DBMS.

• ODBMS - Generated automatically by the system.

Example: Reference to Date object in the Employee object for the date hired.

• RDBMS – Primary key. Example: SSN for Employee


• OID (Object Identity):
• Unique to that object
• Not a primary key
• System generated
• Invariant
• Independent of the values of its attributes
• Invisible to the user
• Advantages:
Fast, efficient, independent of content, not changeable by user
17
Cont’d..
Shared Representation for all Objects of the Class Person

Figure 5.3

Figure 5.4
18
OO Concepts: Objects (cont’d...)
• Methods
• Code that performs operation on object’s data
• Has name and body
• Messages
• Invokes method
• Sent to object
• Classes
• Collection of similar objects
• Shares attributes and structure
• Protocol
• Represents object’s public aspect
• Class hierarchy
• Code that performs operation on object’s data
• Has name and body
19
Object Characteristics

Figure 5.5
20
Class Hierarchy
• Superclass
• Subclass
• Class lattice

Figure 5.6 21
Inheritance

• It’s the ability of object to inherit the data structure and behavior of classes above it. Two types of
inheritance. Single and multiple inheritance.
• Single inheritance:
• Class has one immediate superclass

Figure 5.7
22
Inheritance (cont’d...)
• Multiple inheritance:
• Class has more than one immediate superclass

Figure 5.8
23
Method Overriding

• Method redefined at subclass level

Figure 5.9
24
Class-Subclass Relationship

Figure 5.10

Figure 5.11 25
Cont’d…
 Polymorphism - the ability to appear in many forms.
 Ability to process objects differently depending on their data type or
class.
 It is the ability to redefine methods for derived classes.

 Overloading –
 allows the name of a method to be reused within a class definition.
 Overriding –
 allows the name of a property to be redefined in a subclass.
 Dynamic binding - allows the determination of an object’s type and
methods to be deferred until runtime.

26
Overriding Overloading

27
Object Classification
• Simple
– Only single-valued attributes
– No attributes refer to other object
• Composite
– At least one multivalued attribute
– No attributes refer to other object
• Compound
– At least one attribute that references other object
• Hybrid
– Repeating group of attributes
– At least one refers to other object

28
Characteristics of OODBM
• Supports complex objects
• Must be extensible
• Supports encapsulation
• Exhibit inheritance
• Supports object identity

29
OO vs. ER Data
Modeling
Object Oriented ER
Class Entity type
Object Entity instance
Association Relationship
Inheritance of attributes Inheritance of attributes
Inheritance of behavior No representation of
behavior

Object-oriented modeling is frequently accomplished using the Unified


Modeling Language (UML)
30
OO vs. E-R Model Components

Table 5.1
31
5.4. OO Database Design and
Implementation
OODBMS: Database management system(DBMS) integrates
benefits of typical database systems with OODM characteristics
Handles a mix of data types
Follows OO rules
Follows DBMS rules
OO and Database Design:
• Provides data identification and the procedures for data
manipulation
• Data and procedures self-contained entity
• Iterative and incremental
• DBA does more programming
• Lack of standards
32
Cont’d..
Logical & physical layers

3333
5.5. OO Data modeling and E-R diagramming
• E-R Model is used to represent real life scenarios as entities.
• The properties of these entities are their attributes in the ER diagram and
their connections are shown in the form of relationships.
• An ER model is generally considered as a top down approach in data
designing.
Advantages of E - R model
• The data requirements are easily understandable using an E - R model as
it utilizes clear diagrams.
• The E-R model can be easily converted into a relational database.
• The E-R diagram is very easy to understand as it has clearly defined
entities and the relations between them.
Disadvantages of E-R model
• There is no data manipulation language available for an E- R model as it
is a largely abstract concept.
• There are no standard notations for an E - R model. It depends on 34each
Cont’d…
• An example ER-diagram

35
Object Oriented Model(cont’d…)

• Object oriented data model is based on using real life scenarios. In this
model, the scenarios are represented as objects.
• The objects with similar functionalities are grouped together and linked to
different other objects.
Advantages of Object Oriented Model
• Due to inheritance, the data types can be reused in different objects. This
reduces the cost of maintaining the same data in multiple locations.
• The object oriented model is quite flexible in most cases.
• It is easier to extend the design in Object Oriented Model.
Disadvantages of Object Oriented Model
• It is not practically implemented in database systems as it is mostly a
theoretical approach.
• This model can be quite complicated to create and understand.

36
Cont’d…
• An Example OO Data modeling

37
OODBMS Advantages
• More semantic information
• Support for complex objects(Manages Complex data types
more efficiently).
• Extensibility of data types
• May improve performance with efficient caching
• Supports distributions of data across networks more
efficiently.
• Versioning
• Allows reusability of objects(generic objects can be used in
many applications).
• Inheritance speeds development and application
• Potential to integrate DBMSs into single environment
• Matches the object-oriented application design: it reduces
code, execution time and paging, Real world data model 38
and Easier Navigation
OODBMS Disadvantages
• Strong opposition from the established RDBMSs
• Lack of theoretical foundation
• Throwback to old pointer systems
• More complicated than the relational model. Takes longer to learn.
• Not as efficient when data and relations are simple.
• Low market presence
• Lack of compatibility between different OODBMSs
• Steep learning curve
• Still developing
Lack of accepted standards ad hoc query language
Lack of development tools/business data design and management
tools
Change is more likely to occur in model

39
OO Influences on Relational Model

• Extensibility of new user-defined (abstract) data


types
• Complex objects
• Inheritance
• Procedure calls (rules or triggers)
• System-generated identifiers (OID surrogates)

40
5.6. ObjCP and Attributes
Java & ODB Example
• Example of how to access data in an ODB, using the ODMG Object Query Language (OQL):
• Opens DB
• Starts a transaction
• Executes a query to find a Person object named “S. M. Lee”
• Does additional processing on this Person object
• Gets Address object of Person
• Update street of Address object
• Commit transaction
• Close database

Source: http://www.service-architecture.com/object-oriented-databases 41
Advantages of relational databases or RDBMS.
1. Secure Option:
RDBMS uses tables with several rows, and these are highly secure options to store the data. These tables and
data stay protected with the user names and their passwords. Hence only an authorized person can access
those tables and data to work.
2. Simple to Use:
There is not any process of query processing, and hence the relational databases are simple. And the user is
not required to pass any complex query to access the data. However, if the user knows SQL query, this is more
than sufficient. And they can successfully use the relational database without any problem.
3. Fast Performance:
RDB are easy to use and also are simple by structure. Hence, it allows the user to get a fast experience. The
user gets many optimization filters or options to increase the speed of the data accessing.
4. Present Data Accurately:
Using a RDB is that these databases are more likely to produce accurate and interrelated tables. As it uses the
primary and foreign keys to make the relation between the raw. Thus, the users do not have any problem with
the reputation of any past data they already have received. So, there are zero chances of duplication of the
data in relational databases.
5. Accessible Anytime:
Many other types of databases require to have the specified path for getting access to the data. But here in the
relational database, the user does not require any predefined path. Hence the accessibility in the RDBMS is
easier compared to other databases.
6. It Can Have Multi-User
It is one of the great benefits of RDBs as many users can access the database at one time. Even if the data is
42
already updated, then also many users can visit without any issue. Thus, if the company uses relational
5.7. Drawbacks of Relational Database OR RDBMS
As there are several attractive advantages of relational databases and also the disadvantages of as follows:
1. Increase Expenditure:
Hence these databases are pretty expensive to use. Also, the company or the user needs to purchase the software and tools
to get the complete outcome of RDBMS. Hence, if the business has a low budget, it can feel hard to obtain such a database.
2. Some Information Can Be Lost:
The RDBMS contains the limited space, and these storage devices can not store more data if there is no space. As there is
no more storage, this data can be lost and create problems in the future.
3. Required to Use of Physical Storage Devices:
It also requires substantial storage devices, especially physical memory devices. Because it uses the rows and columns and
every set of data uses separate rows for them. Thus, it becomes crucial to keep the physical devices that can help in proper
optimization.
4. Performance Issue:
The performance level can be low in relational databases. Because it depends on rows and columns. Thus, if there are
many rows and tables, the query will take more time to process the result. Also, if there is considerable data in the machine,
it can slow down the working process.
5. It Can Be Complex to Understand
We have discussed that the relational database is easy to use, but this can also be challenging.
 When the amount of stored data increases, it becomes complicated to understand those data in simplified form.
 It happens because every data has kept using the particular feature that builds vast data sets to filter. 43
5.8 Storing objCP in relational database system

Object-Relational Data Models:


• Extend the relational data model by including object orientation and
constructs to deal with added data types.
• Allow attributes of tuples to have complex types, including non-atomic values
such as nested relations.
• Preserve relational foundations, in particular the declarative access to data,
while extending modeling power.
• Upward compatibility with existing relational languages.

44
C o n t’d .

Simple OQL Queries

Object Query Language (OQL): it provides declarative access to the object database using an SQL-
like syntax.

 It does not provide explicit update operators, but leaves this to the operations defined on object
types.

 An OQL query is a function that delivers an object whose type may be inferred from the operator
contributing to the query expression.

 OQL can be used for both associative and navigational access.


• Basic syntax:
select…from … where…
An entry point to the database is needed for each query
SELECT d.name
FROM departments d
WHERE d.college = ‘Engineering’;
45
Cont’d…
Nested Relations:
• Motivation:
• Permit non-atomic domains (atomic  indivisible)
• Example of non-atomic domain: set of integers , or set of tuples
• Allows more intuitive modeling for applications with complex data
• Intuitive definition:
• allow relations whenever we allow atomic ( scalar ) values - relations within relations
• Retains mathematical foundation of relational model
• Violates first normal form.

46
Cont’d…
Nested Relations, Example: library information system
• Each book has
• title,
• a set of authors,
• Publisher, and
• a set of keywords
• Non-1NF relation books

47
1NF Version of Nested Relation
• 1NF version of books

flat-books

48
Cont’d…
4NF Decomposition of flat–books

49
Cont’d…
Complex Types and SQL:1999
• Extensions to SQL to support complex types include:
1. Collection and large object types
• Nested relations are an example of collection
types
2. Structured types
• Nested record structures like composite attributes
3. Inheritance
4. Object orientation
• Including object identifiers and references

50
Cont’d…
Collection Types
• Set type (not in SQL:1999)
create table books (
…..
keyword-set setoff (varchar(20))
……
)
• Sets are an instance of collection types.
Other instances include
• Arrays (are supported in SQL:1999)
• E.g. author-array varchar (20) array[10]
• Can access elements of array in usual fashion:
• E.g. author-array[1]
• Multi-sets (not supported in SQL:1999)
• I.e., unordered collections, where an element may occur multiple times
• Nested relations are sets of tuples
• SQL:1999 supports arrays of tuples
51
Cont’d…
Large Object Types
• Large object types
• clob: Character large objects
book-review clob(10KB)
• blob: binary large objects
image blob(10MB)
movie blob (2GB)

52
Cont’d…
Structured and Collection Types (Oracle)

• Structured types can be declared and used in SQL


CREATE OR REPLACE TYPE Publisher as Object (
name varchar(20),
branch varchar(20)); /
CREATE OR REPLACE TYPE VA as VARRAY (5) of VARCHAR(30); /
CREATE OR REPLACE TYPE Book AS OBJECT (
title varchar(20),
authors VA,
pub_date date,
pub Publisher,
keywords VA); /
• Structured types can be used to create tables
create table books of Book;

53
cont’d…
Creation of Values of Complex Types
• Values of structured types are created using constructor functions
• E.g. Publisher(‘McGraw-Hill’, ‘New York’)
Note: a value is not an object
• To insert the preceding tuple into the relation books:
Insert into books (title, authors, pub, keywords) values ('Compilers',
VA('Smith', 'Jones'),
Publisher('McGraw-Hill', 'New York'), VA('parsing ', 'analysis'));

55
Creation of Values of Complex Types
• Select Title, a.* from Books b, table ( b.authors )a ;
SQL> Select Title, a.* from Books b, table ( b.authors )a ;

TITLE COLUMN_VALUE
---------- ---------------------
Compilers Smith
Compilers Jones
SQL> Select keywords, a.* from Books b, table( b.authors)a ;
KEYWORDS COLUMN_VALUE
VA('parsing ', 'analysis')........ Smith
VA('parsing ', 'analysis')...........Jones
SQL> Select authors, a.* from Books b, table( b.keywords)a ;
AUTHORS keywords
VA('Smith', 'Jones')...............parsing
VA('Smith', 'Jones').............analysis

56
Cont’d..
Inheritance

• Suppose that we have the following type definition for people:


create or replace type Person_typ as Object
(name varchar(20),
address varchar(20)) not final; /
• Using inheritance to define the student and teacher types
create type Student under Person As Object (
degree varchar(20), department varchar(20)); / incorrect
create or replace type Student_typ UNDER Person_typ
(degree varchar(20),
department varchar(20)) not final; /
create type Teacher_typ under Person_typ (
salary integer,
department varchar(20)) not final; /
• Subtypes can redefine methods by using overriding method in place of member in the member declaration

57
Cont’d...
Reference Types

• Object-oriented languages provide the ability to create and refer to


objects.
• In SQL:1999
• References are to tuples, and
• References must be scoped,
• I.e., can only point to tuples in one specified table

58
Cont’d...
Reference Declaration in SQL:1999
• E.g. define a type Department with a field name and a field head which is a
reference to the Person in table people as scope
create type Department as Object(
name varchar(20),
head ref Person_typ );
/
The table departments is defined as follows:
create table departments of Department;

59
Cont’d...
Initializing Reference Typed Values

• In Oracle, to create a tuple with a reference value, first create


the tuple with a null reference and then set the reference
separately using the function ref(p) applied to a tuple variable.
• E.g. create a department with name CS and head being the
person named John

insert into departments values (`CS’, null);


*update departments d

Update set head = (select ref(p) from people p where


name='John')
where d.name = 'CS' and d.head is null; /

60
Querying with Structured Types
• Find the title and the name of the publisher of each book.
select title, publisher.name from books; // incorrect

• Note,
the use of the dot notation to access fields of the composite attribute
(structured type) publisher

61
Nested Table
CREATE TYPE animal_ty AS OBJECT (
breed VARCHAR(25),
name VARCHAR(25),
birthdate DATE); /
create type animals_nt as table of animal_ty;/
or
Create table animals_nt of animal_ty;

CREATE TABLE breeder (


breederName VARCHAR(25),
animals animals_nt)
nested table animals store as animals_nt_tab;
62
Nested Table
• CREATE TABLE breeder (breederName VARCHAR(25),
animals animals_nt) nested table animals store as animals_nt_tab;
INSERT INTO breeder VALUES('John Smith ', animals_nt(animal_ty('DOG',
'BUTCH', '31-MAR-01'), animal_ty('DOG', 'ROVER', '05-JUN-
01'),animal_ty('DOG', 'JULIO', '10-JUN-01'))
);

63
Nested Table

SELECT breederName, N.Name, N.BirthDate FROM breeder,


TABLE( breeder.Animals) N;
SQL> SELECT breederName, N.Name, N.BirthDate FROM breeder, TABLE( breeder.Animals) N;
BREEDERNAME NAME BIRTHDATE
------------------------- ------------------------- ---------
John Smith BUTCH 31-MAR-01
John Smith ROVER 05-JUN-01
John Smith JULIO 10-JUN-01
SELECT breederName, N.Name, N.BirthDate FROM breeder, TABLE(breeder.Animals) N WHERE N.Name = 'JULIO';
SQL> SELECT breederName, N.Name, N.BirthDate FROM breeder, TABLE(breeder.Animals
) N WHERE N.Name = 'JULIO';

BREEDERNAME NAME BIRTHDATE


------------------------- -------------- ---------
John Smith JULIO 10-JUN-01
64
Comparison of O-O and O-R Databases
• Relational systems
• simple data types, powerful query languages, high protection.
• Persistent-programming-language-based OODBs
• complex data types, integration with programming language, high performance.
• Object-relational systems
• complex data types, powerful query languages, high protection.
• Note: Many real systems blur these boundaries
• E.g. persistent programming language built as a wrapper/binding on a relational
database offers first two benefits, but may have poor performance.

65
Query processing as object
returns a collection (bag) of
• Finding student objects having gpa 3; student objects for which the
select s from students s where s.gpa >= 3.0; gpa is greater than or equal to
3.0.
• Finding Distinct Values
select distinct s.age from students s where s.gpa =3.0;
• Querying Multiple Classes
select distinct y.crse_code from courseofferings x, x.belongs_to y
where x.term = “Fall 2005”;

66
Cont’d…
Suppose that we want to find the number of students enrolled in section 1 of the MBA664 course. The enrollment
operation is available in CourseOffering, but the course code is available in Course.

select x.enrollment from courseofferings x, x.belongs_to y


where y.course_code = “MBA 664” and x.section = 1;

This query traverses two paths, one using the takes relationship and the other using the belongs_to relationship, to find
the codes and titles of all courses taken by Mary Jones.

select c.course_code, c.course_title from students s, s.takes x, x.belongs_to c


where s.name = “Mary Jones”;

We can also select a structure consisting of multiple components. For example, the following query returns a structure
with age and gpa as its attributes.

67
Cont’d...
Calculating Summary Values

• count(students) ;
• We could have also written this query as
• select count (*) from students s;
select avg_salary_female: avg (e.salary) from employees e
where e.gender = female;
 To find the maximum salary paid to an employee, we use the max function:
• max (select salary from employees); OR
• Select max(e.salary) from employees e;
 To find the total of all employee salaries, we use the sum function:
sum (select salary from employees);
select min (e.salary) from employees e group by e.gender;

68
The Next Generation of DBMS

• Object-oriented database systems


• Artificial intelligence systems
• Expert systems
• Distributed database
• The Internet

69

You might also like