Professional Documents
Culture Documents
Interface
Specifies only the behavior of object type
The state of an interface (i.e its attributes and relationships ) cannot
interfaces or classes.
Class
specifies both state (attributes) and behavior (operations) of an object
type,
It is instantiable.
Hence, database and application objects are typically created based on
the user-specified class declarations that form a database schema.
Literal
specifies state but no behavior.
Thus,a literal instance holds a simple or complex structured value but
has neither an object identifier nor encapsulated operations
ODMG MODEL
Interface declaration
interface Object
{ ...
boolean same_as(in object other_object);
object copy();
void delete();
};
Class Date : Object {
enum Weekday { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
enum Month { January, February, March, April, May, June, July, August, September,
October, November, December };
unsigned short year();
unsigned short month();
unsigned short day();
...
boolean is_equal(in Date other_date);
boolean is_greater(in Date other_date); ...
};
ODMG
Class Time : Object {
...
unsigned short hour();
unsigned short minute();
unsigned short second();
unsigned short millisecond();
...
boolean is_equal(in Time a_time);
boolean is_greater(in Time a_time);
...
Time add_interval(in Interval an_interval); Time subtract_interval(in Interval
an_interval); Interval subtract_time(in Time other_time);
};
In general, operations are applied to objects using the dot notation. For example,
given an object O, to compare it with another object P,we write
o.same_as(p)
INHERITANCE IN THE OBJECT MODEL OF ODMG
In the ODMG object model, there are two types of inheritance
1. Behavior inheritance
it is also known as ISA or interface inheritance,
department and
The Has_emps invers relationship that Department has
Interface Date:object
ODL SYNTAX AND DATA TYPE
ODL – Interface Definition
All Objects inherit the basic object interface
Interface Object {
….
Boolean same_as(in object other_date);
Object copy();
Void delete();
}
ODL – INTERFACE DEFINITION
Example 1
Interface Date: object{
enum weekday{ sun,mon,tue,wed,thu,fir,sat};
enum Month { jan, feb, mar…., dec);
unsigned short year();
unsigned short month();
unsigned short day();
…
boolean is_equal(in Date other_date);
boolean same_as(in Date other_date);
}
ODL SYNTAX AND DATA TYPE
ODL – Class Definition
Class Name,[extends Name,]
{
extent name_of_extent
Key Name_of key
}
{
Attribute Structs_name{….} name;
Attribute string ;
}
ODL SYNTAX AND DATA TYPE
ODL – Class Definition
Example 1
Class Person
(
extent Persons
Key ssn
)
{
attribute struct pname (string fname, string lastname) name;
attribute string ssn;
attribute date birthdate;
attribute enum Gunder (M,F) sex;
attribute struct Address(int no,
string street
string ciyt
string post_code) address
int age();
}
ODL SYNTAX AND DATA TYPE
ODL – Class Definition
Example 1
Class FaculityMemebr extends Person
(extent faculity )
{
attribute string rnak;
attribute float salary;
attribute string phone;
relationship dept_works_in Inverse Dept:has_facultyManager
relationship set<GardStu> adviser Inverse Gradstu:adviser ;
Void give_raise(in float raise);
Void promote (in string new_rank);
}
ODL SYNTAX AND DATA TYPE
ODL – Interface Definition
All Objects inherit the basic object interface
Interface Object {
….
Boolean same_as(in object other_date);
Object copy();
Void delete();
}
2.3 OBJECT QUERY LANGUAGE (OQL)
It is ODMG’s query language
Syntax is similar to SQL with additional features.
Basic Syntax
select ...
from ...
where ... Structure
Example
Select d.name
From d in departments
Where d.college=‘Engineering”;
OQL BASIC SYNTAX
For the query, an entry point to the database is
needed.
The entry point can be any named persistent object.
Example
named object DEPARTMENTS is a type
set<DEPARTMENTS>
Named object PERSONS is a type set<PERSON>
OQL BASIC SYNTAX
Iterator variables: When we use extent name in our
query we need to define an iterator variables.
For example “ D” is an iterator variable in the
following query
select D.Dname from D in DEPARTMENTS
where D.College = ‘Engineering’;
However,
A query does not have to follow the following format
select… from …where
The result of a query can be any type that can be expressed
in the ODMG object model.
Where :
<fromList>:- < variableName> IN <expression> |
<variableName> IN < expression>
<expression> AS <variableName>
OQL BASIC SYNTAX – PATH EXPRESSION
A path expression is used to specify a path to attribute
and object in the entry point
A path expression starts at a persistent object name
(or its iterator variables)
The name will be followed by zero or more attribute or
relationship names.
In the following example, there is a
“CS_DEPARTMENT” persistent object and that
become the entry point for the query
CS_DEPARTMENT.Chair;
CS_DEPARTMENT.Chair.Rank;
CS_DEPARTMENT.Has_faculty;
OQL BASIC SYNTAX – PATH EXPRESSION
Example
Select f.rank
from f in computer_dept.has_faculityMember
Select distict f.rank
From f in computer_dept.has_facultyMember
OQL BASIC SYNTAX – PATH EXPRESSION
OQL query can return a result with a complex structure
specified by struct keywords.
Example – Embedded /nested query/
Retrieve last and first name plus degree information for all
student advised by the head of computerDept.
Also written as
select struct ( last_name: S.name.Lname, first_name:
S.name.Fname, gpa: S.gpa )
from S in STUDENTS where S.Majors_in.Dname = ‘Computer
Science’ and S.Class = ‘senior’ order by gpa desc, last_name asc,
first_name asc;
OTHER FEATURES OF OQL
Specifying views as named Queries
The view mechanism in OQL uses the concept of a
named query.
The ‘define’ keyword is used to specify an identifier of
the named query, which must be a unique name
among all named objects, class names, method names,
and function names in the schema.
Example
define Has_minors(Dept_name) as
select S from S in STUDENTS
where S.Minors_in.Dname = Dept_name;
Then we can use the view as
Has_minors(“computer science”), which return a bag of
students minoring in the computer science department
OTHER FEATURES OF OQL
Collection Operator (Aggregate Function,
Quantifiers )
The aggregate operation (min, max, count, sum, avg)
operates over a collection
The operator count returns an integer type. The remaining
aggregate operators (min, max, sum, avg) return the same
type as the type of the operand collection
Example
count ( S in Has_minors(‘Computer Science’));
InterSystems
ObjectDB
Open Sourse
Db4o
Ozone
Prest
Zope(ZODB)
End of Chapter Two
Thank You!