Advanced Database System(CoSc2042)
Chapter one
Object-oriented & object-relational databases
1
Objectives
2
Definition of Terms
Database is an organized collection of related data held in
a computer or a data bank, which is designed to
be accessible in various ways.
The technology of storing and retrieving users’ data
DBMS with utmost efficiency along with appropriate
security measures.
A software package/ system to facilitate the creation
and maintenance of a computerized database.
Database
The DBMS software together with the
System:
data itself.
3
Types of DBMS Models
4
Hierarchical Database Model.
• In a Hierarchical database model, the
data is organized in a tree-like
structure.
• Data is Stored Hierarchically (top
down or bottom up) format.
• Data is represented using a parent-
child relationship that are one to one
or one to many.
• In Hierarchical DBMS parent may
have many children, but children have
only one parent.
5
Network Database Model
• The network database model allows each child to have multiple parents.
• More complex relationships such as the orders/parts many-to-many
relationship.
• The entities are organized in a graph which can be accessed through
several paths.
6
Relational Database Model
• Most widely used DBMS model
• Easiest
• Based on normalizing data in the rows and columns of the tables.
• Data is stored in fixed structures and manipulated using SQL.
7
Relational model (70’s):
Clean and simple.
Great for administrative and transactional data.
Not as good for other kinds of complex data (e.g.,
multimedia, networks, CAD).
Relations are the key concept, everything else is around
relations
Primitive data types, e.g., strings, integer, date, etc.
Great normalization, query optimization, and theory
8
What is missing??
Handling of complex objects
Handling of complex data types
Code is not coupled with data
No inherence, encapsulation, etc.
9
Object-Oriented Database Model
• In Object-oriented Model data stored in the form of objects.
• The structure which is called classes which display data within it.
• It defines a database as a collection of objects which stores both data
members values and operations.
10
Object-Oriented models (80’s):
Complicated, but some influential ideas from Object
Oriented
Complex data types.
Programming languages
Idea: Build DBMS have
based on evolved from Procedural to Object
OO model.
Oriented. So why not DBMSs ???
• Properties
• Name
• Height
• Weight……..
• Behaviors
• Eat
• Pray
• Walk …..
Application areas
: Computer aided software engineering
: Computer aided design
: Computer aided manufacture
12
OO vs. EER Data Modeling
Object Oriented EER
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)
Logical & physical layers
14
OO concepts (mandatory concepts)
The Golden Rules/1 DBMS concepts (mandatory concepts)
Complex objects The Golden Rules/2
Persistence
Object identity
Secondary storage management
Encapsulation Concurrency
Recovery
Types and/or Classes
Ad Hoc Query Facility
Class or Type Hierarchies
Overriding, overloading
Computational completeness
Extensibility- user-defined types can be used in the same way as
15 system-defined types
The Goodies(Optional concepts that may be implemented)
Multiple inheritance
Type checking and type inferencing
Distribution
Design transactions
Versions
16
Two approaches of Object oriented DB
Object-Oriented Model (OODBMS)
Pure OO concepts
Example: Orian, Iris
Object-Relational Model (ORDBMS)
Extended relational model with OO concepts
Example: Oracle, 8i, SQL Server 2000
17
Object Data Management Group(ODMG )
ODMG— to define standards for OODBMSs.
Its standard is 3.0 which is popular.
provide a standard where previously there was none
support portability between products
standardize model, querying and programming issues
Language of specifying the structure of object database
ODL: Object Definition Language
OQL: Object Query Language
ODL is somehow similar to DDL (Data Definition Language) in
SQL
18
Feature of OODBMS
An object typically has two components:
state (value) and
behavior (operations).
Objects can transient or persistent.
To make the object persistent we need OODBMS.
OO database provides a unique system-generated object
identifier (OID) for each object (similar to the concept of
primary key)
19
ODMG Objects and Literals
The basic building blocks of the object model are:
Objects
Literals
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
Transient - unstable and can be updated and deleted
Persistent – permanent object like (oodb)
Naming – giving name
Reachable- Collecting similar objects under one name.
4. Structure: specifies how the object is constructed by using type constructors
It also Specifies whether the object is atomic or collection type
21
Objects type
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.
22
Atomic constructors
Includes the basic built-in data types of the object
model, which are similar to the basic types in many
programming languages: integers, strings, floating
point numbers, enumerated types, Booleans.
They are called single-valued or atomic types, since
each value of the type is considered an atomic
(indivisible) single value.
23
struct (or tuple) constructor
Create standard structured types, such as the tuples (record
types) in the basic relational model.
Referred to as a compound or composite type
Example
struct Name<FirstName: string, MiddleInitial: char,
LastName: string>,
struct CollegeDegree<Major: string, Degree: string, Year:
date>.
24
Collection (or multivalued)
Collection is used to create complex nested type structures in
the object model.
Collection type constructors includes;
Set(T),
List(T),
Bag(T),
Array(T), and
Dictionary(K,T) type constructors.
25
Collection Objects(types)
Set<T>: unordered collections that do not allow duplicates.
used to create objects such that the value of the object is set
whose elements are of type T.
Operations : Intersection, union, & set difference.
Bag<T>: allows duplicate elements in the collection and also inherits the
collection interface.
Has three operations
Create_union(b)
Create_intersection(b) and
Create_difference(b) that all return a new object of type Bag<T>
26
Con…
List<T>: create collections where the order of the elements is
important.
The value of object is an ordered list whose elements are of type
T.
We can refer to the first, last, and ith element in the list.
Operations
O.insert_element_first(E)— inserts the element E before the first
element in the list O.
O.insert_element_last(E) &
O.insert_element_after(E, I)—inserts the element E after the ith
element in the list O and Raise the exception InvalidIndex if no ith
element exists in O.
E = O.remove_first_element(),
E = O.remove_last_element(), and
27 E = O.remove_element_at(I) remove the indicated element from the
Con…
E = O.retrieve_first_element(),
E = O.retrieve_last_element(), and
E = O.retrieve_element_at(I) are used to retrieve an element
without removing it from the list
To manipulate lists two operations are defined.
P = O.concat(I) creates a new list P that is the concatenation
of lists O and I (the elements in list O followed by those in list
I), and
28O.append(I) appends the elements of list I to the end of list O
Con…
Array<T>: set of sorted list referenced by index.
Operations
O.replace_element_at(I, E) replaces the array element at position
I with element E;
E = O.remove_element_at(I) retrieves the ith element and
replaces it with a NULL value; and
E = O.retrieve_element_at(I) simply retrieves the ith element of
the array.
Any of these operations can raise the exception InvalidIndex if I is
greater than the array’s size.
O.resize(N) changes the number of array elements to N.
29
Con…
Dictionary<K,V>: allows the creation of a collection of
association pairs <K,V>, where all K (key) and V(values) are
unique.
Operations
If O is a collection object of type dictionary<K,V>, then
O.bind(K,V) binds value V to the key K
O.unbind(K) removes the association with key K from O, and
V = O.lookup(K) returns the value V associated with key K in O.
The latter two operations can raise the exception KeyNotFound.
O.contains_key(K) returns true if key K exists in O, and returns false
30otherwise.
Object types
An object is made of two things:
State: is defined by the values of an object carries for a set of
properties, which may be either an attribute of the object or a
relationship between the object and one or more other objects.
Attributes (name, address, birthDate of a person)
Behaviour: is defined by a set of operations that can be
performed on or by the object.
operations (age of a person is computed from birthDate and
current date)
31
Object types
• Department, Performance, Marriage,
Registration
Concept or
Event
• User interface, Controller, Scheduler
Artifact of the
Design
Process
Object Factory
The object that helps to generate many objects through
operations.
Example:
Date object – can generate many calendar dates
Ethiopian calendar
European calendar
Arabic calendar
Indian calendar
Attributes
An attribute is defined on a single object type.
Takes as its value a literal or an object identifier.
Example: a Branch class has attributes for the branch number,
street, city, and postcode.
34
Relationships
Relationships are defined between types.
Only binary relationships with cardinality 1:1, 1:*, and *:*.
A relationship have a name &, is not a ‘first class’ object;
Traversal paths are defined for each direction of traversal.
Example: a Branch Has a set of Staff and a member of Staff WorksAt a
Branch.
35
Relationships
36
Relationships
37
Operations
A function or service that is provided by all instances of a class
Types of operations:
Constructor: creates a new instance of a class
Query: accesses the state of an object but does not alter its
state
Update: alters the state of an object
Scope: operation applying to the class instead of an instance
Operations implement the object’s behavior
Powerful Type System
Primitive types
• Integer, string, date, Boolean, float, etc.
Structure type
• Attribute can be a record with a schema
• Struct {integer x, string y}
Collection type
• Attribute can be a Set, Bag, List, Array of other types
Reference type
• Attribute can be a Pointer to another object
Example Of UML Classes
Identity
Identity: every object has a unique identity
Object identity must be unique and non-volatile(immutable)
In time: can not change and can not be re-assigned to another
object, when the original object is deleted
In space: must be unique within and across database
boundaries
Types, classes, interfaces, and inheritance
In the ODMG Object Model there are two ways to specify object
types:
Interfaces, and
classes.
Interface --- defines only the abstract behavior of an object type,
using operation signatures.
Allows behavior to be inherited by other interfaces and classes
using the ‘:’ symbol.
properties (attributes and relationships) cannot be inherited.
42Interface is Noninstantiable
Classes
Class defines both the abstract state and behavior of an object
type.
Class is instantiable (thus, interface is an abstract concept and
class is an implementation concept).
Use the extends keyword to specify single inheritance between
classes. Multiple inheritance is not allowed.
Classes encapsulate data + methods + relationships
In OODBMSs objects are persistent (unlike OO programming
languages)
43
The interface part of an operation is sometimes called the signature, and the
Extents and keys
Extent and keys are Specified during class definition:
Extent is the set of all instances of a given type within a particular
ODMS.
Deleting an object removes the object from the extent of the type.
Key uniquely identifies the instances of a type (similar to the concept
of a candidate key).
A type must have an extent to have a key.
A key is different from an object name; key is composed of
properties specified in an object type’s interface whereas an object
44
name is defined within the database type.
Abstraction, Encapsulation, and Information Hiding
Abstraction is the process of identifying the essential aspects of
an object by ignoring an irrelevant properties.
Encapsulation -- 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.
Information hiding-- separate the external aspects of an object
from its internal details, which are hidden from the outside world.
45
Focus more on data security
Encapsulation
To encourage encapsulation, an operation is defined in
two parts.
Signature or interface of the operation specifies the operation
name and arguments (or parameters).
Method or body specifies the implementation of the operation,
General purpose programming language.
Operations can be invoked by passing a message.
46
Inheritance
Person
A class can be defined in terms of another one.
name: {firstName: string,
middleName: string,
Allows the definition of new types based on other lastName: string}
address: string
predefined types, leading to a type (or class) birthDate: date
age(): Integer
hierarchy. changeAddress(newAdd: string)
Example
Person is super-class and Student is sub- Student
class. regNum: string {PK}
major: string
Student class inherits attributes and register(C: Course): boolean
operations of Person.
47
Types of inheritance(Multiple and Selective Inheritance)
Multiple inheritance: a class inherits features from more than
one superclass .
Example: Engineer_Manager that is a subtype of both Engineer and
Manager.
This leads to the creation of a type lattice rather than a type hierarchy.
Selective inheritance: occurs when a subtype inherits only some
of the functions of a super type.
The mechanism of selective inheritance is not typically
provided in ODBs,
It is used more frequently in artificial intelligence applications.
48
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
49
Overloading Overriding
Extensibility
Extensibility allows the creation of new data types, i.e. user-
defined types, and operations from built-in atomic data types and
user defined data types using the type constructor.
A type constructor is a mechanism for building new domains.
A complex object is built using type constructors such as sets,
tuples, lists and nested combinations.
A combination of an user-defined type and its associated
methods is called an abstract data type (ADT).
51
Versioning
The process of maintaining the evolution of objects is known as
version management.
An object version represents an identifiable state of an object;
a version history represents the evolution of an object.
Versioning should allow changes to the properties of objects to
be managed in such a way that object references always point
to the correct version of an object.
52
Overview of ODL & OQL
The Object Definition Language (ODL) is a language for
defining the specifications of object types for ODMG-compliant
systems.
The ODL defines the attributes and relationships and signature of
the operations, but it does not address the implementation of
signatures.
53
Overview of ODL & OQL
The Object Query Language (OQL) 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.
54
Querying object-relational database
Most relational operators work on the object-relational tables
E.g., selection, projection, aggregation, set operations
Several major software companies including IBM, Informix,
Microsoft, Oracle, and Sybase have all released object-relational
versions of their products.
SQL-99 (SQL3): Extended SQL to operate on object-relational
databases
55
Defining Generalization
OQL following the given classes;
Con…
Suppose we want to find the title and credit hours for MBA 664.
Find the age of John Marsh
returns a collection (bag) of
student objects for which the gpa
Con… is greater than or equal to 3.0.
• Finding student objects having gpa 3;
• select s from students s where s.gpa = 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”;
Con…
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.crse_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.crse_code, c.crse_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.
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);
Calculating Group Summary Values
select min (e.salary) from employees e group by e.gender;