Reference‎ > ‎

Rules: Count

Definition


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

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

public class CustomerLogic {
    
    @Count("orders where paid = false")
    public void deriveNumUnpaidOrders() { }

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 Count for the attribute numOrders would be defined by a method named deriveNumOrders.

Parameters

 <value> [required] the role name indicating the children to be counted, with (optionally) a qualification.
For example:
    "orders"
    "orders where paid = false"
 attributeName [optional] the name of the attribute whose value is calculated by this Count. The type of the attribute must be byte, short, int, long (or their corresponding classes), or BigInteger.

Effect

The value of the attribute will be updated to reflect the number of 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 Count.

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

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

Comments