Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Object-Oriented Language
Nested Relation
Inheritance
Reference Type
Data Encapsulation
eg: C++
Object Structure
• An object has associated with it
Method
E.g:
Group object for people into a person class
Classes are analogous to entity sets in the E-R
model
Class Definition Example
Class employee{
/*variables*/
String name;
String address;
date start-date;
int salary;
/*Message */
int annual-salary();
String get-name():
String get-address();
int set-address(String new-address);
int employment-length();
};
• Strict encapsulation,methods to read and set other variables are also needed
• Employment-length is an example of a derived attribute
Object Oriented languages
Object-Oriented Languages
• Object-oriented concepts can be used as a design tool, and be encoded
• Reference-declare(root) object
Object Identity and Pointers
• Object is assigned a object identifier.
Overloading
-Difficult to use
ODMC C++ Object Definition Language
• C++ to support persistence
String name;
String address;
};
class Customer:public Person{
public:
Date member_from;
int customer_id;
Ref<Branch>home_branch;
Set<Ref<Account>> accounts inverse Account::owners;
};
ODMG C++ Object Manipulation
Language
• C++ operator new(db)
Database * bank_db;
Bank_db=Database::open(“Bank-DB”);
Transaction Trans;
Trans.begin();
Ref<Customer>cust=new(bank_db) Customer;
Cust->name=name;
Cust->address=address;
Cust->accounts.insert_element(account);
account-> owner.insert_element(cust);
}
Object Relational Database
Object Relational databases
• The object-relational data model
-title->audhor
-title->keyword
-title->pub-name,pub-branch
• Decompose data into 4NF
-(title,audhor)
-(title,keyword)
-(title,pub-name,pub-branch)
4NF Decomposition of data
Keywords
Authors
Problems with 4NF Schema
• 4NF ->Joins
• One-to-one correspondence
Define a type
create type Teaching Assistant
under Student,Teacher
• Two occurrences of department
create type Teaching Assistant
under
Student with(departmentas student-dept),
Teacher with(departmentas teacher-dept)
Table Inheritance
• It support multiple type.Entity to exist
under people
Create table teachers of Teacher
under people
• Subtable->student and teacher
• Supertables->people
Table Inheritance:Role
• Most-specific type(unlike type inheritance)
– Supertables implicitly
– Tuple is faster
Inheritance Operation
• Specialization
animals
vertebrates
invertebrates
mammals
birds
Reference Type
Reference Type
• Object –oriented languages provide create and refer to object.
• Type->person
• Table people as scople
• E.g
values(‘cs’,null)
update departments
set head=(select ref(p) from people as p
where name=‘john’)
where name=‘CS’
Query with complex type
Querying with Complex Type
• The name of publisher of each book
select title,publisher.name
from books
• The use dot notation to access fields of the composite attribute
Eg
select title from books where ‘database’ in(unnest(keyword-set))
Nesting
• Nesting-> opposite of unnesting
• Similar to aggregation
• Function set()->aggregation operation
• Eg:
from falt-books
groupby title,audhor,publisher
Nesting(cont…)
• Another approach to creating nested relation is to use subqueries in
the select caluse
select title,
Publisher(pub-name,pub-branch)as Publisher,
– Disadvantages:
returns integer
begin
declare a-count integer;
• Eg
– Self.a
SQL Function and Procedure(cont..)
• The author-count function
• create procedure author-count-pro(in title varchar(20),out a-count
integer)
begin
select count(author) into a-count
from authors
where author.title=title
End
• Procedure from embedded sql
• Eg
declare a-count integer
call author-count-proc(‘database systems concepts’,a-count);
External language Function/Procedures
• Function and procedure written in c and c++
language C;
return integer
language c
external name ‘usr/avi/bin/author-count’
Benefits &Drawbacks
• Benefits:
risk of accidental
security risk
Procedural constructs
• Supports a rich variet of procedural construct
• Compound statement
– Is of the from begin..end
– May contain multiple SQL statement
– Begin and end
– Local variable declared in compound statement
Eg:
While and repeat statements
declare n integer default 0;
while n<10 do
set n=n+1
End while repeat set n=n-1 until n=0 End repeat
• For loop
Eg:
declare n integer default 0;
for r as
do
set n=n+r.balance
end for
Comparison of object oriented and object
relational databases
Comparison of O-O and O-R Database
• Relational systems
simple data type
High performace
• Object-relational System
High protection