Introduction To Objects & Databases: Theory, Practice & Methodology of Relational Database Design and Programming
Introduction To Objects & Databases: Theory, Practice & Methodology of Relational Database Design and Programming
of Relational Database
Design and Programming
Copyright © Ellis Cohen 2002-2006
Introduction to
Objects & Databases
1
Topics
It
It can
can be
be useful
useful to to think
think ofof each
each row
row as
as
an
an object
object or
or entity
entity (i.e.
(i.e. an
an instance
instance of
of
an
an entity
entity class)
class) andand thethe table
table as
as aa
collection
collection of of these
these objects
objects
The
The columns
columns of of the
the table
table correspond
correspond to to
the
the instance
instance variables
variables for for each
each object
object
© Ellis Cohen 2001-2006 6
Object Mapping
works
[manager] for
Employee Dept
empno deptno
ename dname
[worker] job
manages address
Relational Mapping
Mapping an ER model to a Relational Model
Object Mapping
Mapping an ER model to an Object Model
Collections
Set (no duplicates)
Bag (duplicates)
Lists (ordered, duplicates)
Array (list w efficient indexing)
References (Pointers)
© Ellis Cohen 2001-2006 8
Object Definition Language (ODL)
class Employee {
attribute int empno;
attribute string ename;
attribute string job;
attribute Struct[street,city,state,zip] address;
relationship Dept dept inverse Dept::empls;
}
class Dept {
attribute int deptno;
attribute string dname;
relationship Set<Employee> empls
inverse Employee::dept;
emp2
dept2 emp3
dept
emp4
dept3
emp5
empls
© Ellis Cohen 2001-2006 10
ODL Exercise
class Dept {
attribute int deptno;
attribute string dname;
relationship Set<Employee> empls
inverse Employee::dept;
Given an employee e
e.dept - department of e
e.dept.deptno – the # of e's dept
e.dept.dname – the name of e's dept
Given a department d
d.empls – the set of employees
who work in dept d
SELECT e.empno
FROM e IN d.empls
the employee numbers of the employees
who work in department d
SELECT e.empno, e.ename
FROM e IN d.empls
the employee numbers & names of the
employees who work in department d
emp2
dept2 emp3
dept
depts
emp4 emps
dept3
emp5
empls
© Ellis Cohen 2001-2006 19
Queries involving Extents
SELECT e.empno
FROM e IN emps
WHERE e.ename = 'SMITH'
In particular
– the DB is modelled in ODL
– queries are written in ODL
– ODL queries are automatically
mapped to SQL
Hierarchical DB XML DB
Network DB OO/OR DB
Relational DB (RDB)
MultiDimensional DB Deductive DB
In an OODB
Objects exist independently, not just as
rows in a table
An object may have a reference to
another object (allowing navigation)
Instead of a table, there are collections,
which contain references to objects