Introduction To Object Oriented Database: Unit-I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Introduction to Object Oriented Database

UNIT-I
Introduction to Object Oriented Database

• An object database management system (ODBMS, also referred to as object-


oriented database management system or OODBMS), is a database management
system (DBMS) that supports the modelling and creation of data as objects.

• An object-oriented database system must satisfy two criteria:


• The first criterion translates into five features: persistence, secondary storage
management, concurrency, recovery and an ad hoc query facility.
• The second one translates into eight features: complex objects, object identity,
encapsulation, types or classes, inheritance, overriding combined with late binding,
extensibility and computational completeness.
Motivation of ODBMSs
Application
data structures
Copy and
Transparent
translation
Relational ODBMS
representation data transfer

RDBMS

• Complex objects in emerging DBMS applications cannot be


effectively represented as records in relational model.
• Representing information in RDBMSs requires complex
and inefficient conversion into and from the relational
model to the application programming language
• ODBMSs provide a direct representation of objects to
DBMSs overcoming the impedance mismatch problem
Object Oriented Database Management
• Object Oriented databases have evolved along two different paths:
• Persistent Object Oriented Programming Languages: (pure ODBMSs)
• Start with an OO language (e.g., C++, Java, SMALLTALK) which has a rich
type system
• Add persistence to the objects in programming language where persistent
objects stored in databases
• Object Relational Database Management Systems (SQL3 Systems)
• Extend relational DBMSs with the rich type system and user-defined functions.
• Provide a convenient path for users of relational DBMSs to migrate to OO
technology
• All major vendors (e.g., Informix, Oracle) will/are supporting features of SQL3.
Why OODBMS

• In today’s world, Client-Server applications that rely on a database on the server


as a data store while servicing requests from multiple clients are quite
commonplace
• This cause a certain inefficiency as objects must be mapped to tuples in the
database and vice versa instead of the data being stored in a way that is
consistent with the programming model.
• OOP concepts such as encapsulation, polymorphism and inheritance are enforced
as well as database management concepts such as the ACID properties
(Atomicity, Consistency, Isolation and Durability) which lead to system
integrity, support for an ad hoc query language and secondary storage
management systems which allow for managing very large amounts of data.
• Represents more complex data than relational schema
• Integration and Sharing
Disadvantages of Object Oriented DBMSs (OODBMS)

• Lack of universal data model and lack of standards – there is no universally


agreed model for OODBMS.
• Lack of experience – not easy for an end user. We need programmers to interact.
Class
• When looking on the concept of classes in object-oriented databases, you have
to distinguish the terms class and type.
• A type is used to describe a set of objects that share the same behavior. In this
sense, an object's type depends on which operations can be invoked on the
object.
• A class is a set of objects that have the exactly same internal structure. In that
way, a class defines the implementation of an object and a type describes the
way the object can be used.
Object

• Each real-world entity is represented by an object.


• This object has a state and a behavior.
• The combination of the current values of an object's attributes define the object's
state. A set of methods, acting on an object's state, define the object's behavior.
• Each object instance has a unique, unchanging entity called Object Identifier or
OID.
• OIDs are independent of the data contained in the object. The internal data values
are not used to generate identification.
• OIDs are generated by the object system. Users or programs have no control over
identification.
• OIDs last the lifetime of the object. Identification of the object never changes
even when the data contents may change.
Abstraction
• Hide the Implementation Details
Principles of Abstractions

• Specialization
• Generalization
Specialization
• Specialization is a process in which an entity is divided into sub-entities.
• The idea behind Specialization is to find the subsets of entities that have few
distinguish attributes.
Generalization

• Generalization is a process in which the common attributes of more than one entities form a new entity.
Example
• we have two entities Student and Teacher.
• Attributes of Entity Student are: Name, Address & Grade
• Attributes of Entity Teacher are: Name, Address & Salary
Encapsulation

• Allows code and data to be packed together.


• Defining methods for a class is an integral part of encapsulation.
• Encapsulation is derived from the notion of Abstract Data Type (ADT).
• It is motivated by the need to make a clear distinction between the specification
and the implementation of an operation. It reinforces modularity and provides a
form of logical data independence.
Information Hiding

