Try OpenEdge Now
skip to main content
Web Services
Creating OpenEdge REST Web Services : Data Object Services : Coding Business Entities to implement Data Objects : Sample Business Entity with before-image support
 
Sample Business Entity with before-image support
Following is a sample ABL Business Entity class (Customer) defined for a Data Object resource that has before-image support (with all annotations removed). This class inherits from OpenEdge-defined abstract class, OpenEdge.BusinessLogic.BusinessEntity, and calls several of its methods to implement the Data Object. It thus uses the following public methods to implement the standard Data Object CRUD and Submit operations on a ProDataSet named dsCustomer:
*CreateCreatedsCustomer( ), which calls CreateData( ) in the super class
*ReadReaddsCustomer( ), which calls ReadData( ) in the super class
*UpdateUpdatedsCustomer( ), which calls UpdateData( ) in the super class
*DeleteDeletedsCustomer( ), which calls DeletedData( ) in the super class
*SubmitSubmitdsCustomer( ), which calls SubmitData( ) in the super class
In this case, the ProDataSet contains a single temp-table, ttCustomer, with a before-table, bttCustomer, that is defined for the Customer table in the sports2000 database. The listing of the data model follows the class.
The class constructor first invokes the super class constructor to pass the handle of the instance ProDataSet to the abstract class, which sets the protected ProDataSet property defined in the class, then passes the required data source handles and skip lists (one each in this case) by setting the protected ProDataSource and SkipList properties that are defined in the abstract class.
Note: For the Data Object Create, Update, Delete, and Submit operations, the input side of the INPUT-OUTPUT DATASET parameter replaces the dsCustomer data left over from any prior operation. Also note that while the client JSDO invokes the Submit operation on all changed records in the JSDO, the JSDO invokes any Create, Update, or Delete operation on only one changed record at a time, similar to when a Data Object resource is defined without before-image support. However, in this case (with before-image support), before-image data is passed by the JSDO and processed for these single-record operations as well.
Table 11. Sample Business Entity class for a Data Object resource with before-image support
USING Progress.Lang.*.
USING OpenEdge.BusinessLogic.BusinessEntity.


BLOCK-LEVEL ON ERROR UNDO, THROW.


CLASS Customer INHERITS BusinessEntity:

{"customer.i"}

DEFINE DATA-SOURCE srcCustomer FOR Customer.

CONSTRUCTOR PUBLIC Customer():

DEFINE VAR hDataSourceArray AS HANDLE NO-UNDO EXTENT 1.
DEFINE VAR cSkipListArray AS CHAR NO-UNDO EXTENT 1.

SUPER(DATASET dsCustomer:HANDLE).

/* Data Source for each table in dataset. Should be in table order
as defined in DataSet. */
hDataSourceArray[1] = DATA-SOURCE srcCustomer:HANDLE.

/* Skip-list entry for each table in dataset. Should be in temp-table order
as defined in DataSet. Each skip-list entry is a comma-separated list of
field names, to be ignored in the ABL CREATE statement. */
cSkipListArray[1] = "CustNum".

THIS-OBJECT:ProDataSource = hDataSourceArray.
THIS-OBJECT:SkipList = cSkipListArray.

END CONSTRUCTOR.


METHOD PUBLIC VOID ReaddsCustomer(INPUT filter AS CHARACTER, OUTPUT DATASET dsCustomer):

SUPER:ReadData(filter).

END METHOD.


METHOD PUBLIC VOID CreatedsCustomer(INPUT-OUTPUT DATASET dsCustomer):

DEFINE VAR hDataSet AS HANDLE NO-UNDO.
hDataSet = DATASET dsCustomer:HANDLE.

SUPER:CreateData(DATASET-HANDLE hDataSet BY-REFERENCE).

END METHOD.


METHOD PUBLIC VOID UpdatedsCustomer(INPUT-OUTPUT DATASET dsCustomer):

DEFINE VAR hDataSet AS HANDLE NO-UNDO.
hDataSet = DATASET dsCustomer:HANDLE.

SUPER:UpdateData(DATASET-HANDLE hDataSet BY-REFERENCE).

END METHOD.


METHOD PUBLIC VOID DeletedsCustomer(INPUT-OUTPUT DATASET dsCustomer):

DEFINE VAR hDataSet AS HANDLE NO-UNDO.
hDataSet = DATASET dsCustomer:HANDLE.

SUPER:DeleteData(DATASET-HANDLE hDataSet BY-REFERENCE).

END METHOD.


METHOD PUBLIC VOID SubmitdsCustomer(INPUT-OUTPUT DATASET dsCustomer):

DEFINE VAR hDataSet AS HANDLE NO-UNDO.
hDataSet = DATASET dsCustomer:HANDLE.

SUPER:SubmitData(DATASET-HANDLE hDataSet BY-REFERENCE).

END METHOD.

END CLASS.
All the public methods call the corresponding super class methods to manage the business logic, such as calling ReadData( ) to parse the filter string passed to the ReaddsCustomer( ) method and then fill dsCustomer with data accordingly.
Note that the inherited BusinessEntity class provides alternative overloadings of the ReadData( ) method that you can call with different options to implement ReaddsCustomer( ) in the Business Entity. For more information, you can obtain a listing of the installed OpenEdge.BusinessLogic.BusinessEntity class from the following ABL source library:
OpenEdge_install_dir\src\OpenEdge.BusinessLogic.pl
Note that the inherited behavior of the public SubmitData( ) method is to process all record changes in the transaction according to the same order defined for a default call to the saveChanges( ) method on the client JSDO without using the Submit operation:
1. Apply all record deletes
2. Apply all record creates
3. Apply all record updates
Also, you can add additional processing for the respective record changes. For example following the call to a super class method, you might replace or modify the value of the ERROR-STRING attribute returned on each changed record buffer based on custom criteria. This attribute value is then available in the client JSDO as the value of the _errorString property in each record object returned with a record change error.
Note: The Customer class listed above is based on the Business Entity generated for an Express Data Object using the Customer table.
Following is the customer.i include file that provides the data model for the Customer class.
Table 12. Data model from customer.i for the Customer class
DEFINE TEMP-TABLE ttCustomer BEFORE-TABLE bttCustomer
FIELD Address AS CHARACTER LABEL "Address"
FIELD Balance AS DECIMAL INITIAL "0" LABEL "Balance"
FIELD City AS CHARACTER LABEL "City"
FIELD CustNum AS INTEGER INITIAL "0" LABEL "Cust Num"
FIELD Name AS CHARACTER LABEL "Name"
FIELD Phone AS CHARACTER LABEL "Phone"
FIELD State AS CHARACTER LABEL "State"
INDEX CustNum CustNum
INDEX Name Name.

DEFINE DATASET dsCustomer FOR ttCustomer.