company logo

Maintaining an aggregation collection

Maintaining aggregation collections is based on indicating changes on the grouping level. The grouping level, typically is based an instances called partition instances, i.e. instances in the collection defined in FROM parameter. Those are not stored in the aggregation model (except the application stored such a collection in a appropriate relationship.

The application may, however, inform the aggregation collection about changes in partition instances. When a partition instance has been changed, the application instance may call PropertyContext::aggregationUpdate() for the opened aggregation collection property handle. Since old and new instance state must be available, the function should be called in the TypeContext::doBeforeStore() event handler, which evaluates old and new grouping level instances and calls aggregate functions with old and new grouping instance and appropriate aggregation operation.

The aggregationUpdate() function receives the selected partition (source) property handle for old and new instance, which are passed to aggregate function with SubtractLow aggregation option for old instance and AddLow for new instance. More over, the function determines, whether aggregated key value has changed, in which case also created and affected subsets are updated. In order to optimize maintenance process, in case of unchanged key the function first calls the aggregation function with SubtractLow for subtracting old instance from new instance and updating aggregation hierarchy by adding the difference on all aggregation levels.

When the partition instance is not a persistent database instance, the application may also explicitly call PropertyContext::aggregationUpdate() by passing property handle with selected old instance and new instance state.

// type context has opened a property handle aggregation for

// aggregation collection

int32   sTimeSheet::doBeforeStore() {

  aggregation.propertyContext().aggregationUpdate(oldInstance(),property());

}