• Encapsulation: An object contains both current state (Attributes) and set of methods used
to manipulate it. It is called encapsulation.

• Information Hiding: It is process of separates external properties of an object from its


internal properties, which are hidden from external environment. These two concepts also
related with abstraction.

• Importance: These two concepts support the facility that internal properties of an object to
be changed without affecting applications that use it, provided external properties remain
same. It also provides data independence.
Abstraction

• It’s the process of identifying the essential aspects of an entity and ignoring the
unimportant properties.
• It has two fundamentals
• Encapsulation
• Data Hiding
Inheritance

• Implementation "the encapsulated internals of an object"


• “Automatically assuming the attributes and methods of another object at a higher
class“
TYPE_NAME: function, function, ..., function
For example, a type that describes characteristics of a PERSON may be
defined as follows:

PERSON: Name, Address, Birth_date, Age,


• The concept of subtype is useful when the designer or user must create a new
type that is similar but not identical to an already defined type.
• The subtype then inherits all the functions of the predefined type, which is
referred to as the supertype. For example, suppose that we want to define two
new types EMPLOYEE and STUDENT as follows:

• EMPLOYEE: Name, Address, Birth_date, Age, Ssn, Salary, Hire_date, Seniority

• STUDENT: Name, Address, Birth_date, Age, Ssn, Major, Gpa


• Example:
• GEOMETRY_OBJECT: Shape, Area, Reference_point
• RECTANGLE subtype-of GEOMETRY_OBJECT: Width, Height
• TRIANGLE S subtype-of GEOMETRY_OBJECT: Side1, Side2, Angle
• CIRCLE subtype-of GEOMETRY_OBJECT: Radius
Inheritance
Example of Inheritance
Inheritance
Inheritance Type
Overloading
Multiple Inheritance and overloading
Table Inheritance

• Only tables that are defined on named row types support table inheritance.
• Table inheritance is the property that allows a table to inherit the behavior
(constraints, storage options, triggers) from the super table.
• A table hierarchy is the relationship that you can define among tables in which
sub tables inherit the behavior of super tables.
• A table inheritance provides the following advantages:
• It encourages modular implementation of your data model.
• It ensures consistent reuse of schema components.
• It allows you to construct queries whose scope can be some or all of the tables in the
table hierarchy
Polymorphism
Dynamic binding
• Object oriented provides facility to specify that the compiler should match function calls with the correct
definition at the run time; this is called dynamic binding or late binding or run-time binding.
• Dynamic binding is achieved using virtual functions.
• Base class pointer points to derived class object.
Dynamic Binding

• A polymorphic variable is a class variable that can reference (point to)


objects of the class and objects of any of its descendants

• If a class overrides a method and that method is called through a


polymorphic variable, the binding to the correct method will be
dynamic

• Dynamic binding allows software systems to be more easily extended


during both development and maintenance
Dynamic Binding Concepts
• An abstract method is one that does not include a definition (it only
defines a protocol)

• An abstract class is one that includes at least one virtual method

• An abstract class cannot be instantiated


Object-Oriented Data Model
Basic Concepts

• An Object Oriented Data Model(OODM) has been defined for logical database
design and database access.
• The OODM three types of relationships.
• Aggregation, Generalization and specifications.
• It provides four types of data operations defining schema, creating database,
retrieving objects and expanding objects.
• In OODM both data and their relationship are contained in a single structure
known as object.
Types of object based Data Models

• Entity Relationship Model (ER)


• ER data model is one of the important data model which forms the basis for all
the designs in the database world.
• Object oriented data model along with the mapping between the entities,
describes the state of each entity and the task performed by them.
Features of OODM

• The OODM supports a structured menu based interface which allows a user
define the schema and retrieve from the database without any knowledge of the
OODM.
• An important features of this interface is that menu information is modelled as
set of interrelated objects stored in the database.
Object Identity

• It provides unique identity to each independent object stored in database.


• This unique identity is implemented via unique system generated object
identifier.
Advantages

