CHAPTER- 1
OBJECT ORIENTED & OBJECT-
RELATIONAL DATABASES
Objectives of the Chapter
Overview of Object-Oriented Concepts
Object Identity, Type Constructors
Encapsulation of Operations, Multiple
Inheritance, Polymorphism
2
Introduction
Object-Oriented databases are now referred to as object databases (ODB) and the database
systems are referred to as object data management systems (ODMS) (formerly referred to as
ODBMS or OODBMS).
Traditional data models and systems have certain shortcomings when more complex database
applications must be designed and implemented
For Example
Databases for engineering design and manufacturing,
Scientific experiments,
Telecommunications,
Computer Aided Software Engineering,
Office Information System,
Geographic Information Systems, and Multimedia.
3
Cont.…
These newer applications have requirements and characteristics that differ from
those of traditional business applications, such as:-
More complex structures for stored objects;
The need for new data types for storing images, videos, or large textual items;
Object databases were proposed to meet some of the needs of these more complex
applications.
A key feature of object databases is the power they give the designer to specify
both the structure of complex objects and the operations that can be applied to
these objects.
Another reason for the creation of object-oriented databases is the vast increase in
the use of OOP languages for developing software applications. 4
Cont.…
(RDBMS) vendors have also recognized the need for incorporating features that were
proposed for object databases, and newer versions of relational systems have incorporated
many of these features.
This has led to database systems that are characterized as object-relational or ORDBMSs.
A consortium of object DBMS vendors and users, called ODMG, proposed a standard whose
current specification is known as the ODMG 3.0 standard.
Weakness of Relational DBMS
1.Poor representation of “real world” entities
2.Semantic overloading
3.Limited operation
4.Homogenous data structure
5.Difficulty of handling recursive queries 5
1. Poor Representation of “Real World” Entities
The process of normalization leads to the creation of relations that do not
correspond to entities in the real world.
This fragmentation of relations is inefficient leading to many joins during
query processing.
2. Semantic Overloading
Has only one construct to represent data and relationships between data,
that is the relation.
3. Limited Operation
There is no methods to represent has, owns, manages relationships.
Only a fixed set of operations such as set and tuple oriented relations. 6
4. Homogenous Data Structure
Assumes both Horizontal and vertical homogeneity.
Horizontal homogeneity means that each tuple of a relation must be composed of the
same attributes.
Vertical homogeneity means that the values in a particular column of a relation must
all come from the same domain.
Intersection of row and column must be an atomic value.
Also it is too restrictive to real world objects that have complex structures.
5. Difficulty Handling
Recursive Queries
Atomicity of data means that repeating groups are not allowed in the relational model.
As a result, it is extremely difficult to handle recursive queries that are queries about
relationships that a relation has with itself. 7
Introduction to OO Concepts & Features
This section describes approaches to integrate the benefits of object-oriented
relational database technology with the strengths of the relational model.
Such hybrids are based on the relation of the main structure for data but
include additional features to allow the inclusion of complex data structures.
Object-oriented databases rely on the ability to reference object structures
through pointers and use of inheritance to allow the reuse of data structures.
In order to define a type hierarchy, and to specify methods applicable to all
instances of type, it is necessary to add type definitions to the relational data
model.
Before defined Object-oriented lets first define Object.
8
Cont.…
Objects are the basic run time entities in an object-oriented system.
Object is real word entity, or object corresponds to an entity in the ER model.
They may represent a person, a place, a bank account, cars, a table of data or any item
that the program has to handle.
An object typically has two components: state (value) and behavior (operations).
It can have a complex data structure as well as specific operations defined by the
programmer.
In OODB the data is stored in the form of objects.
Object-oriented refers to a programming language, system or software methodology
that is built on the concepts of logical objects. It works through the creation, utilization
and manipulation of reusable objects to perform a specific task, process or objective.
9
Cont.…
Objects in an OOPL exist only during program execution; therefore, they
are called transient objects.
An OO database can extend the existence of objects so that they are stored
permanently in a database, and hence the objects become persistent objects
that exist beyond program termination and can be retrieved later and
shared by other programs.
In other words, OO databases store persistent objects permanently in
secondary storage and allow the sharing of these objects among multiple
programs and applications.
Object-oriented systems allow definition of the operations or functions
10
(behavior) that can be applied to objects of a particular type.
Cont.…
Some OO models insist that all operations a user can apply to an object must
be predefined this forces a complete encapsulation of objects.
This rigid approach has been relaxed in most OO data models for two
reasons:-
First, database users often need to know the attribute names so
they can specify selection conditions on the attributes to retrieve specific
objects.
Second, complete encapsulation implies that any simple retrieval
requires a predefined operation, thus making ad hoc queries difficult to
specify on the fly.
11
What is Object Oriented Database? (OODB)
A database system that incorporates all the important object-oriented
concepts
Database + the object-oriented paradigm.
Integration of OO language and database
Advantage of (OODB)
Designer can specify the structure of objects and their behavior (methods)
Better interaction with object-oriented languages such as Java and C++
Definition of complex and user-defined types
Encapsulation of operations and user-defined methods
12
Object Identity and Objects
ODMS provides a unique identity to each independent object stored in the database.
This unique identity is typically implemented via a unique, system-generated object
identifier (OID).
Object identity is a stronger notion of identity than in programming languages or data
models not based on object orientation.
The value of an OID is not visible to the external user, but is used internally by the system
to identify each object uniquely and to create and manage inter-object references.
The main property required of an OID is that it be immutable; that is, the OID value of a
particular object should not change.
This preserves the identity of the real-world object being represented.
Hence, an ODMS must have some mechanism for generating OIDs and preserving the
immutability property. 13
Cont.…
It is also desirable that each OID be used only once; that is, even if an object is
removed from the database, its OID should not be assigned to another object.
Every object must have an immutable OID, whereas a literal value has no OID
and its value just stands for itself.
Thus, a literal value is typically stored within an object and cannot be
referenced from other objects.
In ODBs, a complex type may be constructed from other types by nesting of
type constructors.
The Three most basic constructors are atom, struct (or tuple), and
collection
14
Atom
Built in data types such as integers, strings, floating point numbers etc..
Tuple (struct)
It Creates standard structured types, such as the tuples (records).
A structured type is made up of several components (compound or composite type).
More accurately, struct is a type generator, because many different structured types can be created.
E.g: struct Name<FirstName: string,MiddleInitial: char, LastName: string>
The type constructor’s atom and struct are the only ones available in the original (basic) relational
model.
The tuple constructor can create structured values and objects of the form <a1:i1, a2:i2, ..., an:in>,
where each aj is an attribute name and each ij is a value or an OID.
The tuple type constructor is often called a structured type, since it corresponds to the struct
construct in the C and C++ programming languages.
15
Collection (multivalued) type constructors
Include the set(T), list(T),bag(T), array(T) type constructors.
These allow part of an object or literal value to include a collection of other objects or values
when needed.
These constructors are also considered to be type generators because many different types
Set
can be Constructor
created.
Create objects or literals that are a set of distinct elements {i1, i2, ..., in}, all of the same type.
Bag Constructor
(multiset) is similar to a set except that the elements in a bag need not be distinct.
16
List constructors
These will create an ordered list [i1, i2, ..., in] of OIDs or values of the same type.
A list is similar to a bag except that the elements in a list are ordered, and hence
we can refer to the first, second, or jth element.
Array Constructor
Creates a single-dimensional array of elements of the same type.
The main difference between array and list is that a list can have an arbitrary
number of elements whereas an array typically has a maximum size.
17
Object Definition Language
The ODL is a language for defining the specifications of object types for ODMG compliant
systems, equivalent to the DDL of traditional DBMSs.
Its main objective is to facilitate portability of schemas between compliant systems while
helping to provide interoperability between ODBMSs.
The ODL defines the attributes and relationships of types and specifies the signature of the
operations, but it does not address the implementation of signatures.
An object definition language (ODL) that incorporates the preceding type constructors can be
used to define the object types for a particular database application.
A type or class is defined by assigning it a type name, and then defining a number of
attributes (instance variables) and operations (methods) for the type.
In the simplified model the attributes and operations are together called functions, since
attributes resemble functions with zero arguments, function name can be used to refer to the
18
value of an attribute or to refer to the resulting value of an operation (method).
Cont.…
A type in its simplest form has a type name and a list of visible (public) functions.
A type can be specified as TYPE_NAME: function, function, ..., function E.g:
PERSON: Name, Address, Birth_date, Age, Ssn
In the PERSON type, the Name, Address, Ssn, and Birth_date functions can be
implemented as stored attributes, whereas the Age function can be implemented
as an operation that calculates the Age from the value of the Birth_date attribute
and the current date.
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. 19
Cont.…
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
Since both STUDENT and EMPLOYEE include all the functions defined for PERSON plus some
additional functions of their own, we can declare them to be subtypes of PERSON.
For STUDENT, Major can be defined as a stored attribute, whereas Gpa may be implemented as an
operation that calculates the student’s grade point average by accessing the Grade values that are
internally stored (hidden) within each STUDENT object as hidden attributes.
For EMPLOYEE, the Salary and Hire_date functions may be stored attributes, whereas Seniority
may be an operation that calculates Seniority from the value of Hire_date. Therefore, we can
declare EMPLOYEE and STUDENT as follows:
EMPLOYEE subtype-of PERSON: Salary, Hire_date, Seniority
STUDENT subtype-of PERSON: Major, Gpa 20
Cont.…
As another example, consider a type that describes objects in plane geometry, which may be defined
as follows:
GEOMETRY_OBJECT: Shape, Area, Reference_point
Area is a method that is applied to calculate the area.
RECTANGLE subtype-of GEOMETRY_OBJECT: Width, Height ,TRIANGLES subtype-of
GEOMETRY_OBJECT: Side1, Side2, Angle , CIRCLE subtype-of GEOMETRY_OBJECT: Radius
Area operation may be implemented by a different method for each subtype, since the procedure for
area calculation is different for rectangles, triangles, and circles.
Notice that type definitions describe objects but do not generate objects on their own.
When an object is created, typically it belongs to one or more of these types that have been declared.
For example, a circle object is of type CIRCLE and GEOMETRY_OBJECT (by inheritance).
Each object also becomes a member of one or more persistent collections of objects (or extents),
which are used to group together collections of objects that are persistently stored in the database.
21
Overview of the Object Model of ODMG
One of the reasons for the success of commercial relational DBMSs is the SQL standard.
The Object Database Management Group is an industry consortium aimed at
standardizing object-oriented databases.
The lack of a standard for ODMSs for several years may have caused some potential
users to shy away from converting to this new technology.
The standard is made up of several parts, including the object model, the object
definition language (ODL), the object query language (OQL), and the bindings to object-
oriented programming languages.
The ODMG object model is the data model upon which the object definition language
(ODL) and object query language (OQL) are based.
It is meant to provide a standard data model for object databases, just as SQL describes
a standard data model for relational databases. 22
The Object Query Language OQL
OQL: is the query language proposed for the ODMG object model.
It is designed to work closely with the programming languages for which an
ODMG binding is defined, such as C++, Smalltalk, and Java.
Hence, an OQL query embedded into one of these programming languages
can return objects that match the type system of that language.
Additionally, the implementations of class operations in an ODMG schema can
have their code written in these programming languages.
The OQL syntax for queries is similar to the syntax of the relational standard
query language SQL, with additional features for ODMG concepts, such as
object identity, complex objects, operations, inheritance, polymorphism, and
23
relationships.
Simple OQL Queries, Database Entry Points, and
Iterator Variables
The basic OQL syntax is a select D.Dname
select ... from ... where ... from D in
structure, as it is for SQL. DEPARTMENTS
For example, the query to where D.College =
retrieve the names of all ‘Engineering’;
departments in the college of
‘Engineering’ can be written
as follows:
24
Consider the following relation:
Product no Name Color
P1 Ford Mustang Black
P2 Toyota Celica Green
P3 Mercedes SLK Black
The following is a sample query :“what are the names of the black product?”
SELECT DISTINCT P.NAME FROM PRODUCTS P WHERE P.COLOR = “BLACK”
25
Cont.…
Valid in both SQL and OQL, but results are
different
26
Comparison
Queries look very similar in SQL and OQL, sometimes they are the same
In fact, the results they give are very different
Query returns:
27
Encapsulation
Encapsulation operation is defined in two parts.
The first part, called the signature or interface of the operation, specifies the operation
name and arguments (or parameters).
The second part, called the method or body, specifies the implementation of the operation.
Operations can be invoked by passing a message to an object, which includes the operation
name and the parameters.
The object then executes the method for that operation.
Another key concept in OO systems is that of type and class hierarchies and inheritance.
This permits specification of new types or classes that inherit much of their structure and/or
operations from previously defined types or classes.
Using this makes it easier to develop the data types of a system incrementally, and to reuse
existing type definitions when creating new types of objects. 28
Multiple Inheritance
Occurs when a certain subtype T is a subtype of two (or more) types and hence inherits the
functions (attributes and methods) of both super types.
The general rule is that if a function is inherited from some common super type, then it is
inherited only once.
In such a case, there is no ambiguity; the problem only arises if the functions are distinct in
the two super types.
There are several techniques for dealing with ambiguity in multiple inheritance.
One solution is to have the system check for ambiguity when the subtype is created, and to let
the user explicitly choose which function is to be inherited at this time.
A second solution is to use some system default.
A third solution is to disallow multiple inheritance altogether if name ambiguity occurs,
instead forcing the user to change the name of one of the functions in one of the super types.
29
Indeed, some OO systems do not permit multiple inheritances at all.
Polymorphism
Another OO concept is Polymorphism which is of two types.
Function overloading, which refers to a function’s ability to be applied to different types of
objects;
For example, an operation to calculate the area of a geometric object may differ in its method
(implementation), depending on whether the object is of type triangle, circle, or rectangle.
Operator overloading refers to operators’ ability to be applied to different types of objects in
different way.
In strongly typed systems, this can be done at compile time, since the object types must be
known.
This is termed early (or static) binding. Sometime the function must check the type of object at
runtime and then invoke the appropriate method.
This is often referred to as late (or dynamic) binding.
30
Summary of Object Database Concepts
Object identity :- Objects have unique identities that are independent of their
attribute values and are generated by the ODMS.
Type constructors:- Complex object structures can be constructed by applying in
a nested manner a set of basic constructors, such as tuple, set, list, array, and bag.
Encapsulation of operations:- Both the object structure and the operations that
can be applied to individual objects are included in the type definitions.
Type hierarchies and inheritance:- Object types can be specified by using a type
hierarchy, which allows the inheritance of both attributes and methods
(operations) of previously defined types. Multiple inheritances are allowed in some
models.
Polymorphism:- Operations and method names can be overloaded to apply to
31
Problems with RDBMS
Restricted built in datatypes (Numbers and strings)
Structural shortcomings (flat and do not support nested structures)
Do not take advantage of OO approaches
Lead to OODBMS
Problems with OODBMS
Tying database design too closely to application design
SQL 92 is productive but needs more resources
Lack of standard data model leads to errors
32
SQL3 “Object-oriented SQL”
Foundation for several OO database management systems – ORACLE8, DB2, etc
New features – “relational” & “Object oriented”
Relational Features – new data types, new predicates, enhanced semantics,
additional security and an active database
Object Oriented Features – support for functions and procedures
Object-Relational Features: Object Database
Extensions to SQL
Some type constructors have been added to specify complex objects
Row type, which corresponds to the tuple (or struct) constructor.
An array type for specifying collections is also provided.
Other collection type constructors, such as set, list, and bag
33
constructors,.
Cont.…
A mechanism for specifying object identity through the use of reference type is
included.
Encapsulation of operations provide the concept of user defined routines (UDRs)
(abstract data types ).
In addition, allows the definition of general methods (operations).
Inheritance User-Defined Types
mechanisms are provided and
using the Complex
keyword UNDER.
Structures for Objects
Structured or composite data types in object relational databases provide this
same capability in a DBMS context.
34
Definition of a named row type can depend on other, previously created one.
Cont.…
Oracle calls the abstract type an object.
Extending the object –oriented terminology further the individual components
of an Oracle abstract data type are referred to as attributes.
To allow the creation of complex-structured objects, and to separate the
declaration of a type from the creation of a table, SQL now provides user-
defined types (UDTs).
In addition, four collection types have been included to allow for multivalued
types and attributes in order to specify complex-structured objects rather than
just simple (flat) records.
The user will create the UDTs for a particular application as part of the
35
Example
A UDT may be Example
specified in its simplest CREATE OR REPLACE TYPE
form using the ADDRESS_T AS OBJECT
following syntax: (
CREATE TYPE street varchar2(10),
TYPE_NAME AS descr varchar(25),
OBJECT(<component
declarations>); postcode varchar2(7)
);
36
Cont.…
The creation of type is independent CREATE TYPE PERSON_T AS
from the creation of table or OBJECT
relation.
It is possible to create column (
types which can be used as nested name varchar2(50),
relations.
contact address_t
The above type can be used as
follows: );
Its also possible to create a table Student from the abstract data
types created above.
CREATE TABLE STUDENT
(
Stud_id varchar2(5) primary key,
Person person_t
) 37
Cont.…
A UDT can be used as either the type for an attribute or as the type for a table.
By using a UDT as the type for an attribute within another UDT, a complex
structure for objects (tuples) in a table can be created.
CREATE TYPE STUDENT_T AS OBJECT
(
Stud_id varchar2(5),
Person person_t
)
CREATE TABLE STUDENT OF STUDENT_T ; OR
CREATE TABLE STUDENT OF STUDENT_T
(
Stud_id primary key
) 38
Cont.…
Here student_t is defined as a type which includes person_t as an inherited structure as a means of
reusing predefined types. & can be used to define a table student based on the student_t type specified
above.
To allow for collection types in order to create complex-structured objects, four constructors are now
included in SQL: ARRAY, MULTISET, LIST, and SET.
CREATE TYPE Phone_T AS VARRAY(4) OF VARCHAR2(20);
This array has a maximum of four elements, meaning that we can store up to four phone numbers, Its
not necessary to define a table of type person since all instances will be of subtypes.
Data can be added into the student table allowing for the embedded structures as shown below:
To Insert Into The Table Student
INSERT INTO STUDENT VALUES
(‘ss1111’,person_t(‘Smith’,address_t(12,’High street’,’Z670101’)));
To refer the individual data items in the abstract data types: 39
Object Relational DBMS
ORDBMS synthesizes the feature of RDBMS with the best ideas of OODBMS.
New data types and functions can be implemented using general-purpose languages
such as C and Java.
OO structural features such as inheritance and polymorphism are part of it.
All attributes are inherited.
The order ofsupertypes
CREATE TYPE
in theEMP_TYPE AS OBJECT
UNDER clause (
determines the inheritance hierarchy.
empNo NUMBER, empName VARCHAR2(200),
Example
Address_obj Address_T,
PhoneList_var Phone_T,
) NOT FINAL;
CREATE TYPE Temporary_Employees UNDER Emp_type
( Resume varchar(50) NOT NULL,
); 40
Cont.…
The clause NOT FINAL enables us to create subtypes.
By default, types are created as FINAL, which means that the type
cannot be further specialized by deriving from it.
General Classification
Simple Data Complex Data
Query Relational DBMS Object-Relational DBMS
No File System Object-Oriented DBMS
Query
41
42