The first step is to define the database schema.
A standard example in database documentations is the well known Person class (or table in relational system) which contains a few attributes such as a firstname, a lastname, an age, an address, a spouse and a set of children.
We will show the inheritance feature through the simple class Employee which inherits from the Person class and will contains a simple attribute: salary.
There are several ways to create such a schema:
All these choices are valid however the last *two* are too complicated to describe here. Please refer to the appropriate manuals.
So we opt for the first choice which is the most pratical and flexible way to define and create a schema within a database.
Here is simple ODL schema for the classes Address, Person and Employee:
//
// person.odl
//
class Address {
int num;
string street;
string town;
string country;
};
class Person {
string firstname;
string lastname;
int age;
Address addr;
Person * spouse inverse Person::spouse;
set<Person *> children;
};
class Employee extends Person {
long salary;
};
A few comments about this schema:
To add the previous schema in the foo database, you need to use the eyedbodl tool as follows:
% eyedbodl -d foo -u --package=person person.odl Updating 'person' schema in database foo... Adding class Address Adding class Person Adding class Employee DoneTo verify that the update has correctly worked, you can generate the ODL schema from the database, as follows:
% eyedbodl -d foo --gencode=ODL
//
// EyeDB Version 2.7.0 Copyright (c) 1995-2005 SYSRA
//
// UNTITLED Schema
//
// Automatically Generated by eyedbodl at Sat Dec 3 19:02:00 2005
//
#if defined(EYEDBNUMVERSION) && EYEDBNUMVERSION != 207000
#error "This file is being compiled with a version of eyedb different from that used to create it (2.7.0)"
#endif
class Address (implementation <hash, hints = "key_count = 2048;">) {
attribute int32 num;
attribute string street;
attribute string town;
attribute string country;
};
class Person (implementation <hash, hints = "key_count = 2048;">) {
attribute string firstname;
attribute string lastname;
attribute int32 age;
attribute Address addr;
relationship Person* spouse inverse Person::spouse;
attribute set<Person*> children;
};
class Employee (implementation <hash, hints = "key_count = 2048;">) extends Person {
attribute int64 salary;
};
Note that the exact output may differ a bit from what is displayed above, depending on the EYEDB version.
By default, eyedbodl generates the ODL on the standard output. You see here that the displayed ODL is very similar to the original ODL except that the keywords attribute and relationship have been added before each attribute declaration. The relationship keyword means that the attribute has an inverse directive.
Note that these two keywords are optional: it is why we have not use them in our example.
Another way to check that the schema has been created within the database, is to use the eyedboql tool, as follows:
% eyedboql -d foo -c "select schema" --print
= bag(2544.2.881020:oid, 2552.2.291360:oid, 2568.2.164397:oid)
struct Address {2544.2.881020:oid} : struct : agregat : instance : object {
attribute int32 num;
attribute string street;
attribute string town;
attribute string country;
};
struct Person {2552.2.291360:oid} : struct : agregat : instance : object {
attribute string firstname;
attribute string lastname;
attribute int32 age;
attribute Address addr;
relationship Person* spouse inverse Person::spouse;
attribute set<Person*> children;
};
struct Employee {2568.2.164397:oid} : Person : struct : agregat : instance : object {
attribute string Person::firstname;
attribute string Person::lastname;
attribute int32 Person::age;
attribute Address Person::addr;
relationship Person* Person::spouse inverse Person::spouse;
attribute set<Person*> Person::children;
attribute int64 salary;
};
Again, note that the exact output may differ a bit from what is displayed above, depending on the EYEDB version.
Note that the object identifiers (oid) of the classes are displayed.