• Because of its inheritance property, we can re-use the attributes and


functionalities.
• It reduces the cost of maintaining the same data multiple times.
• Also, these information's are encapsulated and there is no fear being misused by
other objects.
• Because of the above feature, it becomes more flexible in the case of any
changes.
• since each class binds its attributes and its functionalities, its same as
representing the real world object.
Complex Data Types – Structured Types and Inheritance in SQL
Complex Data Types
Unnested Relations
Array and Multiset Types in SQL

• Arrays – stores information in an order


• Multisets – stores information in an unordered set.

Example of array and multiset declaration:


Creation of Collection Values
• Array construction
array [‘Silberschatz’,`Korth’,`Sudarshan’]
• Multisets
• multisetset [‘computer’, ‘database’, ‘SQL’]
• To insert the preceding tuple into the relation books
insert into books
values
(‘Compilers’, array[`Smith’,`Jones’],
Publisher (`McGraw-Hill’,`New York’),
multiset [`parsing’,`analysis’ ])
Querying Collection-Valued Attributes
• To find all books that have the word “database” as a keyword,
select title
from books
where ‘database’ in (unnest(keyword-set ))
• We can access individual elements of an array by using indices
• E.g.: If we know that a particular book has three authors, we could write:
select author-array[1], author-array[2], author-array[3]
from books
where title = `Database System Concepts’
• To get a relation containing pairs of the form “title, author-name”
for each book and each author of the book
select B.title, A.author
from books as B, unnest (B.author-array) as A (author )
Object Identity and Reference Types in SQL
• Define a type Department with a field name and a field head which is a reference
to the type Person, with table people as scope:

create type Department ( name varchar (20), head ref (Person) scope people)

• We can then create a table departments as follows

create table departments of Department


• Referenced table must have an attribute that stores the identifier, called the
self-referential attribute

create table people of Person ref is person_id system generated;


User Generated Identifiers
Implementing OR Features

• An Object relational model is a combination of a Object oriented database model


and a Relational database model.
• So, it supports objects, classes, inheritance etc. just like Object Oriented models
and has support for data types, tabular structures etc like Relational data model.
• Similar to how E-R features are mapped onto relation schemas
• Sub table implementation
• Each table stores primary key and those attributes defined in that table or,
• Each table stores both locally defined and inherited attributes
• May choose to represent array and multiset directly.
• May choose to use a normalized representation internally.
Object Oriented Model and Relational Database Model
Object relational model = Object Oriented Model + Relational Database Model
Object relational model = Object Oriented Model + Relational Database Model
Persistent Programming Languages
• Persistent data: data that continue to exist even after the program that created it
has terminated.
• A persistent programming language is a programming language extended with
constructs to handle persistent data. It distinguishes with embedded SQL in at
least two ways:
• In a persistent program language, query language is fully integrated with the host language
and both share the same type system.
• Any format changes required in databases are carried out transparently.
• Comparison with Embedded SQL where (1) host and DML have different type systems,
code conversion operates outside of OO type system, and hence has a higher chance of
having undetected errors; (2) format conversion takes a substantial amount of code.
• Using Embedded SQL, a programmer is responsible for writing explicit code to fetch data
into memory or store data back to the database.
• In a persistent program language, a programmer can manipulate persistent data
without having to write such code explicitly.
Drawbacks of Persistent Programming

• Drawbacks:
• (1) Powerful but easy to make programming errors that damage the database;
• (2) harder to do automatic high-level optimization; and
• (3) do not support declarative querying well .
Object Relational Mapping.
• Object-Relational Mapping (ORM) systems built on top of traditional relational
databases
• Implementor provides a mapping from objects to relations
• Objects are purely transient, no permanent object identity
• Objects can be retried from database
• System uses mapping to fetch relevant data from relations and construct objects
• Updated objects are stored back in database by generating corresponding
update/insert/delete statements
• The Hibernate ORM system is widely used
• Provides API to start/end transactions, fetch objects, etc
• Provides query language operating directly on object model
• queries translated to SQL
• Limitations: overheads, especially for bulk update

You might also like