Reference‎ > ‎

Rules: Parent Copy

Definition

A Parent Copy is defined by a method with the @ParentCopy annotation:

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

public class CustomerLogic {

    @ParentCopy("product.price")
    public BigDecimal deriveProductPrice() { }

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

For instance, a Parent Copy for the attribute productPrice would be defined by a method named deriveProductPrice.

If the attributeName parameter is specified in the annotation, then the name of the method can be anything.

The type returned by the method must be the same as the type of the attribute.

Parameters

 <value> [optional] an expression that should evaluate to true or false. If it evaluates to false, the Constraint will fail.
 attributeName [optional] the name of the attribute whose value is set by the Parent Copy.

Effect

A Parent Copy automatically copies the specified attribute from the parent object into the specified attribute, any time the parent is attached to the child.

Assume that you have two classes: Lineitem and Product, with Product being a parent of Lineitem. 

Let's assume that Lineitem has an attribute named productPrice, and that we have defined a Parent Copy for that attribute, so that it copies the Product's price attribute.

If a Lineitem has no Product, then as soon as one is assigned to it, that Product's price will be copied into it.

If a Lineitem already has a Product, and a different Product is assigned to it, that Product's price will be copied into the Lineitem.

If a Lineitem already has a product, and that Product is removed, leaving the Lineitem without a Product, nothing happens.


A Parent Copy method may have code in it. If so, that code will be invoked, but that is meant only as a debugging tool. The code should not modify the object, or any other persistent object.

Comments