Jump to: navigation, search

Difference between revisions of "CDOQuery OCL"

(OCL Query Examples)
Line 44: Line 44:
Get the dates of all Konsultations <pre>Konsultation.allInstances().datum</pre>
Get the dates of all Konsultations <pre>Konsultation.allInstances().datum</pre>
Get the attribute numericId of all instances of Patient <pre>Patient.allInstances()->collect(numericId)</pre>

Revision as of 08:55, 8 April 2013

Based on CDO 4.0-SR2

For some basic references to OCL please find http://atlanmod.emn.fr/atldemo/oclturorial/ or http://cs.ulb.ac.be/public/_media/teaching/infoh302/oclnotes.pdf


We have the following, deliberately trivial, model:


We have the entities Patient and Konsultation (Consultation), which hold some generic attributes resp. features. The enumeration Geschlecht (sex) is self explaining. Each Konsultation belongsTo exactly one Patient, it is however not contained by the patient but exists as independent entity.


This section documents some queries based on the aforementioned model. It is work in progress.

Queries are carried out on the whole Repository, so it is not important to what Resource an element belongs to.

Finding object references

The following OCL query finds all Konsultation entries in the entire repository, that belong to a certain Patient p, "injected" by the context. The element provided by the context is refered as self within the query.

CDOSession session = ...
CDOTransaction cdoTransaction = session.openTransaction();
CDOQuery cqo = cdoTransaction.createQuery("ocl",
		((Patient)p).cdoID(), false);
List<Konsultation> lre = cqo.getResult(Konsultation.class);

The most important part in this query is the fact that we are comparing real objects, as k.belongsTo refers to an element of type Patient. For OCL CDO to evaluate this query correct, we need to pass the context objects CDOID object as otherwise we will receive an error. A direct comparison by simply passing (Patient)p as context is hence not possible.

OCL Query Examples

These query examples are pure OCL only, the need to be embedded into an OCL query!

Find all instances of Patient
Get the number of instances of Patient
Get all instances of Patient where nachname is exactly Descher
Get all instances of Patient where nachname starts with G
Get the dates of all Konsultations
Get the attribute numericId of all instances of Patient