company logo

Database context programming

Context programming allows defining business rules on database and type or property level. In ODABA, business and application rules are implemented in so-called context classes. A context class provide event handlers and common business rules for a complex data type or property (or database(object space). ODABA distinguishes between context classes for complex instances (type context) and context classes describing the behavior of property instances (property context).

Within a context class, system events generated by the system can be handled. System events are generated, when an instance (elementary or complex) changes its system state (system states reflect the current use state of a database item, but not the state for the item - instance or property).

Context programming is provided for two reasons: One reason is, that this is a flexible way of associating context specific behavior for a complex data type or property. By associating context classes with data types or properties, behavior becomes independent on data model but is still related to data model resources.

The second reason is, that this event handlers implemented in context classes are the most efficient way of handling system events whenever necessary.

Usually, only one or two percent of properties and data types in an application need to be linked with specific context classes, since many complex database rules are supported directly by the database. In order to implement a context class, the following steps become necessary:

  • Create a resource reference (SDB_ResourceRef), which provides the link between a data model resource and the context class
  • Create or associate the context class to be linked with the database model resource
  • Implement event handlers and business rules in the context class
  • [Create the context library]

This documents describes the necessary steps for creating a context class without using the ODE ClassEditor. This is not so simple and one may also use the ClassEditor, which automatically does many things to be done manually otherwise. Hence, the subsequent topic will contain references to the ClassEditor documentation for performing the same action.

Property context classes

Property context classes can be implemented in order to provide specific event handlers or business rules for elementary or collection instances. Property events are generated, when the property instance changes its state or when a system event is signaled for the property instance.

Type context classes

Type context classes can be implemented in order to handle events generated for complex instances, i.e. when a complex instance changes its state (instance or system state). The type context class is associated with the complex data type of the instance.

Object space context

Object space context classes can be implemented in order to handle events for an object space. Usually, object space context classes should be implemented only, when the database is working with different object spaces. In order to link an object space with a context class, a named object (object model resource) has to be defined and a resource reference has to be assigned and associated with the corresponding context class.

The root object space is handled, usually, by the database context.

Database context classes

Database context classes can be implemented in order to handle events for a database. In order to link a database with a context class, a database object (object model resource) has to be defined and a resource reference has to be assigned and associated with the corresponding context class.