company logo

Defining transient attributes

Transient attributes allow calculating attributes at run time. A typical example is the age attribute, which should never be stored as persistent attribute, since it changes each day. It can, however, be defined as transient attribute (difference between birth and current date). For the application, transient attributes behave similar to persistent attributes, except, that one cannot update transient attributes, which are result of computation.

In order to define transient attributes, the transient option needs to switched on in the attribute definition.

The source for the attribute can be defined as OSI expression, which can be directly assigned to the attribute definition. The source expression must be a valid expression in the context of the structure, the attribute belongs to.

Source expressions can be assigned in an ODL script attribute definition but also in the ClassEditor application as shown in the picture. 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. Referring to a source expression has the advantage, that the expression is calculated only, when accessing the attribute explicitly.

When not defining a source for the attribute, the value for the transient attribute must be evaluated by the application (e.g. in the DBRead () handler of a context class for database structure).

Transient attributes might be complex. However, in this case an explicit access to the complex attribute is necessary in order to calculate the attribute value properly. Thus, defining an address ( street , zip , city ) as transient attribute, the application has to access the attribute address before accessing address.street etc. To overcome this problem, it is suggested to use transient references or collection in case of complex attributes rather than defining a transient attributes.


// short version

  TRANSIENT INT(5)     age = (Date() - birth_date).Year;

// explicit version

  TRANSIENT INT(5)     age = {

                             VARIABLES

                             PROCESS

                               (Date() - birth_date).Year;

                             };

Notes:

When defining a source for a transient attribute, it must be defined as operand or expression. When defining the source as an expression, there is no limit for the complexity of the expression.