Defining transient or temporary collections
Transient or temporary collections are derived or calculated collections, which are not stored in the database but calculated at run-time. Usually, transient collections allow defining different views (extensional, intentional or mixed). Sometimes, extensional views are more complex than one can express simply by a filter condition. Those problems can be solved by defining transient or temporary collections.
Transient or temporary collections ca be defined on top level (global collections), but also as subordinated reference collections.
In order to define a transient or temporary collections the transient option must be switched on and at least one index must be defined. The index definition is always required, also in case the transient or temporary collection has at maximum one instance (single reference). In case of unordered transient or temporary collections, an empty key name has to be set in the index definition. The distinction between transient and temporary collections is made by the create option ( NO_CREATE in ODL). A transient collection is defined by setting create to false , for a temporary collection create must be set to true.
Transient and temporary collections behave similar but differ in the way they are stored. Transient collections create an index in memory, while temporary collections create an index in a temporary main base. Temporary collections are the better solution for large derived collections, while transient collections perform better for small subordinated collections (less than 1000 instances). Also, when defining more than one index, temporary collections should be used instead.
Transient and temporary collections can be defined based on a source expression, which can be directly assigned to the reference definition (see example below and picture above). This is the simplest way creating transient or temporary collections. Another possibility is to create the collection in a context class handler function (e.g. DBRead () for the parent instance or DBOpened () for the object space).
Referring to source expressions, the expression must be valid in the context of the reference (not the parent structure). In order to access properties of the parent structure (i.e. the structure the reference belongs to), the expression must provide the parent property e.g. by calling GetParentProperty ().
Source expressions can be assigned in an ODL script reference definition but also in the ClassEditor application as shown in the picture aside. Sources in the class editor application may get a name, which does not have any specific meaning in this case, i.e. one may choose any name you want.
Transient and temporary collections with source definitions are calculated on demand, i.e. when accessing the transient collection the first time (e.g. by reading an instance from the transient collection with Get () or Next ()). The collection is created only, when an instance in the parent property handle has been selected. In the example, this means that the mother reference is calculated only, when a person has been selected in the parent property handle. Each time, when selecting another person in the parent property handle, the transient collection will be reset. The new collection is calculated, when being accessed, again.
Instances in transient or temporary collections might be persistent instances located in the database ( AddReference ()). However, transient or temporary collections may contain also transient or temporary instances (depending on the collection type). Transient instances do have the restriction, that they can be stored in transient collections, only, and that they may not refer to other instances, i.e. they may not define persistent references or relationships, which is possible for temporary instances in temporary collections.
// ODL definition
REFERENCE TRANSIENT Person NO_CREATE Mother[1] =
{
VARIABLES
SET<Person> &person = GetParentProperty;
SET<Person> &parents = person.parents;
PROCESS
while ( parents.Next )
if ( parents.sex == 'female' ) {
AddReference(parents); // add instance to collection
break;
}
}
ORDERED_BY (pid UNIQUE);