Top Banner
1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: [email protected]
39

1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: [email protected].

Jan 15, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

1

Active Object-oriented DBMS Case Study Using Ode

Khanh LeEmail: [email protected]

Page 2: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 3: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.)

Page 4: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.

Page 5: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

5

O++ language

Page 6: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.

Page 7: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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);

Page 8: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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;

Page 9: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.

Page 10: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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)

Page 11: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 12: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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;

Page 13: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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);

Page 14: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 15: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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);

Page 16: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.

Page 17: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

17

A Case Study

A Home Security System

Page 18: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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.

Page 19: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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)

Page 20: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 21: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

21

OBM of Active Objects Control Panel Center Controller Detector Alarm Emergency Notifier

Page 22: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 23: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 24: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 25: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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

Page 26: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

26

OBM of Emergency Notifyer

Ready

@set number set phone number

@notify notify emergency unit

Emergency Notifier 1

notify

set number (Number)

Page 27: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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)

Page 28: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

28

Database Schemes (cont) Control Panel(Active Schedule

ID, (Schedule)*) Detector(Detector ID, State) Alarm(AlarmID, State)

Page 29: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

29

Ode Schemes: EmergencyNofitier

persistent class EmergencyNotifier { private:

char phoneNumber[MAX];public: void changeNumber(char N[MAX]); void notify(); …

}

Page 30: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

30

Ode Schemes: DetectionEvent

persistent class DetectionEvent {public:

indexable int detectorID;indexable char

timestamp[MAX];…

}

Page 31: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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);

}

Page 32: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

32

Ode Schemes: Schedulepersistent class Schedule {

public:indexable int scheduleID;int startH, startM, stopH, stopM;int mode;int shortDelay;int longDelay;…

}

Page 33: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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);…

}

Page 34: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

34

Ode Schemes: Detectorpersistent class Detector { private:

indexable int detectorID;int state;

public:void reset();void trip();…

}

Page 35: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

35

Ode Schemes: Alarmpersistent class Alarm { private:

indexable int alarmID;int state;

public:void reset();void activate();…

}

Page 36: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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;

Page 37: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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;

Page 38: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

38

Behavior Implementation (cont)while (delaying) {

if (timeEqual(targetTime)) {emergencyNotifier->notify();state = ACTIVE;delaying = FALSE;

}else if (userAbortButtonPressed()) {

reset();state = READY;delaying = FALSE;

}}

}

Page 39: 1 Active Object-oriented DBMS Case Study Using Ode Khanh Le Email: khanhle@us.ibm.com.

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