company logo

Load database schema

In order to simplify the schema definition, we provide the example as listed below. The example schema describes companies ( Company ), which have got employees ( Employee ), which are persons ( Person ) and cars ( Car ). The cars of a company might be assigned to be used by one or more employees of the company.

Before loading the schema you may change the dictionary folder, which refers to the position where you did create your Sample development database (dictionary). The sample might be copied from this page or from the documentation folder (ImportSample.odl). More explanations for the schema definition you will find in the topic below (Sample schema notes).

After updating the DICTIONARY location in the example below and storing the schema in ImportSample.odl , you may load the sample schema into the database by calling the schema loader according to your platform.

In order to update the schema, one may extend the ODL script and reload it. A more comfortable way, however, is using ODE tools ( ClassEditor ) as being described in the ODABA GUI documentation ( Quick Starter Guide/9 Steps to develop a GUI application/View or update schema definitions ).

DICTIONARY = 'Sample.dev'; // sample resources

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() - birth_date)/365.25 );

    };

    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); )

  {

//    ATTRIBUTE   INT(10,2)  income;

    

    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;

    };

  };

  

// 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 );

};