Developing model classes
For each view object defined in the SLIS configuration file, an interface is generated by SEAF that defines the required methods of the model class that will realize the business logic for the view object. For each model interface generated by SEAF in package seaf.generated.logic within directory generatedsrc a class has to be coded that implements the interface.
Model class interface
A model class must fulfill the following:
- It must be accessible through seaf.ejb.ModelCreator class. The default model lookup behavior is that the class must have the name of the view object with "Model" appended (e.g. CustomerModel), and must reside in package specified by the application code from the SLIS configuration file with ".logic" appended (e.g. csvc.logic).
- Each business logic method of the model class must return an instance of seaf.common.ProcessingContext. For methods that serve actions on a detail view, the ProcessingContext should be of type single with the form values passed in as java.util.Map. For methods that serve actions on a list view, the ProcessingContext should be of type multiple with the table values passed in as java.util.Collection.
Each business logic method of the model class is passed in the request values as java.util.Map and a seaf.common.RequestContext object containing various context data to assist in fulfilling the action in the model method.
Model class environment
The model class implementation can use the following aids provided by SEAF to achieve the target behavior.
1. Method parameters :
- Request values passed in as java.util.Map.
- Request context passed in as seaf.common.RequestContext.
2. The SEAF Data Objects for manipulation with single instance of an entity.
SEAF provides the following 2 interfaces in package seaf.dos:
- Interface DOHome: provides methods to create a new instance, and to read details of an instance by the values of the primary key attributes. Both methods return an instance of interface DO.
- Interface DO works on a particular instance: it provides methods to update the instance, to delete the instance, and to retrieve the detail values of the instance as java.util.Map.
See the Javadoc documentation for more details.
For each entity defined in the SLIS configuration file, SEAF generates a class implementing the DOHome interface and a class implementing the DO interface. The classes are generated in package seaf.generated.dos in directory generatedsrc.
The business logic implementation should use the DOHome and DO interfaces to work with an instance of entity. This way the business logic implementation is shielded from any direct dependencies on Entity EJBs.
3. The SEAF Loader for retrieving multiple instances of an entity.
The seaf.sql.Loader class provides the following methods:
- Constructor that accepts the name of an entity as defined in SLIS configuration file and a list of search criteria in java.util.Map.
- Constructor that in addition to the parameters above accepts also specification of sorting: by what entity attribute should be the list sorted and whether in ascending or descending order.
-
Other constructors exist that accept the exact specification of columns to WHERE clause, including eg. operator.
-
Other constructors exist that accept specification of join tables.
- Method load(int page) searches for all instances of the specified entity that fulfill the search criteria, optionally sorts the result list as specified, and returns a specified page from the result list. If the page is set to seaf.sql.Loader.NO_PAGING, the whole result list is returned. The list returned contains the primary key attributes only. To get the detail values of each entity on the list, the read() method must be called on the appropriate DOHome class.
The Loader interprets the search criteria as follows:
- Parameters with empty values are ignored.
- Then system creates one search criterion per each parameter with a valid value, and combines all these criteria with logical AND. In other words, all the criteria must hold on a particular instance to be included into the result list.
- For parameters with type String, system uses SQL operator LIKE to compare the supplied value with the instance value. Therefore the user of the system can use wildcard characters ('?' to supplement a single character, and '%' to supplement any sequence of characters).
- For parameters of any other type, system uses the standard '=' operator.
4. The standard model implementation classes.
The seaf.logic package contains the SimpleModel, SimpleDependentModel and SimpleSlaveModel classes that can serve as example implementation of a model class, and when subclassed can provide a solid base for a model class implementation.
Rules for coding model classes
No exceptions should be thrown from business logic methods, if possible. On error conditions, return a ProcessingContext of type message with the appropriate error message to be displayed to the user.
Back to SEAF home page…