Upload
sammy21791
View
220
Download
0
Embed Size (px)
Citation preview
8/4/2019 Dbase11
1/31
11-1
CHAPTER 11
Concepts for
Object-Oriented Databases
8/4/2019 Dbase11
2/31
11-2
Overview of
Object-Oriented Concepts Object-oriented databases give designer to specify
The structure of complex objects
The operations that can be applied to objects
Increase uses of OOPL
Object
State(Value)
Behavior(operations)
transient vs. persistent
8/4/2019 Dbase11
3/31
11-3
Overview of
Object-Oriented Concepts (Cont.) Maintain a direct correspondence between
real-world and database objects
A real-world object may have different names
for key attributes in different relations in
traditional database systemsE.G. EMP_ID, SSN in different relations
OODBs provide a unique system-
generated object identifier for each object
8/4/2019 Dbase11
4/31
11-4
Overview of
Object-Oriented Concepts (Cont.)
Objects may have an object structure of
arbitrary complexity
Information about a complex object is often
scatteredover many relations or records in
traditional database systems
1NF in relational databases
8/4/2019 Dbase11
5/31
11-5
Object Identity unique identity for each independent object
stored in the database
created by a unique, system-generated
object identifier, or OID
8/4/2019 Dbase11
6/31
11-6
Object Identity (Cont.)
properties of OID
immutable: the OID value of a particular objectshould not change
Each OID is used only once.
OID should not depend on any physical addressattribute values of the object
Most OO database systems allow for the representation ofboth objects and values (having no OIDs)
8/4/2019 Dbase11
7/31
11-7
Object Structure
(i, c, v)
i: a unique object identifier(OID)
c: a type constructor
basic type: atom
structured type: tuple collection type: array vs. list, set vs. bag
System supports
(integer,real,string,Boolean,)
number of
elementsdistinct vs.
duplicate
order unorder
8/4/2019 Dbase11
8/31
11-8
v: object state
c=atom ::: an atomic value from the domain
c=set ::: a set of object identifiers {i1, i2, , in}
c=tuple ::: a tuple of
c=list ::: an ordered list [i1, i2, , in]
c=array ::: a single-dimensional array of object
identifiers
c=bag
Object Structure (Cont.)
iijj : OID: OID
aajj : attribute name: attribute name
8/4/2019 Dbase11
9/31
11-9
Example 1: Complex Object
EMPLOYEE FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO
John B mith 123456789 09-J N-55 731 Fondren, ouston, TX 30000 333445555 5
Franklin T Wong 333445555 08- EC-45 638 Voss, ouston, TX 40000 888665555 5
licia J Zelaya 999887777 19-JU -58 3321 Castle, pring, TX F 25000 987654321 4
Jenni er Wallace 987654321 20-JUN-31 291 Berry, Bellaire, TX F 43000 888665555 4
amesh K Narayan 666884444 15- E -52 975 Fire Oak, umble, TX 38000 333445555 5
Joyce English 453453453 31-JU -62 5631 ice, ouston, TX F 25000 333445555 5
hmad V Jabbar 987987987 29- -59 980 allas, oustom TX 25000 987654321 4
James E Borg 888665555 10-NOV-27 450 tone, ouston, T 55000 null 1
8/4/2019 Dbase11
10/31
11-10
Example 1: Complex Object (Cont.)
o1=(i1,atom,Houston)
o2=(i2,atom, ellaire)
o3=(i3,atom,Sugarland) o4=(i4,atom,5)
o5=(i5,atom,Research)
o6=(i
6,atom,1988-05-22)
o7=(i5,set,{i1, i2, i3}) ::: the set of locations for
department 5
8/4/2019 Dbase11
11/31
11-11
o8=(i8, tuple, ) ::: department 5
o9=(i9, tuple, )
o10=(i10,set,{i12, i13, i14})
o11
=(i11
,set,{i15
, i16
, i17
})
o12=(i12, tuple, < AME:i18, MI IT: i19, L AME:i20, SS : i21, , SALARY: i26, S PER ISOR: i27,DEPT: i28>)
Example 1: Complex Object (Cont.)
employee John B. Smith
8/4/2019 Dbase11
12/31
11-12
Graphical representation of a complex object
LEGE D: object
tuple
set
D AME D M ER MGR LOCATIO S EMPLOYEES PROJECTS
MA AGER MA AGERSTRATDATE
O5 O4 O9 O7O
10O
11
O8
O1 O2 O3
Houston ellaire Sugarland
i8:
tuple
i5:
atom
i4:
atom i9:
tuplei7:
seti10:
seti11:
set
i15: .....
tuple
i16: .....
tuple
i17: .....
tuple
i12: .....
tuple
i13: .....
tuple
i14: .....
tuple
i6:
atom
O6
1988-05-22
4
9
5
7
10
11
1 2 3
6
Research 5
Object instance ofObject instance of
department typedepartment type
8/4/2019 Dbase11
13/31
11-13
Comparisons of the states of
two objects for equality identical states (deep equality)
the graphs representing their states are identical in
every respect, including the OIDs at every level equal states (shallow equality)
the graph structures must be the same
all the corresponding atomic values in the graphs
should be the same allow some corresponding internal nodes in the two
graphs to have objects with differentOIDs
(Current Values)(Current Values)
8/4/2019 Dbase11
14/31
11-14
Example 2:
Identical vs. Equal Object States o1=(i1, tuple, )
o2=(i2, tuple, )
o3=(i3, tuple, )
o4=(i4, atom, 10)o5=(i5, atom, 10)
o6=(i6, atom, 20)
o1
and o2
have equal states
o1 and o3 have identical states
o4 and o5 have identical states
o4 and o5 are equal but not identical
8/4/2019 Dbase11
15/31
11-15
sing OODDL to define Employee, Date, and
Department types
define typetuple (
Employee:fname:minit:lname:
ssn:birthdate:addresssex:salary:supervisor:
dept:
string;char;string;
string;Date;string;char;float;Employee;
Department);
Attributes refer to Employee,Attributes refer to Employee,
Department objectsDepartment objects
relationship among objectsrelationship among objects
8/4/2019 Dbase11
16/31
11-16
define typetuple (
define typetuple (
Date:year:month:
day:
Departmentdname:dnumber:
mgr:
locations:employees:
projects:
integer;integer;integer; );
string;integer;
tuple (manager:startdate:
set (string);set (Employee);set (Project); );
Employee;Date; );
sing OODDL to define Employee, Date, and
Department types (Cont.)
Inverse reference:Inverse reference:
dept. of employeedept. of employee
employee of dept.employee of dept.
set of referencesset of references
8/4/2019 Dbase11
17/31
11-17
Specifying Object ehavior
via Class Operations
Define theb
ehavior of a type of object basedon the operations that can be externallyapplied to object of that type
create (insert) or destroy (delete) objects
update the object state retrieve parts of the object state
apply some calculations
combination of retrieval, calculation, and update
In relational model, selecting, inserting, deletingIn relational model, selecting, inserting, deletingand modifying tuples areand modifying tuples are genericgeneric..
8/4/2019 Dbase11
18/31
11-18
Specifying Object ehavior
via Class Operations (Continued)
interface
define the name and arguments (parameters) of each
operation
signature (included in the class definition)
implementation method (defined using programming languages)
it is invoked by sending a message to the object to
execute the corresponding method
Operations 1. object constructorsOperations 1. object constructors2. object destructor2. object destructor3. object modifier3. object modifier4. retrieval4. retrieval
8/4/2019 Dbase11
19/31
11-19
sing OODDL to define Employee and
Department classes
operations age
create_emp:
destroy_emp :
end Employee;
integer;
Employee;
boolean;
define classtype tuple (
Employee:fname:minit:lname:ssn:
birthdate:addresssex:salary:supervisor:dept:
string;char;string;string;
Date;string;char;float;Employee;Department);
typedefinition
definition
of
operations
8/4/2019 Dbase11
20/31
11-20
sing OODDL to define Employee and
Department classes (Continued)
define class
type tuple (
Department
dname:dnumber:mgr:
locations:employees:projects:
string;integer;tuple (manager:
startdate:
set (string);set (Employee);set (Project); );
Employee;Date; );
operations
number_of_emps : integer;
create_dept: Department,destroy_dept: boolean;
assign_emp (e: Employee): boolean;
(* adds a new employee to the department *)
remove_emp (e: Employee): boolean;
(* removes an employee from the department *)
end Department;
type
definition
definition
of
operations
8/4/2019 Dbase11
21/31
11-21
Class Operations
object constructor create a new object
destructor
destroy an object object modifier
modify various attribute of an object
dot notation d.no_of_emps where d is a reference to a
department object and no_of_emps is an operation
refer to attributes of an object: d.dnumber, d.mgr.startdate
8/4/2019 Dbase11
22/31
11-22
Specifying Object Persistence via
aming and Reachability transient object
exist in the executing program and disappear once
the program terminates persistent object
stored in the database and persist after program
termination
naming mechanism
give an object a unique persistent name through
which it can be retrieved by this and other program
8/4/2019 Dbase11
23/31
11-23
Reachability
reachability mechanism
make the object reachable from some persistent object
an object is said to be reachable from an object A if asequence of references in the object graph lead from
object A to object e.g., if o8 is persistent, then all other objects also
become persistent (next slide)
defines a persistent collection of objects of class C
create a named persistent object , whose state is aset or list of objects of some class C
add objects of C to the set or list and make themreachable from
8/4/2019 Dbase11
24/31
11-24
Graphical representation of a complex object
LEGE D: object
tuple
set
D AME D M ER MGR LOCATIO S EMPLOYEES PROJECTS
MA AGER MA AGERSTRATDATE
O5
O4
O9
O7
O10 O11
O8
O1 O2 O3
Houston ellaire Sugarland
i8:
tuple
i5:
atom
i4:
atom i9:tuplei7:
seti10:
seti11:
set
i15: .....
tuple
i16: .....
tuple
i17: .....
tuple
i12: .....
tuple
i13: .....
tuple
i14: .....
tuple
i6:
atom
O6
1988-05-22
4
9
5
7
10
11
1 2 3
6
Research 5
Object instance ofObject instance of
department typedepartment type
8/4/2019 Dbase11
25/31
11-25
Creating persistent objects by naming and reachability
define class DepartmentSet:
type set (Department);
operations
add_dept(d: Department): boolean;
remove_dept (d: Department): boolean,
create_dept_set: DepartmentSet;
destroy_dept_set: boolean;end DepartmentSet;
persistent name AllDepartments: DepartmentSet ;
(* AllDepartments is a persistent named object of type set DepartmentSet*)
.....d := create_dept ;
..... (* creates a new department object in the variable d *)
b := AllDepartments.add_dept (d) ;
(* make d persistent by adding it to the persistent named object AllDepartments *)
AllDepartments object: extent of the class Department
8/4/2019 Dbase11
26/31
11-26
differences between traditional
databases and OO databases traditional database models
when an entity type or class is defined in EER,
it represents both type declaration andpersistent set
OO approaches
a class declaration specifies only the type andoperations for a class of objects
user must define a persistent object whose
value is the collection of references to all
persistent
8/4/2019 Dbase11
27/31
11-27
Type Hierarchies and Inheritance
type (or class) hierarchy define new types based on other predefined types (or
classes)
type
type name a number of attributes (instance variables)
operations (methods)
TYPE_ AME: function, function, , function
PERSO : ame, Address, irthdate, Age, SSEMPLOYEE subtype-of PERSO : Salary,
HireDate, SeniorityST DE T subtype-of PERSO : Major, GPA
functions with zero arguments
functions
8/4/2019 Dbase11
28/31
11-28
Type Hierarchies and Inheritance
GEOMETRY_O JECT: Shape, Area, ReferencePoint
RECTA GLE subtype-ofGEOMETRY_O JECT: Width, Height
TRIA GLE subtype-of
GEOMETRY_O JECT: Side1, Side2, Side3
CIRCLE subtype-of GEOMETRY_O JECT:
Radius
attributes(triangle,rectangle,circle)
method attribute
8/4/2019 Dbase11
29/31
11-29
Type Hierarchies and Inheritance
(Cont.)
RECTA GLERECTA GLE subtype-of
GEOMETRY_O JECT (Shape=rectangle): Width, Height
TRIA GLETRIA GLE subtype-of
GEOMETRY_O JECT (Shape=triangle): Side1, Side2, Side3
CIRCLECIRCLE subtype-of
GEOMETRY_O JECT (Shape=circle): Radius
8/4/2019 Dbase11
30/31
11-30
Inheritance multiple inheritance
when T is a subtype of two (or more) types, T inheritsthe functions (attributes and methods) of both
supertypes
type lattice instead of type hierarchy
if a function is inherited from some common supertype,it is inherited only once
ambiguity resolution alarm users
system default
disallow multiple inheritance
8/4/2019 Dbase11
31/31
11-31
Inheritance (Continued) Selective Inheritance
a subtype inherits only some of the functions of
a supertype
an E CEPT clause may be used to list the
functions in a super type that are notto be
inherited by the subtype