Jan 15, 2016
2
Topics Introduction to Ode.
What is Ode? O++ Database Facilities
Using Ode to implement a home security system. Requirement spec of a home
security system Data design and implementation Behavior implementation example
3
What is Ode? An active, Object Database System and
Environment based on object paradigm. Developed by Database System Research
Department of AT&T Bell Lab (in 1989?). Use a programming language called O+
+. upward-compatible extension of C++. offers a simple, elegant notion of persistence. Be able to query and modify the database. provide sophisticated trigger facilities (trigger is
the basic ingredient of active database.)
4
What is Ode? (cont.) Version 4.2 currently run on SunOs 4.1.x,
Solaris 2.3, Windows NT, Windows 95. Product family
Ode<EOS> (aka Ode): disk-based version of Ode, using EOS storage manager. It is free to download.
MM-Ode<Dali> (aka MM-Ode): main-memory based version of Ode, using the Dali main-memory storage manager, useful for time-critical applications.
OdeFS: file system interface to Ode object database, allow objects to be treated and manipulated like files.
Ode/Oql: an interpreter that execute select statement that query objects in Ode.
5
O++ language
6
O++ vs. C++ Has 35 new keywords. Database creation and manipulation. Capability to create objects persist beyond
the lifetime of the program creating them. Provide iterator to manipulate set of objects
similar to SQL Transaction support Capability to create & access multiple
versions of an object. Capability to attach to object the condition &
action that are triggered when condition is T.
7
Class database Open, close, remove. Examplevoid main() {
database * db;if ((db = database::open(“security”)) == NULL) {
cout << “Cannot create database security” << endl;exit(1);
}int i = db->close();cout << “close(): “ << i;
}
registerAction(..)int transCount = 0;void incrementCount () { transCount++;}
database::registerAction(database::AFTER_COMMIT,incrementCount);
8
Persistent Objects Volatile object vs. persistent object. Example:
persistent class Person { public:
indexable char Name[50]; int Age; Person(char * n, int a); …… } persistent Person * p; p = pnew Person(“John Doe”, 35); pdelete p;
9
Clusters of Persistent Objects
Cluster is a physical grouping of persistent objects
By default, all persistent objects of the same type are grouped together in a cluster; the name of a cluster is the same as that of the corresponding type
Objects of class type can be accessed using the iterator.
10
Query All objectsfor (pe in Person)
cout << pe->Name << pe->Age;
Restrict the query by suchthatfor (pe in Person) suchthat (pe->Age > 20)
cout << pe->Name << pe->Age;
All object and its derived objects class Employee : public Person {…};
for (pe in all Person)
11
Indexing a cluster
You can build an index on a data member (declare with indexable) of a persistent class typedatabase::BuildIndex(“Person”, “Person::Name”,DB, 1, HASH_TYPE)
Index type can be Hash table or B-tree
12
Transaction in O++ All code interacting with DB (except open
and close) or manipulate persistent obj must be within transaction block.
Update transactiontrans {…}
Read-only transactionreadonly trans {…}
Hypothetical transactionhypothetical trans {…}
Transaction abort inside trans block: tabort;
13
Versions
Updating an object does not create a new version. New versions must be created explicitly by invoking the function newvers
Temporal relationship vs. Derived-from relationship
Examplepersistent Part *p, *vp1, *vp2, *vp3, *vtemp;
p = pnew Part;
vp1 = newvers(p);
vtemp = vdprev(vp1); vp2 = newvers(vtemp);
vtemp = vtprev(vp2); vp3 = newvers(vtemp);
p v0
p v1 v0
p v2
v0 v1
p v3 v1 v0
v2
15
Triggers - Examplepersistent class Person;
void Alert (persistent Person *, const char *, . . .);
persistent class Stock { char name[40]; float price; public: void NewPrice(float price); . . . event after NewPrice; . . . trigger AboveLimit(persistent Person * p, float limit) : after NewPrice & (price > limit) ==> Alert(p, “%s currently trading at %.2f”, name, price);
16
Triggers Declare events: all the basic events used in
a trigger must be declared in the class containing the trigger.
Declare trigger: trigger trigger_name (parameter) : trigger-body Trigger-body: Event ==> Action
Activate trigger ps->AboveLimit(Joe, 500.0); Fire a trigger: action is an independent
transaction. If triggering trans aborted, then trigger action is aborted.
17
A Case Study
A Home Security System
18
Requirement Specification Center controller monitors detectors,
alarms, and notifies emergency personnel according to a protocol specified in a schedule.
When a detector is tripped, controller records that event, sound the alarms. The resident has a certain amount of time to abort the protocol. If not, notify emergency personnel.
19
Requirement Spec (cont.) Control panel is an interface that
allows user to initialize system, reset alarms, setup, change, delete schedule.
Schedule has start, stop time and a choice of mode (Immediate, Short Delay, Long Delay)
Mode Start Hour
Start Minute
Stop Hour
Stop Minute
Long Delay Time Short Delay Time
ScheduleID Active Schedule ID Schedule
Detection Event
Control Panel
Detector Center Controller Emergency Notifier
Alarm
Detector State Center Controller State
Detector ID Timestamp
Detector ID
Alarm State Alarm ID
Phone Number
1 1 1
1
1 1
1
1
1:* 1:* 1:* 1:*
1:*
1:*
1:*
1
1:*
1
1
1
1 1
1:* 1:*
1 1
1
1
1
1
1
1
1
1:*
1
0:*
0:*
1
0:* 1
1
1
1
0:1
0:1
1
1
1
1
1
0:1
ORM of Home Security System. Modified from “Object Database Development” Figure 17.9
21
OBM of Active Objects Control Panel Center Controller Detector Alarm Emergency Notifier
22
OBM of Control Panel Object
@reset reset
@change a schedule change schedule
@ add schedule add schedule
@ activate schedule activate schedule
@ delete schedule delete schedule
@init
Ready
init reset
change a schedule (Schedule ID)
add schedule (Schedule ID)
activate schedule (Schedule ID)
delete schedule (Schedule ID)
init TO: Center Controller
reset TO: Center Controller
Control Panel 1
23
OBM of Center Controller Obj
@detection (Detector ID) ^ State = Ready if exist (Active Schedule ID) then if current time is between schedule’s time activate alarms; record new detection event; delay := TRUE; while (delay) do if <delay end> then emergency notify; State := Active; delay := FALSE; else if <user abort> reset detectors; reset alarms; State := Ready; delay := FALSE; end; end; else //not in current schedule’s time reset detector; State := Ready; end; end;
State: (Ready, Active)
@reset ^ State = Active reset detectors reset alarms State := Ready
@init init detectors int alarms State := Ready
Exists
1 1
Center Controller 1
24
OBM of Detector
Exists
@init init State := Ready
@reset ^ State = Active State := Ready
@trip detector (Detector ID) ^ State = Ready detection(Detector ID) State := Active
@ delete detector(Detector ID)
@add detector (Detector ID) State := Ready
State: (Ready, Active) 1 1:*
Detector
25
OBM of Alarm
Exists
@init init State := Ready
@reset ^ State = Active State := Ready
@activate alarm(Alarm ID) ^ State = Ready activate(Alarm ID) State := Active
@ delete Alarm(Alarm ID)
@add alarm (Alarm ID) State := Ready
State: (Ready, Active) 1 1:*
Alarm
26
OBM of Emergency Notifyer
Ready
@set number set phone number
@notify notify emergency unit
Emergency Notifier 1
notify
set number (Number)
27
Database Schemes Emergency Notifier(Emergency Phone
Number) Detection Event(Detector ID, Timestamp) Center Controller(State, (Detection
Event)*) Schedule(Schedule ID, Start Hour, Start
Minute, Stop Hour, Stop Minute, Mode, Short Delay Time, Long Delay Time)
28
Database Schemes (cont) Control Panel(Active Schedule
ID, (Schedule)*) Detector(Detector ID, State) Alarm(AlarmID, State)
29
Ode Schemes: EmergencyNofitier
persistent class EmergencyNotifier { private:
char phoneNumber[MAX];public: void changeNumber(char N[MAX]); void notify(); …
}
30
Ode Schemes: DetectionEvent
persistent class DetectionEvent {public:
indexable int detectorID;indexable char
timestamp[MAX];…
}
31
Ode Schemes: CenterControllerpersistent class CenterController {
private:int state;persistent DetectionEvent * detectionEvents;
public:void reset();void detection(int detectorID);void addDetector(int detectorID);void deleteDetector(int detectorID);void addAlarm(int alarmID);void deleteAlarm(int alarmID);
}
32
Ode Schemes: Schedulepersistent class Schedule {
public:indexable int scheduleID;int startH, startM, stopH, stopM;int mode;int shortDelay;int longDelay;…
}
33
Ode Schemes: ControlPanelpersistent class ControlPanel {
private:indexable int activeScheduleID;persistent Schedule * schedules;
public:void reset();void changeSchedule(int schedID);void addSchedule(int schedID);void deleteSchedule(int schedID);void activateSchedule(int schedID);…
}
34
Ode Schemes: Detectorpersistent class Detector { private:
indexable int detectorID;int state;
public:void reset();void trip();…
}
35
Ode Schemes: Alarmpersistent class Alarm { private:
indexable int alarmID;int state;
public:void reset();void activate();…
}
36
Behavior Implementation Examplepersistent EmergencyNotifier * emergencyNotifier;persistent CenterController * centerController;persistent ControlPanel * controlPanel; void CenterController::detection(int detectorID) {
. . .for (alarms in Alarm)
alarms->activate();
detectionEvents = pnew DetectionEvent(detectorID, makeTimeStamp());wait = FALSE;
37
Behavior Implementation (cont)if (controlPanel->getActiveMode() == MODE_IMMEDIATE)
state = ACTIVE;else
wait = TRUE;if (wait) {
if (controlPanel->getActiveMode() == MODE_SHORT)
delaytime = controlPanel->getShortDelay();else
delaytime = controlPanel->getLongDelay();
targetTime = gettime() + delaytime;delaying = TRUE;
38
Behavior Implementation (cont)while (delaying) {
if (timeEqual(targetTime)) {emergencyNotifier->notify();state = ACTIVE;delaying = FALSE;
}else if (userAbortButtonPressed()) {
reset();state = READY;delaying = FALSE;
}}
}
39
Credit This home security system case study is
extracted from Chapter 17 from “Object Database Development Concepts and Principles” by David W. Embley
Code for this case study is extracted from security.c file, developed by Matthew Lundgreen, Brian Bouck, and Michael Martin