Now that a database has been created, we are going to populate it with objects.
The first step is to define the database schema.
A standard example in databases 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.
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:
% eyedbodl -d foo -u person.odl Updating 'person' schema in database foo... Adding class Address Adding class Person Adding class Employee DoneNote that you must pass the following command line options to the eyedbodl command: -d foo to specify to which database you are applying the schema and -u to update the database schema.
% eyedbodl -d foo --gencode=ODLČ
//
// EyeDB Version 2.8.4 Copyright (c) 1995-2007 SYSRA
//
// UNTITLED Schema
//
// Generated by eyedbodl at Mon Dec 10 13:44:03 CET 2007
//
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.
% eyedboql -d foo -c "select schema" --print
= bag(2546.2.120579:oid, 2553.2.112046:oid, 2568.2.515951:oid)
struct Address {2546.2.120579:oid} : struct : agregat : instance : object {
attribute int32 num;
attribute string street;
attribute string town;
attribute string country;
};
struct Person {2553.2.112046: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.515951: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.