0% found this document useful (0 votes)
125 views

Object Oriented Databases Oodb

oodb

Uploaded by

mahmoud shaheen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Object Oriented Databases Oodb

oodb

Uploaded by

mahmoud shaheen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 35

Object Oriented Databases

OODB

Copyright © 2004 Pearson Education, Inc.


Introduction

 Traditional Data Models : Hierarchical, Network (since mid-


60’s), Relational (since 1970 and commercially since 1982)
 Object Oriented (OO) Data Models since mid-90’s
 Reasons for creation of Object Oriented Databases
– Need for more complex applications
– Need for additional data modeling features
– Increased use of object-oriented programming languages
 Commercial OO Database products – several in the 1990’s,
but did not make much impact on mainstream data
management

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
History of OO Models and Systems

 Languages: Simula (1960’s), Smalltalk (1970’s), C++


(late 1980’s), Java (1990’s)
 Experimental Systems: Orion at MCC, IRIS at H-P
labs, Open-OODB at T.I., ODE at ATT Bell labs,
Postgres - Montage - Illustra at UC/B,
Encore/Observer at Brown
 Commercial OO Database products: Ontos,
Gemstone, O2 ( -> Ardent), Objectivity, Objectstore (
-> Excelon), Versant, Poet, Jasmine (Fujitsu – GM)

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Overview of Object-Oriented Concepts

 MAIN CLAIM: OO databases try to maintain a


direct correspondence between real-world and
database objects so that objects do not lose their
integrity and identity and can easily be identified
and operated upon
 Object: Two components: state (value) and
behavior (operations). Similar to program variable
in programming language, except that it will
typically have a complex data structure as well as
specific operations defined by the programmer
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Overview of Object-Oriented Concepts

 In OO databases, objects may have an object


structure of arbitrary complexity in order to contain
all of the necessary information that describes the
object.
 In contrast, in traditional database systems,
information about a complex object is often
scattered over many relations or records, leading to
loss of direct correspondence between a real-world
object and its database representation.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
 Object identity: Objects have unique identities that
are independent of their attribute values.
 Type constructors: Complex object structures can
be constructed by recursively applying a set of
basic constructors, such as tuple, set, list, and bag.
 Encapsulation of operations: Both the object
structure and the operations that can be applied to
objects are included in the object class definitions.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
 Programming language compatibility: Both
persistent and transient objects are handled
uniformly. Objects are made persistent by
being attached to a persistent collection.
 Type hierarchies and inheritance: Object
types can be specified by using a type
hierarchy, which allows the inheritance of
both attributes and methods of previously
defined types.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
 Extents: All persistent objects of a particular type can
be stored in an extent. Extents corresponding to a
type hierarchy have set/subset constraints enforced on
them.
 Support for complex objects: Both structured and
unstructured complex objects can be stored and
manipulated.
 Polymorphism and operator overloading: Operations
and method names can be overloaded to apply to
different object types with different implementations.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
The Object Model of ODMG

 Provides a standard model for object


databases
 Supports object definition via ODL
 Supports object querying via OQL
 Supports a variety of data types and type
constructors

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
ODMG Objects and Literals
 The basic building blocks of the object model are
– Objects
– Literlas
 An object has four characteristics
1. Identifier: unique system-wide identifier
2. Name: unique within a particular database and/or
program; it is optional
3. Lifetime: persistent vs transient
4. Structure: specifies how object is constructed by the
type constructor and whether it is an atomic object

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
ODMG Literals
 A literal has a current value but not an identifier
 Three types of literals
1. atomic: predefined; basic data type values (e.g.,
short, float, boolean, char)
2. structured: values that are constructed by type
constructors (e.g., date, struct variables)
3. collection: a collection (e.g., array) of values or objects

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Collection Objects

 A collection object inherits the basic


collection interface, for example:
– cardinality()
– is_empty()
– insert_element()
– remove_element()
– contains_element()
– create_iterator()

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-12


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Collection Types
 Collection objects are further specialized into types
like a set, list, bag, array, and dictionary
 Each collection type may provide additional
