Reference‎ > ‎

Rules: Sum

Definition


A Sum is defined by a method with the @Sum annotation:

import com.autobizlogic.abl.businesslogic.annotations.*;

public class CustomerLogic {
    
    @Sum("orders.total where paid = false")
    public void deriveUnpaidBalance() { }

The name of the method has a special meaning if (and only if) the attributeName parameter is not specified. In that case, the name of the method must be deriveX where X is the name of the attribute.

For instance, a Sum for the attribute unpaidBalance would be defined by a method named deriveUnpaidBalance.

Parameters

 <value> [required] the role name indicating the children to be summed followed by a period, followed by the name of the attribute to be summed. This can then be (optionally) followed by a qualification.
For example:
    "orders.total"
    "orders.total where paid = false"
 attributeName [optional] the name of the attribute whose value is calculated by this Sum. The type of the attribute must be numeric, but not necessarily of the exact same type as the summed attribute. Conversion is done when necessary.

Effect

The value of the attribute will be updated to reflect the sum of the specified attribute in the child objects whenever necessary. This includes objects being added to and removed from the parent object, as well as modifications to the children objects that change their qualification in the Sum.

A Sum is not recalculated from scratch, but rather adjusted as necessary. For instance, when a new (qualifiying) child is added to the parent, the Sum attribute will be incremented by the child's amount. This means that there is very little performance impact.

If the method contains code, that code will be invoked every time the sum is adjusted, but this is meant only as a debugging aid: the code should not do anything that affects the object.
Comments