Object-Based Databases by Jose Reyes Jose

Download Report

Transcript Object-Based Databases by Jose Reyes Jose

Object-Based Databases
Jose Reyes Jose
Overview
• Object-relational data model extends the
relational data model by providing a richer
type system including complex data types
and object orientation
• Database systems based on the objectrelation model provide a convenient migration
path for users of relational databases who
wish to use object-oriented features
Complex Data Types
•
•
•
•
Book title
List of authors
Publisher
Set of keywords
4NF Decomposition
Nested Relation
Structured Types
Create type Name as
(firstname varchar(20),
lastname varchar(20))
final
Create type Address as
(street varchar(20),
city
varchar(20),
zipcode varchar(20))
not final
Note: final and not final indicate where
subtypes can be created
Structured Types cont…
Create table customer(
name Name,
address Address,
dateOfBirth date)
Create type CustomerType as (
name Name,
address Address,
dateOfBirth date)
not final
Create table customer of CustomerType
Create table customer(
name row (firstname varchar(20),
lastname varchar(20))
address row (street varchar(20),
city varchar(20),
zipcode varchar(9)),
dateOfBirth date)
Select name.lastname, address.city
From customer
We add a method to a structured type definition:
create type CustomerType as (
name Name,
address Address,
dateOnBirth date)
not final
method ageOnDate(onDate date)
returns interval year
We create the method body separately:
create instance method ageOnDate(onDate date)
returns interval year
for CustomerType
begin
return onDate -- self.dateOfBirth;
end
Select name.lastname, ageOnDate(current_date)
From customer
create function
Name(firstname varchar(20), lastname varchar(20))
returns Name
begin
set self.firstname = firstname;
set self.lastname = lastname;
end
insert into Customer
values
(new Name(‘John’, ‘Smith’),
new Address(‘20 Main St’, ‘New York’, ‘11001’),
date ‘1960-8-22’)
Inheritance
create type Person
(name varchar(20),
address varchar(20))
create type Student
under Person
(degree varchar(20),
department varchar(20))
create type Teacher
under Person
(salary integer,
department varchar(20))
create type TeachingAssistant
under Student with (department as student_dept),
Teacher with (department as teacher_dept)
Conclusion
• object based database simplify complex
data types
• the SQL for structuring these data types
• the SQL for methods and inheritance
References
• http://highered.mcgrawhill.com/sites/0072958863/
• Database System Concepts 5th edition