Sample Read operation updated to handle JFP input and server paging
- Last Updated: March 30, 2020
- 4 minute read
- OpenEdge
- Version 12.2
- Documentation
Following is a sample Business Entity showing the method generated to implement the Data Object Read operation, with manual annotation and code changes required both to implement a JSDO for access by the Kendo UI DataSource and to implement a Rollbase external object.
This is the include file (customer.i) that is referenced by the Business Entity, including a
ProDataSet (dsCustomer) that contains a single
temp-table (ttCustomer), with fields that you add to
the fields that correspond to the existing database table fields indicated in bold, and
an additional index you must also add shown in bold:
|
The id field is added to each
temp-table record to support Rollbase external objects.
The seq field is used to guarantee the
order of records in the serialized temp-table that is returned as JSON to the JSDO. To
work properly, this field must be initialized with the Unknown value (?). You must also add an index on seq that is both PRIMARY and UNIQUE. You can also have additional indexes, which can be
the same or different than those in the database, as shown for CustNum, but the index on seq
must be the PRIMARY one.
Following is the class file for the Business Entity, Customer.cls. Manually added annotations and code are in
bold, except in the case of added methods, where only the first
and last lines of the method are in bold:
|
Key changes to note in Customer.cls
include the following:
- Added statement:
USING Progress.Json.ObjectModel.*.— Supports access to the ABL core classes for parsing the JSON Filter Pattern object returned in thefilterparameter of theReadCustomer( )method. - Added
@openapi.openedge.method.propertyannotations:(name="mappingType", value="JFP")and(name="capabilities", value="ablFilter,top,skip,id,orderBy")— Causes the JSDO created from this Business Entity to intercept the value the Kendo UI DataSource passes to thefilterparameter ofReadCustomer( )and convert it to a JSON Filter Pattern object. Without this annotation, the DataSource passes a value to thefilterparameter that is a JSON duplicate of the Kendo UI-proprietary settings most recently provided by thefilterconfiguration property or thefilter( )method on the DataSource. - Updated statement in the
ReadCustomer( )method:IF filter BEGINS "~{" THEN ... ELSE ...— If thefilterparameter value starts with a left brace, invokes an added method (JFPFillMethod( )) to handle an anticipated JSON Filter Pattern; otherwise, theBATCH-SIZEattribute on the buffer handle forttCustomeris set to return all records in the result set, theAddIdField( )method is registered as a callback for theAFTER-ROW-FILLevent ondsCustomerto initialize theidandseqfields of each record in the result set, and thefilterparameter is passed to theReadData( )method of the inheritedOpenEdge.BusinessLogic.BusinessEntityabstract class to handle anotherfilterstring format specified when not using Kendo UI to access the Read operation. (Note thatJFPFillMethod( )also sets different values forBATCH-SIZEbased on thefiltersettings before registeringAddIdField( ).) - Added method:
JFPFillMethod( )— Parses the property values from the JSON Filter Pattern passed to thefilterparameter, assigning any that are found to corresponding ABL variables. Any of these variables that contain appropriate values are then used to implement the filtering, sorting, and paging options that are specified. These values determine theBATCH-SIZEto return in thettCustomertemp-table for a successful result. Thus, a successful result returns either a single record identified byid, a specified page of records (iMaxRows > 0), or the entire result set of records in thettCustomertemp-table of theDATASET dsCustomerparameter passed as output from theReadCustomer( )method. The record, or set of records, returned represent the result from the specified filtering, sorting, and paging options, if any. Note that an ABL query is used for some options, while theFILL( )method ondsCustomeris used for others to copyCustomerdata tottCustomerand update the correspondingidandseqfields. - Added callback method:
AddIdField( )— With this callback registered by eitherReadCustomer( )orJFPFillMethod( )in response to theAFTER-ROW-FILLevent ondsCustomer, this method assigns the current sequence number (seq) andROWIDvalue (id) of the corresponding database record whoseCustomerfields have just been copied (usingFILL( )) into the corresponding fields of the currentttCustomerrecord. - Added method:
MyCount( ), added as a Data Object Count operation to return the total number of records in the server result set — Executed as part of returning a server page to the Kendo UI DataSource, this method identifies anyWHEREstring in thefilterparameter and adds it to aPRESELECTquery on the target database table that it constructs and opens. (Note that it sets the string returned byfilterto""if its value is otherwise unspecified and set to the Unknown value (?).) It then passes the value of theNUM-RESULTSattribute on the opened query to its output parameter to provide the total number of records to Kendo UI.Note: If you do not add a method like this to the Business Entity and annotate it (in Developer Studio) as a Count operation, the JSDO throws an exception when the Kendo UI DataSource tries to reference the method as part of reading a server page.