Chapter 1 OODB
Chapter 1 OODB
Chapter one
OBJECT-BASED DATABASES
Traditional database applications like airline reservation and employee management consist of des
processing tasks with relatively simpler data types such as integers, dates, and strings, which an
well suited to the relational model. However, complex database applications such as Computer
Auded Design (CAD), Computer Aided Software Engineering (CASE), and Geographical
Information tem (GIS) demand the use of complex data types to represent multivalued attributes,
composite m butes, and inheritance. Such features can be easily represented in the E-R and
Extended E-R model but are difficult to translate into relational model using simpler SQL data
types. Thus, the need of new database model that allows us to deal with complex data types arose.
The new database model proposed was based on the concept of object, since objects represent
complex data types naturally. The concept of object was implemented in the database system in
he ways, which resulted in object-relational and object-oriented systems. These object-based
database systems provide a richer type system including complex data types and object orientation.
This chapter discusses both of them in detail.
1
Advanced Database by Fk£
Another major reason for the development of object-based databases is the increasing use of
object-oriented programming languages in software development. Traditional databases seem to
be difficult to use with software applications that are developed in object-oriented languages
such as C++, Smalltalk, or Java. Object-oriented databases are designed so that they can be
directly integrated with the applications that are developed using object-oriented programming
language.
2
Advanced Database by Fk£
We can now use the defined type (that is, AddressType) as a type for an attribute while creat ing
a relation. For example, a relation PUBLISHER can be created by declaring an attribute Pad
dress of type Address Type as shown here
The attribute Paddress in the PUBLISHER relation is now a composite attribute having
HouseNo, Street, City, State, and Zip as its components.
The row types discussed so far hav bee names associated with them. SQL provides an alternative
way of defining composite attributes by using unnamed row types. To illustrate this, consider the
following declaration.
3
Advanced Database by Fk£
Note that the attribute Paddress has unnamed type and rows of the relation also have an unnamed
type.
Now in order to access the components of a composite attribute "dot" notation is used. For
example. Paddress. City returns the city component of the Paddress attribute. For example,
consider the following query.
In addition to creating an attribute of user-defined type in a relation, SQL also allows creating a
relation whose rows are of a user-defined type. For example, we can define a type
PublisherType, which can be further used to create a relation PUBLISHER as follows
An array type is used to specify an attribute (multivalued attribute) whose value will be a collec-
tion. For example, an author can have many phone numbers, thus, the attribute Phone can be
repre- sented using array type
4
Advanced Database by Fk£
Defining Methods
We can also define methods on the structured types. The methods are declared as part of the type
definition as shown here
Here method ShowName is declared that takes P ID as parameter and it is supposed to return the
name of the publisher. The method body is created separately as shown here.
CREATE INSTANCE METHOD ShowName (P_ID VARCHAR (20))
RETURNS VARCHAR (50)
FOR PublisherType
BEGIN
RETURN SELF. Pname;
END
In this declaration, the FOR clause indicates that the method is declared for the type
PublisherType, and the keyword INSTANCE indicates that the method executes on an instance
of PublisherType. Note that the method returns Pname by using the variable SELF, which refers
to the current instance of PUBLISHER on which the method is invoked.
5
Advanced Database by Fk£
2. Inheritance
Unlike relational system, object-relational database system supports inheritance directly. In chips
relational database system, inheritance can be used in two ways: for reusing and refining types i
inheritance) and for creating hierarchies of collection of similar objects (table inheritance).
Unlike relational system, object-relational database system supports inheritance directly. In chips
relational database system, inheritance can be used in two ways: for reusing and refining types i
inheritance) and for creating hierarchies of collection of similar objects (table inheritance).
NOTE SQL:1999 and SQL:2003 supports only single inheritance. Though it may possible that
future versions of SQL support multiple inheritance also.
2.1 Inheritance
Type Inheritance
Consider the following type definition for BookType.
CREATE TYPE BookType (
Book title VARCHAR (50),
Category VARCHAR (50),
Price NUMERIC (4),
Copyright_date NUMERIC (4),
Year NUMERIC (4),
Page_count NUMERIC (4),
P ID VARCHAR (50)) NOT FINAL;
6
Advanced Database by Fk£
Further, suppose that want store additional information in the database about the books that are
textbooks. Instead of creating separate type for text book we can inherit BookType to define type
TextBookType shown here.
This statement creates a new type TextBookType, which inherits the attributes of BookType,
plus it has one additional attribute Subject. Here, BookType is a supertype of TextBookType,
and TextBookType is a subtype of BookType.
Note that the keyword NOT FINAL states that the subtypes can be created from the given type.
In addition, SQL also provides FINAL keyword, which states that subtypes cannot be created
from the given type.
7
Advanced Database by Fk£
OODBMS
It supports ODL and OQL for defining and manipulating complex data types.
The query facilities of OQL are not supported efficiently in most OODBMS.
8
Advanced Database by Fk£