interfaces, for example, a set provides:
– create_union()
– create_difference()
– is_subst_of(
– is_superset_of()
– is_proper_subset_of()

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-13


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Object Inheritance Hierarchy

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-14


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Atomic Objects
 Atomic objects are user-defined objects and
are defined via keyword class
 An example:
class Employee (extent all_emplyees key ssn) {
attribute string name;
attribute string ssn;
attribute short age;
relationship Dept works_for;
void reassign(in string new_name);
}

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Class Extents
 An ODMG object can have an extent defined via
a class declaration
 Each extent is given a name and will contain all
persistent objects of that class
 For Employee class, for example, the extent is
called all_employees
 This is similar to creating an object of type
Set<Employee> and making it persistent

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-16


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Class Key
 A class key consists of one or more unique
attributes
 For the Employee class, the key is ssn
Thus each employee is expected to have a
unique ssn
 Keys can be composite, e.g.,
(key dnumber, dname)

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-17


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Object Definition Language

 ODL supports semantics constructs of


ODMG
 ODL is ndependent of any programming
language
 ODL is used to create object specification
(classes and interfaces)
 ODL is not used for database manipulation

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-18


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
ODL Examples (1)
A Very Simple Class
 A very simple, straightforward class
definition
class Degree {
attribute string college;
attribute string degree;
attribute string year;
};

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-19


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
ODL Examples (2)
A Class With Key and Extent
 A class definition with “extent”, “key”, and more
elaborate attributes; still relatively straightforward

class Person (extent persons key ssn) {


attribute struct Pname {string fname …} name;
attribute string ssn;
attribute date birthdate;

short age();
}

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-20


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
ODL Examples (3)
A Class With Relationships
 Note extends (inheritance) relationship
 Also note “inverse” relationship

Class Faculty extends Person (extent faculty) {


attribute string rank;
attribute float salary;
attribute string phone;

relationship Dept works_in inverse Dept::has_faculty;
relationship set<GradStu> advises inverse GradStu::advisor;
void give_raise (in float raise);
void promote (in string new_rank);
};

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-21


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Object Query Language

 OQL is DMG’s query language


 OQL works closely with programming
languages such as C++
 Embedded OQL statements return objects
that are compatible with the type system of
the host language
 OQL’s syntax is similar to SQL with
additional features for objects
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-22
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Simple OQL Queries
 Basic syntax: select…from…where…
SELECT d.name
FROM d in departments
WHERE d.college = ‘Engineering’;
 An entry point to the database is needed for
each query
 An extent name (e.g., departments in the
above example) may serve as an entry point
 Iterator variable d

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-23


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Data Type of Query Results

 The data type of a query result can be any


type defined in the ODMG model
 A query does not have to follow the
select…from…where… format
 A persistent name on its own can serve as a
query whose result is a reference to the
persistent object, e.g., departments; whose
type is set<Departments>

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-24


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Path Expressions

 A path expression is used to specify a path to


attributes and objects in an entry point
 A path expression starts at a persistent object
name (or its iterator variable)
 The name will be followed by zero or more
dot connected relationship or attribute
names, e.g., departments.chair;

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-25


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Views as Named Objects

 The define keyword in OQL is used to


specify an identifier for a named query
 The name should be unique; if not, the
results will replace an existing named query
 Once a query definition is created, it will
persist until deleted or redefined
 A view definition can include parameters

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-26


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
An Example of OQL View
 A view to include students in a department
who have a minor:

define has_minor(dept_name) as
select s
from s in students
where s.minor_in.dname=dept_name
 has_minor can now be used in queries

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-27


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Single Elements from Collections

 An OQL query returns a collection


 OQL’s element operator can be used to
return a single element from a singleton
collection that contains one element:
element (select d from d in departments)
where d.dname = ‘Software Engineering’);

 If d is empty or has more than one elements,


an exception is raised

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-28


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Collection Operators

 OQL supports a number of aggregate


operators that can be applied to query results
 The aggregate operators include min,
max, count, sum, and avg and operate
over a collection
 count returns an integer; others return the
same type as the collection type

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-29


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
An Example of an OQL
Aggregate Operator
 To compute the average GPA of all seniors
majoring in Business:

avg (select s.gpa from s in students


where s.class = ‘senior’ and
s.majors_in.dname =‘Business’);

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-30


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Membership and Quantification

 OQL provides membership and


quantification operators:
– (e in c) is true if e is in the collection c
– (for all e in c: b) is true if all e
elements of collection c satisfy b
– (exists e in c: b) is true if at least one
e in collection c satisfies b

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-31


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
An Example of Membership

 To retrieve the names of all students who


completed CS101:

select s.name.fname s.name.lname


from s in students
where ‘CS101’ in
(select c.name from c in
s.completed_sections.section.of_course);

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-32


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Ordered Collections

 Collections that are lists or arrays allow


retrieving their first, last, and ith
elements
 OQL provides additional operators for
extracting a sub-collection and concatenating
two lists
 OQL also provides operators for ordering the
results

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-33


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
An Example of Ordered Operation

 To retrieve the last name of the faculty


member who earns the highest salary:

first (select struct


(faculty: f.name.lastname,salary f.salary)
from f in faculty
ordered by f.salary desc);

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-34


Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Grouping Operator
 OQL also supports a grouping operator
called group by
 To retrieve average GPA of majors in each
department having >100 majors:
select deptname, avg_gpa:
avg (select p.s.gpa from p in partition)
from s in students
group by deptname: s.majors_in.dname
having count (partition) > 100

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 21-35


Copyright © 2004 Ramez Elmasri and Shamkant Navathe

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy