Creating Business Components

Much like Business Entities, it is necessary to create an implementation (*_​Impl) class containing the actual logic that is then processed by the artifact generator. Below is an example that would be created by hand:


/**
 * Component used to query for {@link Person} instances based on various
 * predefined criteria.
 *
 * @BusinessComponent
 *   (customizationReplaceable = false)
 */
public class PersonFinders_Impl
    extends GenericBusinessComponent
    implements PersonFinders
    /**
     * @param   nameType  a name type
     * @return  count of names by name type
     *
     * @BusinessMethod (customizationCallable = true)
     */
    public int findCountByNameType(Lookup nameType) {
        Query query = createQuery
            ("FROM PersonName name where name.nameType = :type");
        query.bindLookup("type", nameType);

        return (int) query.listSize();
    }
}

This example shows a "finder" component that is responsible for holding queries related to the "person" entity. These queries are not related to any particular person because, in that case, they would rightfully belong on the entity implementation class itself. Our (cooked up) example shows a single method that returns a count of PersonName instances by name type.

Let's look at various parts of the component:

  • @BusinessComponent class annotation.
    • customizationReplaceable attribute specifies whether or not customers can replace this component at runtime. The default is false. If a component is "replaceable", its methods are assumed to be "customizationCallable".
  • GenericBusinessComponent is extended which gives this class access to framework methods.
  • PersonFinders is implemented. This is the name of the generated business interface. Any customized replacement of the business component would implement this interface as well.
  • The business method findCountByNameType. For the method to be exported to the business interface (and therefore callable by other business objects), it must be public.
    • @BusinessMethod is an optional method-level annotation.
      • customizationCallable specifies that this method is part of the "supported" API. That is, our customers are entitled to call this method from their customizations and therefore, we must change this method with great reluctance in future release.