Chapter 5-OODB
Chapter 5-OODB
.
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
7
5.2. Object Oriented Concepts (Abstraction, Encapsulation, and Information hiding)
• 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.
14
Object-Oriented Concepts, Class & Encapsulation
Object(ObjCP) and Attributes:
• Class encapsulates the data structure and
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.
16
5.3. Object Identity
Object-Oriented Concepts, Object Identifier
• Object Identifier (OID) – The unique OID is maintained by the DBMS.
Example: Reference to Date object in the Employee object for the date hired.
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
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
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
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
44
C o n t’d .
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.
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)
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
57
Cont’d...
Reference Types
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
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;
63
Nested Table
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.
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.
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
69