Building a Mediator

Step 2: Defining the mediator - extents

We want to specify the mapping from data sources to our classes. We'll focus on the Person class. In K2MDL, this is done by inserting OQL into the ODL in three places. First, we must define the extent of each class. An extent is a set of object identifiers (OIDs), each of which uniquely identifies a particular object.

For example, the following piece of OQL pulls the Employee ID's out of the company phonebook. We're assuming that Phonebook has been exported by one of the data drivers as a collection of records, each containing information from a phonebook entry.

    select distinct p.ID from Phonebook p;

This set will constitute the extent of the Person class. To change our ODL into K2MDL, we change the class keyword to classdef, and place this OQL query inside the extent clause of the class, enclosed in braces:

  classdef Person (extent People { select distinct p.ID from Phonebook p; })
  {
    attribute String name;
    attribute integer salary;

    relationship set member_of_projects
        inverse Project::team;
    relationship set manager_of_projects
        inverse Project::manager;
  }

The keyword distinct is important here, since an extent cannot contain duplicates (that is, the type of the collection must be "set", not "bag" or "list"). Note that any OQL query that returns a set type can be used here - there are no restrictions on the type of elements in the set. So, for example, if we didn't have a convenient value like Employee ID that uniquely identified a person, our extent might be a set of records, each containing the person's name and address.

The next step is to define the attributes.


[Tech Docs Index]