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 one may change the dictionary folder, which refers to the position where you did create your Sample development database (dictionary). When the definition file Sample.odl had not been copied to the OSI folder in the project folder, the sample might be copied from this page or from the documentation folder. More explanations for the schema definition you will find in the topics below (Sample schema notes).

In order to load the schema, one may call ODL.sh (LINUX) or ODL.cmd (Windows). 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 next chapter.

When using the generated defaults, the dictionary will be created in the project's root directory (e.g. ~/Sample/Sample.dev). In order to place it somewhere else, the DICTIONARY path in the ODL script (OSI/Sample.odl) has to be changed.

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

};

Notes:

Schema loading should work without problems when the Sample project had been created. When creating another project, one may have to update the ODL.sh or ODL.cmd file in order to ser the proper location for the schema file. Moreover, one has to make sure, that the dictionary path in the .odl file is correct.