Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

Code Block
themeEclipse
linenumberstrue
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. 
 


Sample use case 2 

On the backend side you often have to calculate values based on information from tables which are not available within the same BusinessEntity at that time. Now within the DataAccess class you are doing the calculation in, you could implement a query to lookup these values directly from the database or you could use the reliable (central) way of getting the value from another BusinessEntity which makes the solution a lot more future proof and secure. The good point is that you can use the same code from the previous sample to get the discount of customer number 10. 

...

The provided filter classes are located in the Consultingwerk.OERA.ModelFilter  package:  


Abstracts the access from the ModelFilter classes to the  

TableModel for invoking the Filter 

Abstract base class for generated TableModelFilter classes 

Provides Filter methods for CHARACTER Buffer Fields 

Provides Filter methods for DATE Buffer Fields 

Provides Filter methods for DATETIME Buffer Fields 

Provides Filter methods for DATETIME-TZ Buffer Fields 

Provides Filter methods for DECIMAL Buffer Fields 

Provides Filter methods for INT64 Buffer Fields 

Provides Filter methods for INTEGER Buffer Fields 

Provides Filter methods for LOGICAL Buffer Fields 

 


You will find all different kinds of operators for filters existing in the filter classes such as EQ, GE, LE, BEGINS and also some more advanced like IsNotUnknownValue. The available operators depend on the data type of the underlying field. 

...

In this short sample we increase the discount for Customer number 10 by 5 percent, each time we run this code.

Code Block
themeEclipse
linenumberstrue
DEFINE VARIABLE oCustomerDatasetModel AS Test.ModelClasses.CustomerDatasetModel NO-UNDO. 

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

oCustomerDatasetModel:TrackingChanges = TRUE. 

oCustomerDatasetModel:Customer:Discount = oCustomerDatasetModel:Customer:Discount + 5. 

oCustomerDatasetModel:SaveChanges().
 


If you want to learn more about how to use Views together with Model classe click here.