figure 12 - cs.boisestate.educs.boisestate.edu/~jhyeh/cs410/cs410_bookfigures_ch12.pdf · ©...
TRANSCRIPT
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Figure 12.1a Overview of the interface definitions for part of the ODMG
object model. The basic Object interface, inherited by all objects.
interface Object {...boolean same_as(in Object other_object);Object copy();void delete();
};
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
inte
rfac
e D
ate
: Obj
ect {
enum
Wee
kday
{Sun
day,
Mon
day,
Tue
sday
, Wed
nesd
ay, T
hurs
day,
Frid
ay, S
atur
day}
;en
umM
onth
{Jan
uary
, Feb
ruar
y, M
arch
, Apr
il, M
ay, J
une,
Jul
y, A
ugus
t, S
epte
mbe
r, O
ctob
er, N
ovem
ber,
Dec
embe
r};
unsi
gned
sho
rtye
ar()
;un
sign
ed s
hort
mon
th()
;un
sign
ed s
hort
day(
);… bo
olea
nis
_equ
al(in
Dat
e ot
her_
Dat
e);
bool
ean
is_g
reat
er(in
Dat
e ot
her_
Dat
e);
…}; in
terf
ace
Tim
e : O
bjec
t {… un
sign
ed s
hort
hour
();
unsi
gned
sho
rtm
inut
e();
unsi
gned
sho
rtse
cond
();
unsi
gned
sho
rtm
illis
econ
d();
… bool
ean
is_e
qual
(in T
ime
othe
r_T
ime)
;bo
olea
nis
_gre
ater
(in T
ime
othe
r_T
ime)
;… T
ime
add_
inte
rval
(in In
terv
al s
ome_
Inte
rval
);T
ime
subt
ract
_int
erva
l(in
Inte
rval
som
e_In
terv
al);
Inte
rval
subt
ract
_tim
e(in
Tim
e ot
her_
Tim
e);
}; inte
rfac
e T
imes
tam
p : O
bjec
t {… un
sign
ed s
hort
year
();
unsi
gned
sho
rtm
onth
();
unsi
gned
sho
rtda
y();
unsi
gned
sho
rtho
ur()
;un
sign
ed s
hort
min
ute(
);un
sign
ed s
hort
seco
nd()
;un
sign
ed s
hort
mill
isec
ond(
);… T
imes
tam
ppl
us(in
Inte
rval
som
e_In
terv
al);
Tim
esta
mp
min
us(in
Inte
rval
som
e_In
terv
al);
bool
ean
is_e
qual
(in T
imes
tam
p ot
her_
Tim
esta
mp)
;bo
olea
nis
_gre
ater
(in T
imes
tam
p ot
her_
Tim
esta
mp)
;…
}; inte
rfac
e In
terv
al :
Obj
ect {
unsi
gned
sho
rtda
y();
unsi
gned
sho
rtho
ur()
;un
sign
ed s
hort
min
ute(
);un
sign
ed s
hort
seco
nd()
;un
sign
ed s
hort
mill
isec
ond(
);… In
terv
alpl
us(in
Inte
rval
som
e_In
terv
al);
Inte
rval
min
us(in
Inte
rval
som
e_In
terv
al);
Inte
rval
prod
uct(
in lo
ng s
ome_
valu
e);
Inte
rval
quot
ient
(in lo
ng s
ome_
valu
e);
bool
ean
is_e
qual
(in In
terv
al o
ther
_Int
erva
l);bo
olea
nis
_gre
ater
(in In
terv
al o
ther
_Int
erva
l);…
};
Figure 12.1b Overview of the interface definitions for part of the ODMG
object model. Some standard interfaces for structured literals.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
inte
rfac
e C
olle
ctio
n : O
bjec
t {... ex
cept
ion
Ele
men
tNot
Fou
nd{a
ny e
lem
ent;
};un
sign
ed lo
ngca
rdin
ality
();
bool
ean
is_e
mpt
y();
... bool
ean
cont
ains
_ele
men
t(in
any
ele
men
t);
void
inse
rt_e
lem
ent(
in a
ny e
lem
ent)
;vo
idre
mov
e_el
emen
t(in
any
ele
men
t)
rai
ses(
Ele
men
tNot
Fou
nd);
Itera
tor
crea
te_i
tera
tor(
in b
oole
an s
tabl
e);
...}; in
terf
ace
Itera
tor
{ex
cept
ion
NoM
oreE
lem
ents
();
... bool
ean
is_s
tabl
e();
bool
ean
at_e
nd()
;vo
idre
set(
);an
yge
t_el
emen
t()
rais
es(N
oMor
eEle
men
ts);
void
next
_pos
ition
() r
aise
s(N
oMor
eEle
men
ts);
...}; in
terf
ace
Set
: C
olle
ctio
n {
Set
crea
te_u
nion
(in S
et o
ther
_set
);... bo
olea
nis
_sub
set_
of(in
Set
oth
er_s
et);
...}; in
terf
ace
Bag
: C
olle
ctio
n {
unsi
gned
long
occu
rren
ces_
of(in
any
ele
men
t);
Bag
crea
te_u
nion
(in B
ag o
ther
_bag
);...
}; inte
rfac
e Li
st :
Col
lect
ion
{ex
cept
ion
Inva
lid_I
ndex
{uns
igne
d_lo
ng in
dex;
};
void
rem
ove_
elem
ent_
at(in
uns
igne
d lo
ng p
ositi
on)
rais
es(I
nval
idIn
dex)
;an
yre
trie
ve_e
lem
ent_
at(in
uns
igne
d lo
ng p
ositi
on)
rais
es(I
nval
idIn
dex)
;vo
idre
plac
e_el
emen
t_at
(in a
ny e
lem
ent,
in u
nsig
ned
long
pos
ition
)ra
ises
(Inv
alid
Inde
x);
void
inse
rt_e
lem
ent_
afte
r(in
any
ele
men
t, in
uns
igne
d lo
ng p
ositi
on)
rais
es(I
nval
idIn
dex)
;... vo
idin
sert
_ele
men
t_fir
st(in
any
ele
men
t);
... void
rem
ove_
first
_ele
men
t()
rais
es(I
nval
idIn
dex)
;... an
yre
trie
ve_f
irst_
elem
ent(
) ra
ises
(Inv
alid
Inde
x);
... List
conc
at(in
Lis
t oth
er_l
ist)
;vo
idap
pend
(in L
ist o
ther
_lis
t);
}; inte
rfac
e A
rray
: C
olle
ctio
n {
exce
ptio
nIn
valid
_Ind
ex{u
nsig
ned_
long
inde
x; }
;vo
idre
mov
e_el
emen
t_at
(in u
nsig
ned
long
inde
x)ra
ises
(Inv
alid
Inde
x);
any
retr
ieve
_ele
men
t_at
(in u
nsig
ned
long
inde
x)
rais
es(I
nval
idIn
dex)
;vo
idre
plac
e_el
emen
t_at
(in u
nsig
ned
long
inde
x, in
any
ele
men
t)ra
ises
(Inv
alid
Inde
x);
void
resi
ze(in
uns
igne
d lo
ng n
ew_s
ize)
;}; st
ruct
Ass
ocia
tion
{any
key
; any
val
ue; }
;
inte
rfac
e D
ictio
nary
: C
olle
ctio
n {
exce
ptio
nK
eyN
otF
ound
{any
key
; };
void
bind
(in a
ny k
ey, i
n an
y va
lue)
;vo
idun
bind
(in a
ny k
ey)
rais
es(K
eyN
otF
ound
);an
ylo
okup
(in a
ny k
ey)
rais
es(K
eyN
otF
ound
);bo
olea
nco
ntai
ns_k
ey(in
any
key
);};
Figure 12.1c Overview of the interface definitions for part of the ODMG
object model. Interface definitions for collection objects.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Object
Iterator Collection Date Time Interval
Set List Bag Array Dictionary
Timestamp
Figure 12.2 Inheritance hierarchy for thebuilt-in interfaces of the object model.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
class Employee( extent all_employees
key ssn ){
attribute string name;attribute string ssn;attribute date birthdate;attribute enum Gender{M, F} sex;attribute short age;relationship Department works_for
inverse Department::has_emps;void reassign_emp(in string new_dname)
raises(dname_not_valid);};
class Department( extent all_departments
key dname, dnumber ){
attribute string dname;attribute short dnumber;attribute struct Dept_Mgr {Employee manager, date startdate}
mgr;attribute set<string> locations;attribute struct Projs {string projname, time weekly_hours}
projs;relationship set<Employee> has_emps inverse Employee::works_for;void add_emp(in string new_ename) raises(ename_not_valid);void change_manager(in string new_mgr_name; in date startdate);
};
Figure 12.3 The attributes, relationships,and operations in a class definition.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
interface ObjectFactory {Object new();
};
interface DateFactory : ObjectFactory {exception InvalidDate{};...Date calendar_date( in unsigned short year,
in unsigned short month,in unsigned short day)
raises(InvalidDate);...Date current();
};
interface DatabaseFactory {Database new();
};
interface Database {void open(in string database_name);void close();void bind(in any some_object, in string object_name);Object unbind(in string name);Object lookup(in string object_name)
raises(ElementNotFound);...
};
Figure 12.4 Interfaces to illustrate factory objects and database objects.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Interface
Class
Relationships
Person-IF
Student
1.1
1:N
M:N
Inheritance Interface (is-a)inheritanceusing “:”
Classinheritanceusing extends
Figure 12.5 An example of a database schema. (a) Graphical notationfor representing ODL schemas.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Person Department
Section
Course
has_majors offers
majors_in
completed_sections
offered_by
has_sections
students
of_course
registered_students
registered_in
committee
advisoradvises
on_committee_of
Faculty
GradStudent
Student
CurrSection
has_faculty
works_in
Figure 12.5 An example of a database schema. (b) A graphical objectdatabase schema for part of the UNIVERSITY database.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
clas
s P
erso
n(
exte
nt
pers
ons
key
ssn
){
attr
ibu
test
ruct
Pna
me
{str
ing
fnam
e, s
trin
g m
nam
e, s
trin
g m
nam
e }
nam
e;at
trib
ute
stri
ng
ssn;
attr
ibu
ted
ate
birt
hdat
e;at
trib
ute
en
um
Gen
der{
M, F
}se
x;at
trib
ute
stru
ct A
ddre
ss {
sho
rt n
o, s
trin
g s
tree
t, sh
ort
apt
no,
stri
ng
city
, str
ing
sta
te, s
ho
rt z
ip }
addr
ess;
sho
rt a
ge()
;}; cl
ass
Fac
ulty
ext
end
s P
erso
n(
exte
nt
facu
lty
){
attr
ibu
test
rin
g
rank
;at
trib
ute
flo
atsa
lary
;at
trib
ute
stri
ng
offic
e;at
trib
ute
stri
ng
phon
e;re
lati
on
ship
Dep
artm
ent
wor
ks_i
n in
vers
e D
epar
tmen
t::ha
s_fa
culty
;re
lati
on
ship
set<
Gra
dStu
dent
> a
dvis
es in
vers
e G
radS
tude
nt::a
dvis
or;
rela
tio
nsh
ipse
t<G
radS
tude
nt>
on_
com
mitt
ee_o
fin
vers
e G
radS
tude
nt::c
omm
ittee
;vo
idgi
ve_r
aise
(in
flo
at r
aise
);vo
idpr
omot
e(in
str
ing
new
_ran
k);
}; clas
s G
rade
(ex
ten
tgr
ades
)
{at
trib
ute
en
um
Gra
deV
alue
s{A
,B,C
,D,F
,I,P
}gr
ade;
rela
tio
nsh
ipS
ectio
n se
ctio
n in
vers
e S
ectio
n::s
tude
nts;
rela
tio
nsh
ipS
tude
nt s
tude
nt in
vers
e S
tude
nt::c
ompl
eted
_sec
tions
;}; cl
ass
Stu
dent
ext
end
s P
erso
n(
exte
nt
stud
ents
)
{at
trib
ute
stri
ng
clas
s;at
trib
ute
Dep
artm
ent
min
ors_
in;
rela
tio
nsh
ipD
epar
tmen
t maj
ors_
in in
vers
e D
epar
tmen
t::ha
s_m
ajor
s;re
lati
on
ship
set<
Gra
de>
com
plet
ed_s
ectio
ns in
vers
e G
rade
::stu
dent
;re
lati
on
ship
set<
Cur
rSec
tion>
reg
iste
red_
inin
vers
e C
urrS
ectio
n::r
egis
tere
d_st
uden
ts;
void
chan
ge_m
ajor
(in
str
ing
dna
me)
rai
ses(
dnam
e_no
t_va
lid);
flo
atgp
a();
void
regi
ster
(in
sh
ort
sec
no)
rais
es(s
ectio
n_no
t_va
lid);
void
assi
gn_g
rade
(in
sh
ort
sec
no; i
n G
rad
eVal
ue
grad
e)ra
ises
(sec
tion_
not_
valid
,gra
de_n
ot_v
alid
);};
Figure 12.6 Possible ODL schema for theUNIVERSITY database of Figure 12.5(b).
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
clas
s D
egre
e{
attr
ibu
test
rin
g
colle
ge;
attr
ibu
test
rin
gde
gree
;at
trib
ute
stri
ng
year
;}; cl
ass
Gra
dStu
dent
ext
end
s S
tude
nt(
exte
nt
grad
_stu
dent
s )
{at
trib
ute
set<
Deg
ree>
degr
ees;
rela
tio
nsh
ipF
acul
ty a
dvis
or in
vers
e F
acul
ty::a
dvis
es;
rela
tio
nsh
ipse
t<F
acul
ty>
com
mitt
ee in
vers
e F
acul
ty::o
n_co
mm
ittee
_of;
void
assi
gn_a
dvis
or(i
n s
trin
g ln
ame;
in s
trin
g fn
ame)
rais
es(f
acul
ty_n
ot_v
alid
);vo
idas
sign
_com
mitt
ee_m
embe
r(in
str
ing
lnam
e; in
str
ing
fnam
e)ra
ises
(fac
ulty
_not
_val
id);
}; clas
s D
epar
tmen
t(
exte
nt
depa
rtm
ents
)
{at
trib
ute
stri
ng
dnam
e;at
trib
ute
stri
ng
dpho
ne;
attr
ibu
test
rin
gdo
ffice
;at
trib
ute
stri
ng
colle
ge;
attr
ibu
teF
acul
tych
air;
rela
tio
nsh
ipse
t<F
acul
ty>
has
_fac
ulty
inve
rse
Fac
ulty
::wor
ks_i
n;re
lati
on
ship
set<
Stu
dent
> h
as_m
ajor
s in
vers
e S
tude
nt::m
ajor
s_in
;re
lati
on
ship
set<
Cou
rse>
offe
rs in
vers
e C
ours
e::o
ffere
d_by
;}; cl
ass
Cou
rse
(ex
tent
cour
ses
){
attr
ibu
test
rin
gcn
ame;
attr
ibu
test
rin
gcn
o;at
trib
ute
stri
ng
desc
riptio
n;re
lati
on
ship
set<
Sec
tion>
has
_sec
tions
inve
rse
Sec
tion:
:of_
cour
se;
rela
tio
nsh
ipse
t<D
epar
tmen
t> o
ffere
d_by
inve
rse
Dep
artm
ent::
offe
rs;
}; clas
s S
ectio
n(
exte
ntse
ctio
ns
){
attr
ibu
tesh
ort
secn
o;at
trib
ute
stri
ng
year
;at
trib
ute
en
um
Qua
rter
{Fal
l, W
inte
r, S
prin
g, S
umm
er}
qtr;
rela
tio
nsh
ipse
t<G
rade
> s
tude
nts
inve
rse
Gra
de::s
ectio
n;re
lati
on
ship
Cou
rse
of_c
ours
e in
vers
e C
ours
e::h
as_s
ectio
ns;
}; clas
s C
urrS
ectio
n ex
ten
ds
Sec
tion
(ex
tent
curr
ent_
sect
ions
){
rela
tio
nsh
ip s
et<
Stu
dent
> r
egis
tere
d.st
uden
ts in
vers
e S
tude
nt::r
egis
tere
d_in
void
regi
ster
_stu
dent
(in
str
ing
ssn
)
rai
ses(
stud
ent_
not_
valid
, sec
tion_
not_
valid
, sec
tion_
full)
;};
Figure 12.6 Possible ODL schema for theUNIVERSITY database of Figure 12.5(b).
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
GeometryObject
Rectangle Triangle Circle ...
Figure 12.7a An illustration of interface inheritance via “:”.Graphical schema representation.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
inte
rfac
e G
eom
etry
Obj
ect
{at
trib
ute
enu
m S
hape
{Rec
tang
le,T
riang
le,C
ircle
,...}
sha
pe;
attr
ibu
test
ruct
Poi
nt {
sho
rt x
, sh
ort
y}
refe
renc
e_po
int;
flo
atpe
rimet
er()
;fl
oat
area
();
void
tran
slat
e(in
sh
ort
x_t
rans
latio
n; in
sh
ort
y_t
rans
latio
n);
void
rota
te(i
n f
loat
ang
le_o
f_ro
tatio
n);
}; clas
s R
ecta
ngle
: G
eom
etry
Obj
ect
(ex
ten
tre
ctan
gles
){
attr
ibu
test
ruct
Poi
nt {
sho
rt x
, sh
ort
y}
refe
renc
e_po
int;
attr
ibu
tesh
ort
leng
th;
attr
ibu
tesh
ort
heig
ht;
attr
ibu
te
flo
ator
ient
atio
n_an
gle;
}; clas
s T
riang
le :
Geo
met
ryO
bjec
t(
exte
nt
tria
ngle
s )
{at
trib
ute
stru
ct P
oint
{sh
ort
x, s
ho
rt y
}re
fere
nce_
poin
t;at
trib
ute
sho
rtsi
de_1
;at
trib
ute
sho
rtsi
de_2
;at
trib
ute
fl
oat
side
1_si
de2_
angl
e;at
trib
ute
fl
oat
side
1_or
ient
atio
n_an
gle;
}; clas
s C
ircle
: G
eom
etry
Obj
ect
(ex
ten
tci
rcle
s
){
attr
ibu
test
ruct
Poi
nt {
sho
rt x
, sh
ort
y}
refe
renc
e_po
int;
attr
ibu
tesh
ort
radi
us;
}; ...
Figure 12.7b An illustration of interface inheritance via “:”.Corresponding interface and class definitions in ODL.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
stru
ct E
nam
e {
d_S
trin
gfn
ame;
d_S
trin
gm
nam
e;d_
Str
ing
lnam
e;}; st
ruct
Add
ress
{d_
US
hort
no;
d_S
trin
gst
reet
;d_
US
hort
aptn
o;d_
Str
ing
city
;d_
Str
ing
stat
e;d_
US
hort
zip;
}; clas
s P
erso
n : p
ublic
d_O
bjec
t {pu
blic
://
Attr
ibut
esE
nam
een
ame;
d_S
trin
g ss
n;d_
Dat
ebi
rthd
ate;
enum
Gen
der
{M,F
}se
x;A
ddre
ssad
dres
s;//
Ope
ratio
nsP
erso
n(co
nst c
har
* pn
ame)
;d_
US
hort
age
;//
Ext
ent
stat
ic d
_Set
<d_
Ref
<P
erso
n>>
pers
ons;
stat
ic c
onst
cha
r *
cons
tex
tent
_nam
e;}; cl
ass
Fac
ulty
: pub
lic P
erso
n {
publ
ic:
// A
ttrib
utes
d_S
trin
gra
nk;
d_F
loat
sala
ry;
d_S
trin
gof
fice;
d_S
trin
gph
one;
// R
elat
ions
hips
(sy
ntax
is O
DM
G 1
.1 c
ompl
iant
)d_
Ref
<D
epar
tmen
t>w
orks
_in
inve
rse
Dep
artm
ent::
has_
facu
lty;
d_S
et<
d_R
ef<
Gra
dStu
dent
>>
ad
vise
sin
vers
e G
radS
tude
nt::a
dvis
or;
d_S
et<
d_R
ef<
Gra
dStu
dent
>>
on_
com
mitt
ee_o
fin
vers
e G
radS
tude
nt::c
omm
ittee
;//
Ope
ratio
nsF
acul
ty(c
onst
cha
r *
fnam
e, d
_Flo
at s
alar
y);
void
giv
e_ra
ise(
in d
_Flo
at r
aise
);vo
id p
rom
ote(
in d
_Str
ing
new
_ran
k);
// E
xten
tst
atic
d_S
et<
d_R
ef<
Fac
ulty
>>
facu
lty;
stat
ic c
onst
cha
r *
cons
tex
tent
_nam
e;};
Figure 12.8a Example illustrating O2. Defining part of theUNIVERSITY schema using the C++ O2 binding.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
// Faculty Class
const char * const Faculty::extent_name = "faculty";
// Faculty constructor hereFaculty::Faculty(const char * fname, d_Float fsalary) :
Person(fname) {
salary = fsalary;// Put this new faculty into the extensionfaculty->insert_element(this);
}
void Faculty::give_raise(d_Float raise);{
salary += raise;}
void Faculty::promote(d_String new_rank);{
rank = new_rank;}
Figure 12.8b Example illustrating O2. C++ O2schema implementation for the Faculty class.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
/* th
is is
the
file
univ
_sch
ema.
H th
at in
clud
es th
e da
taba
se c
lass
dec
lara
tions
*/
stru
ct P
hone
{in
t are
a_co
de ;
int n
umbe
r ;
} stru
ct D
ate
{in
t yea
r ;
int m
onth
;in
t day
;} cl
ass
Per
son
{pu
blic
:ch
ar s
sn[9
] ;st
ruct
{ch
ar*
first
nam
e ;
char
* m
iddl
enam
e ;
char
* la
stna
me
;}
nam
e ;
stru
ct {
int
n
umbe
rch
ar*
stre
et ;
char
* ap
t_no
;ch
ar*
city
;ch
ar*
stat
e ;
char
* zi
pcod
e ;
} ad
dres
s ;
Dat
e bi
rthd
ate
;ch
ar s
ex ;
int a
ge (
) ;
} stru
ct T
rans
crip
t {ch
arflo
at
Sec
tion
} clas
s S
tude
nt: p
ublic
Per
son
{
/* S
tude
nt in
herit
s (
is d
eriv
ed fr
om)
Per
son
*/ p
ublic
:ch
ar*
Dep
artm
ent
Dep
artm
ent
os_S
et<
Sec
tion*
>os
_Set
<T
rans
crip
t*>
float
gra
de_p
oint
_ave
rage
()
;vo
id c
hang
e_cl
ass
() ;
void
cha
nge_
maj
or (
Dep
artm
ent *
new
_maj
or)
;} st
ruct
Deg
ree
{ch
ar*
colle
ge ;
char
* de
gree
;in
t
yea
r ;
} clas
s G
rad_
stud
ent:
publ
ic S
tude
nt {
/* G
rad_
stud
ent i
nher
its (
is d
eriv
ed fr
om)
Stu
dent
*/p
ublic
:
os
_Set
<D
egre
e*>
deg
rees
;
F
acul
ty
*
advi
sor
;} cl
ass
Fac
ulty
: pub
lic P
erso
n {
/*
Fac
ulty
inhe
rits
(is
der
ived
from
) P
erso
n */
float
ch
ar*
char
*ch
ar*
os_S
et<
Dep
artm
ent*
>D
epar
tmen
tos
_Set
<G
rant
*>os
_Set
<S
tude
nt*>
void
pro
mot
e_fa
culty
()
;vo
id g
ive_
rais
e (f
loat
per
cent
) ;
}
Figure 12.9 ObjectStore C++ classdeclarations for part of the UNIVERSITY database.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Figure 12.9 (continued)
stru
ct D
egre
e {
char
* co
llege
;ch
ar*
degr
ee ;
int
y
ear
;} cl
ass
Gra
d_st
uden
t: pu
blic
Stu
dent
{
/*
Gra
d_st
uden
t inh
erits
(is
der
ived
from
) S
tude
nt *
/pub
lic :
os_S
et<
Deg
ree*
>
d
egre
es ;
Fac
ulty
*ad
viso
r ;
} clas
s F
acul
ty: p
ublic
Per
son
{
/* F
acul
ty in
herit
s (
is d
eriv
ed fr
om)
Per
son
*/flo
at
sala
ry;
char
*ra
nk;
char
*fo
ffice
;ch
ar*
fpho
ne;
os_S
et<
Dep
artm
ent*
>be
long
s_to
;D
epar
tmen
t*c
hairs
;os
_Set
<G
rant
*>gr
ants
;os
_Set
<S
tude
nt*>
advi
ses;
void
pro
mot
e_fa
culty
()
;vo
id g
ive_
rais
e (f
loat
per
cent
) ;
} clas
s D
epar
tmen
t {ch
ar*
dnam
e;ch
ar*
offic
e;P
hone
dpho
ne;
os_S
et<
Fac
ulty
*>m
embe
rs;
os_S
et<
Stu
dent
*>m
ajor
s;F
acul
tych
airp
erso
n;os
_Set
<C
ours
e*>
cour
ses;
void
add
_maj
or (
Stu
dent
*s)
;vo
id r
emov
e_m
ajor
(S
tude
nt *
s) ;
}
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
extern database *univ_db ;
class Person ;
class Faculty: public Person { /* Faculty inherits (is derived from) Person */float salary ;char* rank ;char* foffice ;char* fphone ;os_Set<Department*> belongs_to
inverse_member Department::members ;Department *chairs
inverse_member Department::chairperson ;os_Set<Grant*> grants ;os_Set<Student*> advises ;
Faculty (char s[9]) { ssn = new (univ_db) char[9] ; strcpy(ssn, s) ; }/* the ssn attribute is inherited from Person */
void promote_faculty () ;void give_raise (float percent) ;
}
class Department {char*char*Phoneos_Set<Faculty*> members
inverse_member Faculty::belongs_to ;os_Set<Student*> majors ;Faculty *chairperson
inverse_member Faculty::chairs ;os_Set<Course*> courses ;
Department (char* d) { dname = new (univ_db) char[strlen(d)+1] ; strcpy(dname, d) ; }void add_faculty (Faculty *f) ;void add_major (Student *s) ;int remove_major (Student *s) ;
}
dname ;office ;dphone ;
Figure 12.10 Declaring inverse relationships in ObjectStore C++.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
(a)int Person::age () {
Date d = today() ; int a = d.year - birthdate.year ;if ( d.month < birthdate.month ) ll ( d.month == birthdate.month ) && ( d.day < birthdate.day ) ) --a ;return a;
} ;
float Student::grade_point_average () {float sum = 0.0 ; int count = 0 ; Transcript* t ;foreach (t, transcript) {
sum += t->ngrade ; ++count ; /* increments sum by ngrade, count by 1 */}
return sum/count ;} ;
void Student::change_major (Department *new_major) {majors_in = new_major ; }void Department::remove_major (Student *s) {majors->remove(s) ; }void Department::add_faculty (Faculty *f) { members->insert (f) ; }void Department::add_major (Student* s) { majors->insert(s) ; }
(b)main () {
database *univ_db = database::open ("/database/univ" ) ;
transaction::begin () ;/* create two persistent sets to hold all Faculty and all Department objects *
os_Set<Faculty*> &all_faculty = os_Set<Faculty*>::create(univ_db) ;os_Set<Department*> &all_depts = os_Set<Department*>::create(univ_db) ;
/* create a new Faculty object and a new Department object using the constructors */Faculty *f = new (univ_db) Faculty ("123456789") ;Department *d = new (univ_db) Department ("Computer Science") ;
/* relate the objects by invoking the appropriate method */d->add_faculty (f) ;
/* add the objects to their persistent sets */all_faculty.insert(f) ; all_depts.insert(d) ;
transaction::commit () ;}
Figure 12.11 ObjectStore C++ programming.(a) Code for some of the member functions (operations)
in Figure 12.9. (b) Creating persistent objects.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
os_Set<Faculty*> &asst_profs =all_faculty [: rank == 'Assistant Professor' :]
os_Set<Faculty*> &rich_asst_profs =all_faculty [: rank == 'Assistant Professor' && salary > 5000.00 :]
os_Set<Faculty*> &dept_chairs =all_faculty [: chairs :]
os_Set<Faculty*> &cs_faculty =all_faculty [: belongs_to [: dname == 'Computer Science' :] :]
Figure 12.12 Queries in ObjectStore ++.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
IDLStubs DII
Control Control
ORBInterface
Object Request Broker
IDLSkeleton
DSI
*Really the Basic Object Adaptor
Object Adapter*
TargetObjectClient
Figure 12.13 The CORBA 2.0 ORB Architecture. Pearson Education Ltd. from CORBA Distributed Objects by Sean Baker © 1997 Addison Wesley Longman.
© Addison Wesley Longman, Inc. 2000, Elmasri/Navathe, Fundamentals of Database Systems, Third Edition
Application Objects
Application Object
CORBA Services CORBA Facilities
Object Request Broker
Figure 12.14 The CORBA Object Management Architecture (OMA).Pearson Education Ltd. from CORBA Distributed Objects by Sean Baker © 1997 Addison Wesley Longman.