©Copyright by Kazimierz Subieta.

SBQL for the AS2 Store Model

by Kazimierz Subieta

Back to Description of SBA and SBQL.

Back to AS2 store model.

To the best of our knowledge, among all the proposed query languages only SBQL addresses the model with dynamic object roles and dynamic inheritance. This feature was implemented (several times) in our prototypes, for instance, in for the needs of PhD-s by A.Jodlowski and R.Adamus. Other proposals do not even noticed that such a model can be the subject of query languages. However, many features of currently considered artifacts, such as executable UML in the MDA architecture, call for such a capability. Similar features sooner or later will be necessary for Web-oriented ontology descriptions. In our opinion, a sufficiently general query language having such a feature cannot be developed on the ground of other theoretical approaches to query languages. Changes introduced by AS2 in comparison to the AS0 and AS1 models concerns essentially three points, which are rather conceptually obvious and easy in implementation.

1. An initial database section on ENVS should contain binders to all the roles.

2. When a non-algebraic operator pushes on ENVS a section for a role, it automatically pushes on it sections of all its super-roles, in proper order.

3. Some new operators in SBQL are necessary to serve roles.

For instance, Fig.36 presents the beginning state of ENVS for the database shown in Fig.11 and Fig.12.


Fig.36. Beginning state of ENVS in the model with dynamic roles

In more formal terms, if the database is described by the AS2 store model <S, C, R, CC, SC, SS>, then the database section is filled in by binders all binders n(i), where i R and n is the name of the object (perhaps a role) <i, n, x> S.

Concerning the second change, it implies pushing sections of super-roles when a role section is pushed on ENVS. Consider Fig.11, Fig.12 and a query having the form:

Emp where ... n ...

where n is any name occurring in the subquery after where. We assume that the where operator currently processes the Emp role identified by i16. The state of ENVS is presented in Fig.37.


Fig.37. State of ENVS during processing a role Emp by a non-algebraic operator

Fig.38 presents a more general case when an object contains 5 roles connected to some classes. Classes are connected by inheritance links.

Fig.38. Object with five roles connected to their classes

Assume that currently the role R5 is processed by a non-algebraic operator. The situation of ENVS is presented in Fig.39.

Fig.39. Situation on ENVS when the role R5 is processed by a non-algebraic operator

All the 9 sections, in the order determined by Fig.39, are pushed by a single non-algebraic operator. All of them are removed when the operator finishes its job. Developing a general case, on the ground of the given relations CC, SC, SS, is a rather easy implementation issue. Note that some sections may appear more than once. This is not a problem, because only the section closest to the top is taken into account. Optimization of this case, by removing unused sections, is possible, but one should not expect a big gain from it.

Note that (unlike AS1) the AS2 model does not require that object names are to be invariant of classes. At the same time it allows to create and process heterogeneous collections. Obviously, through its roles an object can simultaneously belong to many collections. Still, however, there is the same problem as in AS1 concerning typing pointers leading to an object with a given name.

Special SBQL Operators for the AS2 Model

According to the conceptual closure principle, roles, as a new feature of store model, require some new features in a corresponding query/programming language. In SBQL we propose the minimal and sufficient set of such features. Concerning the pure querying, we see only the need for two new operators:

  • A dynamic cast operator which converts a reference to a role into a reference (references) of another role (roles) of the same object. The operator will be written before a query returning such a reference (references) as

(role_name) query

  • If the object has no a role role_name, the operator returns an empty bag. The operator is defined as macroscopic: it may act on a bag of references to roles and returns a bag being the union of all the references that are returned for individual arguments. The operator works in any direction: it may be used to identify a super-role, a sub-role or a neighbor role.
  • Testing if an object has a given role. The syntax is the following:

query has role role_name

where query returns a single reference to a role. The operator returns true if the role identified by query has a sub-role named role_name, and false otherwise. If query returns an empty bag or it returns more than one role, this is probably an error thus the system should throw an exception. Alternatively, we can assume existential quantification, that is, the following equivalence:

query has role role_name is equivalent to $ query as x (x has role role_name)

Assuming dynamic programming with reflection other operators can be necessary, such as returning names of all roles of the given object.

There is very low demand for new data manipulation operators specific for dynamic object roles. Actually, only one such operator is indeed necessary, that is, insert an object as a sub-role of the given role. The reverse delete operator is a bit extended: removing a role implies removing all its sub-roles. In particular, removing a main role is equivalent to removing the corresponding object. Roles, however, may present some problem for virtual updateable database views. Concerning this topic, no research, implementation or proposal is till now done (afaik), but the topic looks as challenging, just for some PhD.

Examples of SBQL Queries for the AS2 Model


Fig.40. A database schema for the model with dynamic object roles

In Fig.40 dynamic inheritance is denoted by an arrow with a black and white diamond end. Cardinalities express the facts that there can be any number of persons, each person can be an employee at most once and a student zero or more times. Each Student role is connected to exactly one school. Each Emp role is connected to exactly one Dept. An Emp role can have a Manager sub-role; it has no attributes.



Get employees older than 60 who live in Warsaw (dynamic inheritance of the attribute Address and the method age).


Emp where age > 60 and $Address (city = “Warsaw”)



Get names and net salaries of managers managing departments located in “Cracow” (dynamic inheritance of the attribute name from the Person class, static inheritance of the method netSal from the Emp class and navigation to Dept).


(Manager where $((manages.Dept.loc) as l )(l = Cracow)).

                                                                                        (name, netSal)



Get names of persons who are at the same time employees and students (dynamic casts or the has role operator).




((Person as p) where p has role Emp and p has role Student).p.name



Get name, faculty and school name for each person studying at two or more faculties.


(((Person as p) join ((((Student)p) group as s))) where count(s) ≥ 2). (p.name, s.(faculty, (studiesAt.School.name)))



For each person get name and the sum of all the incomings (salary and scholarships).


(Person as p).

(p.name, sum(bag(0, ((Student)p).scholarship, ((Emp)p).sal)))

Note that the query takes automatically into account that some Person has no incomings. It correctly addresses the fact that he/she can have many Student roles, thus many scholarships. It also works for the case when his/her role Emp role has no sal attribute. Compare an “equivalent” SQL query to realize that it is much more complex and illegible than the SBQL query.


Get students who live in the same city as the city of their school.


Student where $Address (city = (studiesAt.School.city))


Last modified: January 07, 2010