company logo

Database model for ODABA sample database

The model below defines the sample database model in ODL language. ODABA ODL is an extension of the ODMG ODL standard. With the server, also a test library is delivered, which contains a number of test requirements (and examples).

UPDATE SCHEMA Sample {

// Car class definition

  CLASS Car PERSISTENT (  KEY IDENT_KEY pk(cid); ) {

    ATTRIBUTE {

            CHAR(10)   cid;

            STRING(40) type;

            INT(2)     number_of_seats = 4;

    };

    RELATIONSHIP {

            Company       SECONDARY  company  INVERSE cars;

            SET<Employee> SECONDARY  users    ORDERED_BY (pk UNIQUE) INVERSE used_cars;

    };

  };

// Person class definition

  CLASS Person PERSISTENT

  ( KEY { IDENT_KEY pk (pid); sk (name); };

    EXTENT MULTIPLE_KEY owner Persons ORDERED_BY (pk UNIQUE NOT_EMPTY, sk); )

  {

    ENUM Sex {

                male = 1,

                female = 2,

                undefined = 0

    };

    STRUCT Address PERSISTENT {

                STRING(6)  zip;

                STRING(40) city;

                STRING(80) street;

                STRING(6)  number;  

    };

    ATTRIBUTE {

      NOT_EMPTY CHAR(16)   pid;

                STRING(40) name;

                STRING(40) first_name[3];

                DATE       birth_date;

                Sex        sex = male;

                bool       married = false;

                INT(10,2)  income;

      TRANSIENT INT(3)     age SOURCE( (Date().now() - birth_date)/365.25 );

      TRANSIENT INT(10,2)  children_inc SOURCE ( children.sum(income) );

    };

    REFERENCE   Address  location;

    REFERENCE   STRING   notes[4000];

    

    RELATIONSHIP {

                SET<Person>         children      BASED_ON Persons

                                                  INVERSE parents;

                Person   SECONDARY  parents[2]    BASED_ON Persons

                                                  INVERSE children;

                Employee SECONDARY  employee      INVERSE person;

    };

  };

// Employee class definition

  CLASS Employee PERSISTENT : Person person BASED_ON Person::Persons INVERSE employee

  ( KEY  IDENT_KEY pk(pid); )

  {

    RELATIONSHIP {

                Company SECONDARY   company       BASED_ON Company

                                                  ORDERED_BY (pk UNIQUE)

                                                  INVERSE employees;

                Car     NO_CREATE   used_cars[2]  BASED_ON .company.cars

                                                  ORDERED_BY (pk UNIQUE)  

                                                  INVERSE users;  

    };

  };

  

// Company class definition

  CLASS Company PERSISTENT ( KEY IDENT_KEY pk(name); ) {

    ATTRIBUTE   NOT_EMPTY STRING(200)  name;

    

    RELATIONSHIP {

                SET<Employee>       employees BASED_ON Employee

                                              ORDERED_BY (pk UNIQUE)

                                              INVERSE company;

                SET<Car>      OWNER cars      ORDERED_BY (pk UNIQUE)

                                              INVERSE company;

    };

  };

  

// View definition

  VIEW ChildrenIncome

    FROM( SET<Person> persons = Person::Persons  )

    WHERE( children.count > 0 )

    GROUP BY( STRING incGroup = (income <= 1000 ? 'low'    :

                                 income <= 3000 ? 'medium' :

                                 income <= 7000 ? 'high'   : 'very_high' ),

              Sex sex = sex)

    ( KEY IDENT_KEY pk( incGroup, sex ); )

  {

    ATTRIBUTE {

                STRING(10) incGroup ;

                Sex        sex ;

                INT(10,2)  ci_sum = sum(children_inc);

                INT(10,2)  ci_avr = average(children_inc);

                INT(10,2)  ci_dev = deviation(children_inc);

                INT(10,2)  ci_min = minimum(children_inc);

                INT(10,2)  ci_max = maximum(children_inc);

      TRANSIENT INT(10,2)  diff   = ci_max-ci_min;

    };

  };

  // Global extent definition

  EXTENT Company UPDATE MULTIPLE_KEY OWNER Company

               ORDERED_BY ( pk UNIQUE NOT_EMPTY );

  EXTENT Employee UPDATE MULTIPLE_KEY OWNER Employee

               ORDERED_BY ( pk UNIQUE NOT_EMPTY );

  EXTENT ChildrenIncome TRANSIENT OWNER ChildrenIncome

               ORDERED_BY ( pk UNIQUE NOT_EMPTY );

  

};