Using DatasetModel classes to simplify data access from custom code

The Model classes provide an easy way to access and modify data in a consistent way from the client and the server. Model classes are based on  BusinessEntities and can be generated from the BusinessEntityDesigner the Consultingwerk.BusinessEntityDesigner.Plugins.ModelClassGeneratorPlugin plugin. The plugin will generate one DatasetModel for the BusinessEntity and one TableModel for each Temp Table of the ProDataset. The access to the data is provided through an easy to use API which can be used in the same way on the client and on the AppServer. In the following you will see how you can access customer data from a BusinessEntity using the Model classes. As an example we created based on the sports2000 database a CustomerBusinessEntity with two Temp Tables, Customer and Salesrep using the BusinessEntity Designer. Once activated the plugin will generate a series of class files generated in addition to the normal BusinessEntity files every time the BusinessEntity Designer generates code:


CustomerDatasetModel_Generated 

Auto Generated portion of the CustomerDatasetModel class 

CustomerDatasetModel 

DatasetModel of the CustomerBusinessEntity 

CustomerTableModel_Generated 

Auto Generated portion of the CustomerTableModel class 

CustomerTableModel 

TableModel of the Customer Temp Table 

CustomerTableModelFilter 

Filter class for the CustomerTableModel 

SalesrepTableModel_Generated 

Auto Generated portion of the SalesrepTableModel class 

SalesrepTableModel 

TableModel of the Salesrep Temp Table 

SalesrepTableModelFilter 

Filter class for the SalesrepTableModel 

  

The foundation for the functionality of the Model classes is implemented in the base classes located in the Consultingwerk.OERA package: 


Model base class for a Dataset 

Performs the backend requests of the Dataset Model class 

Abstract base class for Temp Table Models 

  

Sample use case 1 

When creating a new order for a customer you might need to display the correct prices for all items without having to save the changes. To make this possible we need to calculate the value based on the item price and the general discount of the customer. Problem here is that we do not have the information about the current customers discount available on the client. Using the Model classes you have an easy way to get that detail without having to deal with the configuration of UI components like the SmartBusinessEntityAdapter or creating your own FetchDataRequest and use the ServiceAdapter to communicate with the backend to get the information and then get the information from a Temp Table. 

See below how to get the customer discount for customer number 10:

DEFINE VARIABLE oCustomerDatasetModel AS Test.ModelClasses.CustomerDatasetModel NO-UNDO. 

oCustomerDatasetModel = NEW Test.ModelClasses.CustomerDatasetModel (10). 

IF oCustomerDatasetModel:Customer:Available THEN  
    MESSAGE oCustomerDatasetModel:Customer:Discount 
        VIEW-AS ALERT-BOX.