Creating the Implementation Class

There is very little that needs to be done by application developers to create a basic business entity. In addition to the setup of the CI_​MD_​* tables describing the entity and its constraints only an implementation class (or "Impl" for short) needs to be added. In this case a developer added Person_​Impl. The following is a simple example of an "Impl" class for the Person entity.


/**
 * @BusinessEntity
 *   (tableName = CI_PER,
 *    oneToManyCollections  = { @Child( collectionName = names,
 *                                 childTableName = CI_PER_NAME,
 *                                 orderByColumnNames = { SEQ_NUM } )
 *                            }
 *   )
 */
public class Person_Impl
    extends Person_Gen {
    /**
     * @return the UI Display "info" for this person
     */
    public String getInfo() {
        return "PrimaryName: " + getPrimaryName().getInfo();
    }
}

Important parts of the implementation class are described below:

  • The implementation class name must end with the suffix "_​Impl". For example, if the entity has a name of "person" then the implementation class name of "some.package.Person_​Impl". It also means that the generated business interface will have a name of "some.package.Person".
  • A Class Annotation which declares:
    • What table this entity represents
    • What the owned-child tables are and what they should be called
    • Other information. Please see the BusinessEntityAnnotation class for more details.
  • The class extends an abstract superclass having the suffix of "_​Gen". Continuing the example of an entity named "person", the implementation class would extend a not-yet-created abstract superclass named "some.package.Person_​Gen". This superclass is created by the artifact generator based on metadata about the table and contains:
    • Getter methods for properties including parent objects and collections
    • The getDTO() and setDTO(...) methods that allow for properties to be changed
    • Access to standard framework methods like createQuery(...)
  • Business methods. Any hand coded public methods are automatically exported onto the generated business interface (e.g. "some.package.Person"). Client code can then access the added business method as follows:

 Person aPerson = some logic retrieving a person instance
 String thePersonsInfo = aPerson.getInfo(); 

  • Constants. Any hand coded public static final variables are automatically exported onto the generated business interface. This will be useful for constants related to the entity.
  • Having created a new entity, it is likely that validation rules and other behaviors should be added to it. Please see Adding Change Handlers for more information.