• No results found

ODL & OQL Interactive Session

5 – Object-Oriented Paradigm – OODB and the ODMG Standard

5.2 Path Expressions

5.3.5 ODL & OQL Interactive Session

The following is a sequence of ODL, OQL, scripts for an EyeDB-based object collection. The artefacts were executed on EyeDB CLIs.

Remark Define a class called person

class Person {

attribute string fname; attribute set<tel*> telno; …

relationship set<Project*> workson inverse Project::staff;};

Remark Define a class called student which is a subclass of person

class Student extends Person { attribute string stage;

attribute set<result*> results; relationship Course* enrolon inverse Course::candidates;};

Remark Define a class called lecturer which is a subclass of person

class Lecturer extends Person { attribute integer salary; … };

Remark Define a class called course

class Course {

attribute string cname; attribute integer cnum; … };

Remark Define an enumerated list for gender domain

enum gender { male = 1, female = 2 };

Remark Run a script to generate test objects for course Remark (? Is command prompt)

? for (x in 1000 <= 1999)

{ varname := "course" + string(x); nw :=

" := Course(cname:\"name"+string(x)+ "\", cnum:"+ string(x)+ ");"; cmd := varname + nw;

eval (cmd); }; ? \commit

Remark Extent and deep extent queries

Remark (= is response prompt and – start a remark)

-- Includes instance of person class and -- all its subclasses

? count(select x from Person x); = 1390

? select x.class.name from Person x where x.fname = "fn 6002"; = bag("Student")

OOP – OODB and the ODMG Standard- Page [ 116] -- Find Person instances that are instance

-- of class Lecturer

? select x.fname from Person x where classof(x) = "Lecturer"; = bag("fn 5025", "fn 5022", … ? count(select x from Person x where classof(x) = "Person"); = 350

? count(select x from Person x where classof(x)="Lecturer"); = 10

Remark Simple queries to check test objects

-- count is an aggregate function ? count (select Course);

= 1000

-- course10 is a variable points at an object ? select course10.cname;

= "name10"

-- first is function that returns 1st -- instance of a collection

? first(select Course.cname); = "name183"

Remark Controlling the output data type

-- return a bag of … ? select Student;

= bag(8831.3.17414:oid, 8803.3.1005572:oid,… -- return a set of …

? select distinct Student;

= set(8831.3.17414:oid, 8803.3.1005572:oid,… -- return a list of …

? select s.fname from Student s order by s.fname;

= list(8831.3.17414:oid, 8803.3.1005572:oid,… -- return a set of structures

? select distinct

struct(student:s.fname,level:s.stage) from Student s;

= set(struct(student:”stud 11”,level:”s”),…

Remark Selection Queries with path expressions

-- conjunction

? select p.fname from Lecturer p where p.addr.town="town 511" and p.salary > 45000; = bag("fn 5050", "fn 5037") -- disjunction

? select p.fname from Lecturer p where p.addr.town="town 511" or p.salary > 45000;

= bag("fn 5050", "fn 5011", … "fn 5037", "fn 5041")

Remark Projection query

? select bag(s.fname, s.enrolon.cname) from Student s

order by s.fname;

= list(bag("fn 5048",”f”), bag("fn 5112",”f”), bag("fn 5260",”f”), …

Remark Implicit join query

-- find which students and persons share -- the same town but not name (the last -- condition rids us of spurious instances) ? select struct(cons:s.fname,

emp:p.fname, town:p.addr.town) from Student s, Person p

where s.addr.town=p.addr.town and s.fname != p.fname;

= bag(struct(cons: "fn 4013", emp: "fn 4000", town: "town 500"), struct(cons: "fn 4006", emp: "fn 4019", town: "town 506"), …

OOP – OODB and the ODMG Standard- Page [ 117]

Remark Query over data dictionary – direct subclasses of class Person

? select struct(cn:x.name,cp:x.parent.name) from class x where x.parent.name="Person" = bag(struct(cn: "Student", cp: "Person"), …)

Remark Stored procedure: recursively traverse the class hierarchy for subclasses

-- definition

function subclasses(cn) {

clist := bag(); cclist := bag(); cmd := "clist:= (select x.name”+ “ from class x”+

“where x.parent.name = \"" + cn + "\");"; eval cmd;

if ( clist[!]=0 ) { return clist; } else { cclist := clist; for ( c in clist ) { cclist += subclasses(c); } return cclist; }}; -- invocation of function ? select subclasses("Person"); =bag("Student", … )

Remark Stored procedure: generate a random digit

-- definition function rnddigit() { dseq := 0; dseq := (select time_stamp::local_time_stamp()). usecs; s := string(dseq); l := s[!]; return s[l-1]; }; -- invocation of function ? select rnddigit(); = '9'

5.4 Summary

Interest in object-oriented databases started in the early Nineties with much diversity in the data models and clearly an alignment effort was required. In this chapter we have synthesised a data model that provides a basis for an object-oriented database with a practical and effective selection of features. Our object-oriented data model has classes, ISA

relationship, data types, and objects composed of value, identity and instance-of relationship. We emphasise that there are two separate relationships from classes to inheritance and data types.

A section was dedicated to path expressions; these are constructs that abbreviate object navigation expressions. Path expressions implement what are called implicit joins over the database schema. Advanced path expression can be adorned with universal quantification and pattern matching.

The standardisation process by ODMG finished in the early Naughties; its object and query model was a focal point in this chapter. Their final version is a good standard. We have

OOP – OODB and the ODMG Standard- Page [ 118]

given a critical look at its data model and how it is used as a basis to its query model. The main critical points were: it took a long time to produce; its quality took too long to pick up; although adequately thorough in its object and query model it lacks precision and completeness in substantial parts (e.g. views, integrity constraints). Also some features, for example relationships, need more and wider capabilities.

EyeDB is an open-source OODBMS and has a good level of compliance with ODMG’s ODL and OQL. This level of conformance is hard to find and was the main reason for its adoption here. EyeDB is used to read and creates schemas generated from a framework we developed that reads an EERM and create a sequence of ODL and EyeDB constructs (e.g. integrity constraints not catered for in ODMG) to implement the design.

During the progression of this chapter a number of side references were made to other technologies that can be considered to have a basis in one of the object-oriented database features presented; e.g. Xpath and path expressions.

Nonetheless we still have to resolve a basic requirement made earlier on; i.e. to have a declarative and a procedural language that operates on our synthesised object-oriented data model. In the following two chapters we show how a deductive database caters for the declarative query modelling; furthermore the same logic can describe an array of structural constraints. Once the logic is in place we can present our framework and an algebra that operates on an object-oriented database.

Chapter 6

Deductive & Object-Oriented Databases