Creating Business Components
Much like Business Entities, it is necessary to create an implementation class
(*_Impl) 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:
-
@BusinessComponentclass annotation.-
customizationReplaceableattribute specifies whether or not customers can replace this component at runtime. The default isfalse. If a component is replaceable, its methods are assumed to becustomizationCallable.
-
-
GenericBusinessComponentis extended, which gives this class access to framework methods. -
PersonFindersis 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.-
@BusinessMethodis an optional method-level annotation.-
customizationCallablespecifies 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.
-
-
