Académique Documents
Professionnel Documents
Culture Documents
Chapter 4: Overview
4.1 Type constructors, complex objects
4.2 Classes: Type- and Set-View
4.3 Relations between Classes, Aggregation
4.4 Object Identity
4.5 Inheritance
4.6 Query Operations
4.7 OQL Object Query Language of ODMG
4.8 Methods
4.9 Integrity
2
Database perspective
Persistance
Disk-storage organisation
Concurrent transactions
Recovery mechanisms
Query languages
Database operations
optional:
Multiple inheritance
optional:
Distributed databases
Version administration
3
Sequence is of interest
5
Dictionary constructor
DICTIONARY OF (key, value)
0
1
2
may contain gaps
index of type long integer Atlanta Paris
unordered sequence of
(key, value)-pairs
lookup operation
returns value to a given key
London
Key Value
A
excellent
very good
good
satisfactory
sufficient
fail
Tuple
Person
Name
Tuple
PhoneNumbers
date
Set Addresses
DOB
string
string
string
First
Second Last
Name Name Name
string
string
Title
Saluta
tion
string
string
Street City
Tuple Address
List
Tuple
Phone
Number
string
string
string
string
State
ZIP
Type
Phone Type
Nr
string
ODMG Standard
Collections supported by
the ODMG-Model
Set <t>
Bag <t>
List <t>
Array <t>
Dictionary <t, v>
where t and v are any types
Atomic types
type generator
can only take values listed in
declaration
Structured literals
date
time, timestamp
interval
user defined with struct
10
11
Country;
City;
Street;
ZIP;
State;
Type;}
PhoneNr;
Type;}
12
complex properties
Tuple Constructor
No dictionary
constructor
13
C A C
A C H
C H
C A C
A C H
C H
15
C A C
A C H
C H
16
C A C
A C H
C H
Tuple
Saving Account
Transactions
string
Type
string
date
Account Begin
Number
date
End
float
Arr. Interest
Current
Amount
Index: int
redundant
information
List
Year
Tuple
Transaction
string
date
Sender Date
float
string
Amount Purpose
19
Tuple constructor
Access to components
Test two tuples on equality
20
Set constructor
Bag constructor
Set comparisons: =,
Set operations: intersection, union, difference
Number of occurencies of an element
Set operations: intersection, union, difference
No set comparisons
List construktor
Array constructor
Dictionary constructor
22
C A C
A C H
C H
23
Purpose
C A C
A C H
C H
Success Failure
List: Insert(value)
Add value to
collection
InsertAt(value, index)
Array: SetAt(value,key)
error
status
List: InsertList(list)
Appends list
error
status
Find(element)
Tests whether
index or ""
element is in list key
GetAt(key)
""
24
Purpose
C A C
A C H
C H
Success Failure
RemoveAt(key)
Remove object
key
value at ""
key
Count()
Count items
integer
Clear()
Empty collection 1
error
status
25
26
Line x
Point begin;
Point end;
int width;
(3;15);
(5;17);
6;
type of
Line a2
Line yxa
(3;15);
(1;1);
6;
(3;0);
(5;17);
2;
Line x
Line gt
(3;15);
(5;17);
6;
"p1";
"p2";
"thin";
Line a2
4
1
r
x 5 k 2
6
3
A class is a container
Types of the elements are not fixed
28
AND class is
container for
objects (extent)
Set-type-based
Line x
class Line
Point begin;
Point end;
int width;
class defines
a complex
type
(3;15);
(5;17);
6;
Line a2
Line yxa
(3;15);
(1;1);
6;
(3;0);
(5;17);
2;
This is the solution in OODBMSs
29
30
Dependent/Independent
Component Objects
32
Encapsulated/Standalone
Component Objects
Different Types of
Component-Classes
priv
enc
aut
dep
ind
dir
Buildings Rooms
Countries Towns
ATMs Currency Orders
Lectures Students
Books Publishers
Books Pages
Folders Files
Parents Children
35
37
Possibility c) later
38
Relationships in Cach
Independent (One-to-many).
Dependent (Parent-to-children).
C A C
A C H
C H
C A C
A C H
C H
Relationship statement:
specialized Property statement.
One, many, parent, and children define cardinality of
each side of relationship.
40
Example:
Branch and ATM Class Model
FCE.Branch
Phone
Opens
Closes
ATMs
FCE.ATM
0..* Branch
CurrencyBalances
0..1
1
0..1
FCE.RealEstate
1
Street
City
State
Zip
C A C
A C H
C H
C A C
A C H
C H
42
C A C
A C H
C H
43
C A C
A C H
C H
44
Referential Integrity
Parent-to-Children:
C A C
A C H
C H
Demonstration:
Create a Relationship
C A C
A C H
C H
Specify name.
46
Cach:
Simulate One-to-One Relationship
C A C
A C H
C H
47
Using Relationships
C A C
A C H
C H
48
C A C
A C H
C H
C A C
A C H
C H
50
Storing Relationships
C A C
A C H
C H
51
Implicit Joins
table.foreignkey->column
Joins:
C A C
A C H
C H
C A C
A C H
C H
May be chained.
select Branch->Address->Street
childtable.parentforeignkey->columninparenttable
parenttable.childtable->columninchildtable
53
C A C
A C H
C H
54
Employee
advises
0..*
relation with
attribute
0..*
Customer
advisers
subject area
55
advises
Employee
1
connectio
n class
subject
area
attribu
te
0..*
Customer
advisers
56
Relationship parent-to-children
Relationship one-to-many
C A C
A C H
C H
Connection class
58
59
60
Example:
Branch "City Hall"
are not printable
must be created and
defined
carry no information
itself
are described by the
values of their attributes
Values
Example :
number 182
printable
already exist
carry information
themselves
describe objects
61
simple implementation
efficient access of components
address is not a value of the object
Disadvantages
Disadvantages
63
Disadvantages
64
Example:
Saving Accounts with Identifier-Attributes
SET OF (TUPLE OF
(Account_Nr: IDENTIFIER,
Type: STRING,
Begin: Date,
End: Date
Account_Holder: IDENTIFIER,
Account Transactions
_Holder
54355
1; 456 $; 1.7.02;
2; -63 $; 5.7.02;
3;
134584 incr. 1.
inter AUG
est
2005
31. 37704
JUL
2009
1; 456 $; 1.8.05;
2; 11 $; 31.12.05;
3;
66
not structured,
countably infinite,
abstract set
with the only information that
the elements are different
physical addresses
Names
Identifier-attributes
Operations on objects
object
19
19
State of object 19
Hugo Ross
1 May 89
2
State of object 2
5 Garden Ave
San Francisco, CA
88250
68
Abstract Objects
Advantages
Disadvantage
Two versions
Type Beg.
End
Acc.
Transactions
Holder
1; 2 ; 3 ;
134584 incr.
inter
est
4 ; 5 ; 6 ;
1.
31.
AUG JUL
2005 2009
Operations on Objects
71
Comparison of Objects
Philosophical question:
When are two objects identical?
Different comparisons
72
1 == MyPrimaryAccount?
1 == 3?
73
C A C
A C H
C H
An oref is a temporary
identifier for an object in
memory.
Remove object from memory
oref is no longer valid
cannot be printed
and object ID
An object ID is a permanent
identifier for a stored object
is automatically created by
%Save()-method
never changes
can be used to locate or
delete an object in the DB
can be printed
C A C
A C H
C H
77
C A C
A C H
C H
78
4.5 Inheritance
Inheritance (cont.)
80
Specialization
Generalization
vertebrates
mammals
invertebrates
birds
82
Class Graph
Person
A subclass inherits
from more than one
superclass
(multiple inheritance)
class graph
Not allowed in all
object oriented
systems
Supported by Cach
Addresses
Name: String
DOB: Date
Phone: String
Email: String
Employee
Salary: Float
ESince: Date
Qualification: String
Customer
Type: String
CSince: Date
Rating: String
EmpCust
InterestBonus:
Float
83
Inheritance in ER-Diagrams
Example: ER-Diagram of a personal address-book
Name
Address
Phone
Person
Colleague
RoomNr
WorkPhone
Friend
DOB
Hobbies
84
Problems
85
Inheritance in Cach
C A C
A C H
C H
C A C
A C H
C H
87
C A C
A C H
C H
88
Abstract Classes
C A C
A C H
C H
Suitable for
89
Is FCE.Person abstract?
90
Abstract Methods
C A C
A C H
C H
Similar to Private.
91
Vehicle
Car
Truck
Journey
Person
Customer
Employee
Sale
92
Generic Operations:
Operation
Projection
Selection
Join
Union
Intersection
Difference
Grouping
95
UBX
123-5
102
Euro 3075
USD 4788
16
UBX
123-7
370
Pound 2350
USD 5340
17
Abam 112675
20
Rupees 3900
USD 3340
18
Euro 5150
USD 2500
96
123-5
102
Euro 3075
USD 4788
16
123-7
370
Pound 2350
USD 5340
Abam 17
112675
20
Rupees 3900
USD 3340
T.C.C. 18
45-44-6 876
UBX
Euro 5150
USD 2500
97
Object Navigation
C A C
A C H
C H
98
b)
c)
Example:
Projection of ATMs to Brand and SerialNr
b)
a)
Brand SerialNr
15
UBX
123-5
UBX
123-5
16
UBX
123-7
UBX
123-7
17
Abam 112675
18
T.C.C. 45-44-6
Abam 112675
T.C.C. 45-44-6
c)
UBX
123-5
16
UBX
123-7
17
Abam 112675
18
T.C.C. 45-44-6
10
UBX
123-5
102
Euro 3075
15? 3
UBX
123-5
102
USD 4788
16
UBX
123-7
370
Pound 2350
16? 4
UBX
123-7
370
USD 5340
17
Abam 112675
20
Rupees 3900
17? 3
Abam 112675
20
USD 3340
18
Euro 5150
18? 4
USD 2500
10
Queries in Cach
C A C
A C H
C H
Advantages:
C A C
A C H
C H
C A C
A C H
C H
C A C
A C H
C H
10
currency is a parameter
Use Implicit join operator
(for more information refer to slide Implicit Joins)
You have to use the SQL-Name of the property
CurrencyBalances: ATM_CurrencyBalances
The currencies' names are stored in the column
element_key of ATM_CurrencyBalances
10
C A C
A C H
C H
Overview of OQL
11
OQL:
Traversing Attributes and Relationships
11
b
LIST (b,c,d)
a
d
LISTTOSET(LIST(1,2,3,2)) {1,2,3}
11
11
Example:
SELECT a.Address.Street
FROM a IN (SELECT a
FROM Branch b, a IN b.ATMs
WHERE b.Opens < '08:00:00'
WHERE a.Brand = 'T.C.C'
11
11
OQL Quantification
Practice:
Define OQL Queries
Practice Solution:
Define OQL Queries
12
Practice Solution:
Define OQL Queries
12
Practice Solution:
Define OQL Queries
4.8 Methods
12
C A C
A C H
C H
Operation in Cach
Insert
Constructor
%New() classmethod
%Save() instancem.
Update
Access to attribute
set obj.property =
NewVal
Delete
Persistent destructor
%DeleteId(Id)
classmethod
Insert Copy
Copy
%ConstructClone(d)
d: deep or shallow
copy
12
Practice:
Client or Server Side Method
Methods in Cach
C A C
A C H
C H
Inherited Methods
C A C
A C H
C H
13
C A C
A C H
C H
Method Signature
arguments
method name
argument name
default value
body
return type:
result of calculation or
object or
status
13
Method Arguments
C A C
A C H
C H
ObjectScript Arguments
Pass by value.
C A C
A C H
C H
Pass by reference.
13
C A C
A C H
C H
For example:
By value: do oref.Method(a,b)
By reference: do oref.Method(.a,.b)
13
Objects as Arguments
C A C
A C H
C H
13
Method Overloading
C A C
A C H
C H
13
Private Methods
C A C
A C H
C H
13
C A C
A C H
C H
Examples:
set branch = ##class(FCE.Branch).%New()
set status = branch.%Save() // save THIS branch
13
C A C
A C H
C H
Examples:
..Property
..Method()
..#ClassParameter
ObjectScript only.
13
C A C
A C H
C H
Accessor Methods
write oref.PropertyGet()
do oref.PropertySet(value)
14
C A C
A C H
C H
14
C A C
A C H
C H
C A C
A C H
C H
14
C A C
A C H
C H
14
%sqlcontext Object
C A C
A C H
C H
14
C A C
A C H
C H
14
Instance Methods
Instance query-methods
C A C
A C H
C H
Instance update-methods
Computed Properties
C A C
A C H
C H
Always-computed.
Triggered-computed.
SqlComputeCode Examples
C A C
A C H
C H
15
SqlComputeCode Attribute
C A C
A C H
C H
{ColumnName} is:
15
How To:
Create a Computed Property
C A C
A C H
C H
Specify SqlComputeCode.
15
4.9 Integrity
NOT-NULL-Constraint
UNIQUE-Constraint:
Integrity (cont.)
CHECK-Constraint
DEFAULT-Constraint
C A C
A C H
C H
C A C
A C H
C H
Cach
SQL
class X
ClassMethod %DeleteId()
ClassMethod %OnDelete()
Trigger XBeforeDelete
do ##class(Y).%DeleteId(5)
C A C
A C H
C H
15
Saving Object
C A C
A C H
C H
%Save() calls:
Method %OnAddToSaveSet(depth,insert).
Method %OnValidateObject().
15
C A C
A C H
C H
%Save() calls:
Method %OnBeforeSave(insert).
Method %OnAfterSave(insert).
Method %OnRollBack().
C A C
A C H
C H
%DeleteId() calls:
ClassMethod %OnDelete().
16
C A C
A C H
C H
Comment
%New()
%OnNew()
%OpenId()
%OnDetermineClass()
%OnOpen()
Class method
Instance method
%ConstructClone()
%OnConstructClone
(object, deep)
object is OREF of
cloned object
deep is deep argument
of %ConstructClone()
16
16
Practice Solution:
Write Callback Method
Practice Solution:
Write Callback Method
C A C
A C H
C H
SQL Triggers
C A C
A C H
C H
16
C A C
A C H
C H
Row-Based Triggers
C A C
A C H
C H
16
Writing a Trigger
C A C
A C H
C H
16
Preventing Event
C A C
A C H
C H
16
17
PracticeSolution:
Write Trigger
C A C
A C H
C H
17