progress.data.JSDO class
- Last Updated: July 8, 2019
- 12 minute read
- OpenEdge
- Version 13.0
- Documentation
The progress.data.JSDO is a JavaScript
class that provides access to resources (Data Objects) of a Progress Data Object Service. A
single progress.data.JSDO object (JSDO instance) provides
access to a single resource supported by a given Data Object Service. This resource
implements a given Data Object depending on the type of Data Object Service that provides
it. For an OpenEdge Data Object Service, the resource is implemented using an ABL Business
Entity, which is a singleton class or persistent procedure running on an OpenEdge
application server.
Once created for a given Data Object resource, a JSDO provides application-oriented, JavaScript methods that invoke Data Object operations supported by its resource implementation. These can include standard operations for reading and writing data, and can also include custom operations for invoking business logic and more complex data operations, depending on the implementation. An OpenEdge resource maps specified ABL routines to any of several supported operation types, each of which corresponds to a particular method in the JSDO.
For an OpenEdge Data Object Service, you (or another OpenEdge user) identify how a JSDO maps JavaScript methods to operations of a given resource by adding annotations to the singleton procedure or class source code. These annotations map the ABL routines that implement a given resource operation to the corresponding JavaScript method in the JSDO that invokes the operation. You specify these annotations using features of Progress Developer Studio for OpenEdge (Developer Studio) in two ways:
- When initially creating an ABL Business Entity to implement a Data Object that supports the business operations you want on a specified data model
- When modifying any existing ABL singleton class or procedure that you want to function as a Business Entity that implements a Data Object resource
You can also use Developer Studio to add a given resource to an existing OpenEdge Data Object Service, as part of generating the Service along with the client-side artifacts required to create a corresponding JSDO for the resource on the client. These client-side artifacts include the Data Service Catalog that defines the schema and operations for each resource you can access in the Service using a corresponding JSDO.
At run time, the JSDO maintains an internal data store (JSDO memory) for managing table records that are exchanged between a given Data Object resource and the JSDO, and it provides methods to read and write data in JSDO memory as individual JavaScript record objects (see the progress.data.JSRecord class description). To support this data exchange between a JSDO and its Data Object resource, a given resource can support standard operation types that include Create, Read, Update, Delete (CRUD) operations, and Submit operations. The Read operation of a resource returns a specified result set from the resource to the client; the CUD operations create, update, or delete (respectively) one record at a time in the resource; and a Submit operation creates, updates, and deletes multiple records at a time in the resource. In addition to these standard operations, a resource can also support custom Invoke operations to access ABL business logic in a given OpenEdge resource.
The standard CRUD operations can operate on any OpenEdge single-table resource, or on an OpenEdge multi-table resource (ProDataSet) containing one or more temp-tables. Standard Submit operations are currently available only on an OpenEdge ProDataSet resource that supports before-imaging (with potentially complex server transaction support).
Each standard Data Object operation type (CRUD or Submit) maps to a corresponding standard method of the JSDO on the client. The records of each resource table are managed in the JSDO as an array of record objects, which the standard JSDO methods use to exchange data with the server as supported by the type of Data Object Service. The standard JSDO methods mapped to standard operation types support client access to the common business operations that can be generated for an OpenEdge Business Entity. Other standard methods of the JSDO provide internal access to individual record objects in JSDO memory. Depending on the results of its standard methods, the JSDO also maintains a working record for each table in its memory that you can access directly using table and field references (see the notes in this class description). Thus, using the standard methods of a JSDO and its table references, you can interact with a corresponding Data Object resource in a consistent manner from one JSDO-resource mapping to another.
fill( ) to Read resource data and saveChanges( ) to either Create, Update, or Delete individual
records in the resource, or Submit to create, update, and delete multiple records in the
resource. Both of these JSDO methods execute asynchronously. Any results, including errors,
that are returned from both the resource operations and the JSDO method invocations
themselves can be managed using two mechanisms:- Named events — To which you can subscribe
event handlers (callback functions) to process the results when a given event is fired.
The available events fire both before and after each resource operation executes, and
both before and after execution of the JSDO method that invokes the operation, or
operations. The callback for each event has a particular signature that is appropriate
for the results returned for the event. See the descriptions of both the JSDO
fill( )andsaveChanges( )methods and the associated event descriptions for more information. - jQuery Promises — Deferred Promise objects,
an instance of which can be returned as the method value when results are available. A
Promise object provides methods that you can use to register callback functions that, in
turn, execute for different conditions associated with the JSDO method results. In order
to use jQuery Promises, your development environment must support them (or the exact
equivalent). For more information on this mechanism, and how it works with the
fill( )andsaveChanges( )methods, see the notes for this class description.
If your environment supports jQuery Promises, you can use either or both of these mechanisms to return results for the standard resource operations.
Like the standard CRUD and Submit operations, a resource can define custom Invoke operations, depending on the type of resource. For OpenEdge resources, an Invoke operation can call and return results for any ABL routine on the server that is defined by the resource. To call an Invoke operation for a specific ABL routine, an OpenEdge resource defines a corresponding invocation method that you can call on the JSDO to send the request the server.
Note that data exchanged between server and client using Invoke operations
is not automatically stored in JSDO memory. It is initially accessible only from the return
values and other results of the invocation methods provided by the JSDO. You can
subsequently use other standard JSDO methods to exchange data between the invocation methods
and JSDO memory. For example, you can use the JSDO addRecords( ) method to merge appropriate data returned by an invocation method
directly into JSDO memory. The result in JSDO memory can then continue to be maintained and
synchronized with the server using the JSDO fill( ) and
saveChanges( ) methods to invoke the standard CRUD and
Submit operations.
Unlike the standard fill( ) and saveChanges( ) methods, you can execute custom JSDO invocation
methods either synchronously or asynchronously, depending on parameter settings that you use
to call them. If you execute an invocation method asynchronously, the JSDO also supports
events that fire before and after the method (and its Invoke operation) execute in the
resource, returning the results in any event handler callbacks that you subscribe to these
events. In addition, you can use the standard JSDO invoke( ) method as an API to asynchronously call custom invocation methods that
return their results in jQuery Promise callbacks, similar to the fill( ) and saveChanges( ) methods, as long as
your environment supports jQuery Promises.
Note that all JSDO methods that invoke either standard or custom resource operations return a request object to any subscribed event callbacks. This request object supports a number of properties containing the results of the resource operation, some of which appear in the request object only for specific events. Similarly, any Promise object returned by a JSDO method also returns an appropriate request object to each callback that you register for that object. For custom invocation methods that you execute synchronously, this request object is returned as the value of the invocation method. For more information on this request object, see the request object description.
When you instantiate a JSDO, it relies on a prior JSDO login session that
you can establish using an instance of either the progress.data.JSDOSession class or the progress.data.Session class. This login session enables optionally secure
communications between the client JSDO and the web server, its supported Data Object
Services, and ultimately the application server that implements the resource accessed by the
JSDO.
A JSDOSession insatnce manages its JSDO
login session asynchronously using only jQuery Promises to return all session-related
results, where as a Session instance can manage its JSDO
login session either synchronously or asynchronously using several Session object events. Note that, similar to managing resource operations using
jQuery Promises returned from JSDO methods, you can use the JSDOSession class to manage JSDO login sessions only if your environment
supports jQuery Promises. Otherwise, you must use the Session class to manage the login session for a JSDO. For more information, see
the progress.data.JSDOSession class description.
Constructors
Two constructors are available for the JSDO. The first constructor takes the name of the corresponding Data Object resource as a parameter; the second constructor takes an initialization object as a parameter.
The resource name specified for the constructor must match the name of a resource provided by a Data Object Service for which a login session has already been established. After the JSDO is created, it uses the information stored in the Data Service Catalog to communicate with the specified resource.
Syntax
|
- resource-name
- A
stringexpression set to the name of a resource that the JSDO will access. This resource must be provided by a Data Object Service for which a login session has already been established. - init-object
- An object that can contain any writable JSDO properties. It must
contain the required JSDO
nameproperty, which specifies the Data Object resource that the JSDO will access. This resource must be provided by a Data Object Service for which a login session has already been established.
Example
The following example illustrates the use of an initialization object to instantiate a JSDO:
|
Properties
| Member | Brief description (See also the reference entry) |
|---|---|
| autoApplyChanges property | A |
| autoSort property | A |
| caseSensitive property | A |
| name property (JSDO class) | Returns the name of the Data Object resource for which the current JSDO was created. |
| record property | A property on a JSDO table reference that references a |
| table reference property (JSDO class) | An object reference property on a JSDO that has the name of a corresponding table in the Data Object resource for which the current JSDO was created. |
| useRelationships property | A |
Methods
Certain methods of the progress.data.JSDO class are called on the JSDO object itself, without regard to
a table reference, whether that reference is explicit (specified in the method signature) or
implicit (in the case of a JSDO containing only one table that is not explicitly specified).
Other methods can be called on a specific table reference that is mapped to one of possibly
multiple tables managed by the resource for which the current JSDO is created.
| Member | Brief description (See also the reference entry) |
|---|---|
| acceptChanges( ) method | Accepts changes to the data in JSDO memory for the specified table reference or for all table references of the specified JSDO. |
| acceptRowChanges( ) method | Accepts changes to the data in JSDO memory for a specified record object. |
| addLocalRecords( ) method |
Reads the record objects stored in the specified local storage area and updates JSDO memory based on these record objects, including any pending changes and before-image data, if they exist. |
| addRecords( ) method | Updates JSDO memory with one or more record objects read from an array, single-table, or multi-table resource that are passed in an object parameter, including any pending changes and before-image data, if they exist. |
| deleteLocal( ) method | Clears out all data and changes stored in a specified local storage area, and removes the cleared storage area. |
| fill( ) method Alias:
|
Initializes JSDO memory with record objects from the data records in a single-table resource, or in one or more tables of a multi-table resource, as returned by the Read operation of the Data Object resource for which the JSDO is created. |
| getProperties( ) method |
Returns an object containing the names and values of the user-defined properties defined in the current JSDO instance. |
| getProperty( ) method |
Returns the value of the specified JSDO user-defined property. |
| hasData( ) method | Returns |
| hasChanges( ) method | Returns |
| invocation method | A custom method on the JSDO that executes an Invoke operation defined for a Data Object resource. |
| invoke( ) method |
Asynchronously calls a custom invocation method on the JSDO to execute an Invoke operation defined by a Data Object resource. |
| readLocal( ) method | Clears out the data in JSDO memory and replaces it with all the data stored in a specified local storage area, including any pending changes and before-image data, if they exist. |
| rejectChanges( ) method | Rejects changes to the data in JSDO memory for the specified table reference or for all table references of the specified JSDO. |
| rejectRowChanges( ) method | Rejects changes to the data in JSDO memory for a specified record object. |
| saveChanges( ) method | Synchronizes to the server all record changes
(creates, updates, and deletes) pending in JSDO memory for the current Data Object
resource since the last call to the |
| saveLocal( ) method | Saves JSDO memory to a specified local storage area, including pending changes and any before-image data, according to a specified data mode. |
| setProperties( ) method |
Replaces all user-defined properties in the current JSDO instance with the user-defined properties defined in the specified object. |
| setProperty( ) method |
Sets the value of the specified JSDO user-defined property. |
| subscribe( ) method (JSDO class) | Subscribes a given event callback function to a named event of the current JSDO or table reference. |
| unsubscribe( ) method (JSDO class) | Unsubscribes a given event callback function from a named event of the current JSDO or table reference. |
| unsubscribeAll( ) method |
Unsubscribes all event callback functions from a
single named event of the current JSDO, |
| Member | Brief description (See also the reference entry) |
|---|---|
| acceptChanges( ) method | Accepts changes to the data in JSDO memory for the specified table reference or for all table references of the specified JSDO. |
| acceptRowChanges( ) method | Accepts changes to the data in JSDO memory for a specified record object. |
| add( ) method Alias:
|
Creates a new record object for a table referenced in JSDO memory and returns a reference to the new record. |
| addRecords( ) method | Updates JSDO memory with one or more record objects read from an array, single-table, or multi-table resource that are passed in an object parameter, including any pending changes and before-image data, if they exist. |
| assign( ) method (JSDO class) Alias:
|
Updates field values for the specified |
| find( ) method | Searches for a record in a table referenced in JSDO memory and returns a reference to
that record if found. If no record is found, it returns |
| findById( ) method | Locates and returns the record in JSDO memory with the internal ID you specify. |
| foreach( ) method | Loops through the records of a table referenced in JSDO memory and invokes a user-defined callback function as a parameter on each iteration. |
| getData( ) method | Returns an array of record objects for a table referenced in JSDO memory. |
| getErrors( ) method |
Returns an array of errors from the most recent
invocation of Create, Read, Update, Delete, or Submit operations (CRUD or Submit) that
you have invoked by calling the JSDO |
| getErrorString( ) method | Returns any before-image error string in the data of a record object referenced in JSDO memory that was set as the result of a resource Create, Update, Delete, or Submit operation. |
| getId( ) method | Returns the unique internal ID for the record object referenced in JSDO memory. |
| getSchema( ) method | Returns an array of objects, one for each field that defines the schema of a table referenced in JSDO memory. |
| hasData( ) method |
Returns |
| rejectChanges( ) method | Rejects changes to the data in JSDO memory for the specified table reference or for all table references of the specified JSDO. |
| rejectRowChanges( ) method | Rejects changes to the data in JSDO memory for a specified record object. |
| remove( ) method | Deletes the specified table record referenced in JSDO memory. |
| setSortFields( ) method | Specifies or clears the record fields on which to automatically sort the record objects for
a table reference after you have set its |
| setSortFn( ) method | Specifies or clears a user-defined sort function with which to automatically sort the
record objects for a table reference after you have set its |
| sort( ) method | Sorts the existing record objects for a table reference in JSDO memory using either specified sort fields or a specified user-defined sort function. |
| subscribe( ) method (JSDO class) | Subscribes a given event callback function to a named event of the current JSDO or table reference. |
| unsubscribe( ) method (JSDO class) | Unsubscribes a given event callback function from a named event of the current JSDO or table reference. |
Events
| Member | Brief description (See also the reference entry) |
|---|---|
| afterCreate event | Fires after the JSDO, by means of a |
| afterDelete event | Fires after the JSDO, by means of a |
| afterFill event Alias:
|
Fires on the JSDO after a call to the |
| afterInvoke event | Fires after a custom invocation method is called asynchronously on a JSDO and a response to the Invoke operation request is received from the server. |
| afterSaveChanges event | Fires once for each call to the |
| afterUpdate event | Fires after the JSDO, by means of a |
| beforeCreate event | Fires before the JSDO, by means of a |
| beforeDelete event | Fires before the JSDO, by means of a |
| beforeFill event Alias:
|
Fires on the JSDO before a call to the |
| beforeInvoke event | Fires when a custom invocation method is called asynchronously on a JSDO before the request for the Invoke operation is sent to the server. |
| beforeSaveChanges event | Fires once on the JSDO before a call to the
|
| beforeUpdate event | Fires before the JSDO, by means of a |
The JSDO can subscribe to the events listed in the previous table in either of two ways:
- Using the JSDO constructor — In the init-object parameter of the constructor, list each subscribed event with an optional scope object and an event handler method to be executed when the event fires. See the constructors description for this class.
- Using the
subscribe( )method — See the subscribe( ) method (JSDO class).
Example
The following code fragment shows a simple JavaScript coding sequence for
creating and using a JSDO referenced by the variable dsCustomer to read resource data, starting with the attempted JSDO login using a
progress.data.JSDOSession instance:
|
Notes
- Three web-communicating methods of this class,
fill( ),saveChanges( ), andinvoke( ), always execute asynchronously and return a reference to a jQuery Promise object as the return value when jQuery Promises are supported in the development environment. A Promise is a deferred object that defines methods which, in turn, register callbacks that execute when results are available from the method that returns the Promise. You provide your own code in each callback to handle the results returned for a given Promise method, much like the code you provide in an event callback.The primary Promise methods for use with a JSDO object include
done( ),fail( ), andalways( ), which allow you to separately handle the successful, unsuccessful, and all results (respectively) of a JSDO method execution. Note that for any given JSDO method, the parameter lists for all Promise method callbacks have the same signature. Note also that the callback for thealways( )method executes with the same values in its parameter list as the callback for thedone( )orfail( )method, whichever one executes with results.For more information on the jQuery implementation of Promises and the additional Promise methods that are available to register callbacks, see the following jQuery topics at the specified web locations:
- Category: Deferred Object — http://api.jquery.com/category/deferred-object/
- Promise Object — http://api.jquery.com/Types/#Promise
- .promise — http://api.jquery.com/promise/
- For more information on defining a Data Object resource, including the
standard CRUD, Submit, and any custom Invoke operations, for:
- OpenEdge Data Object Services — See the topics on creating Business Entities to implement Data Object resources and updating Business Entities for access by mobile and web apps built using Kendo UI in OpenEdge Development: Web Services.
- The JSDO supports a working record for each table
referenced in JSDO memory. Certain JSDO methods set a specific record as the working
record. After other methods execute, there is either no working record set or existing
working records remain unchanged. When there is a working record, you can access the
fields of the record using one of the following mechanisms:
Syntax
jsdo-ref.table-ref.field-ref jsdo-ref.field-ref jsdo-ref.record.data.field-ref // Read-only; // For a jsdo-ref with only one table-ref jsdo-ref.table-ref.record.data.field-ref // Read-only jsrecord-ref.data.field-ref // Read-only- jsdo-ref
- The reference to a JSDO, and if the JSDO contains only a single table, an implied reference to any working record that is set for that table.
- table-ref
- A table reference property with the name of a table in jsdo-ref memory and a reference to the table working record. There is one table reference in a JSDO for each table referenced by the JSDO. For more information on table reference properties, see the table reference property (JSDO class) description.
- field-ref
- A field reference property on a table-ref or on the
dataproperty object, with the name and value of a field in the working record of the referenced table. There is one such field reference anddataobject property for each field defined in the table schema. If field-ref is an array field, which is supported in OpenEdge resource tables for example, you can also access individual array elements using either standard JavaScript subscripts or JSDO array-element references in the form,field-ref_integer, where integer is a one (1)-based integer that qualifies the name of the field reference property that corresponds to the array field element. For more information on field reference properties, see the table reference property (JSDO class) description. - record
- A property of type
JSRecordon a table reference, which references the working record of a referenced table specified by:- jsdo-ref.table-ref
- jsdo-ref if the JSDO references only one table
If the JSDO references more than one table, the
recordproperty isnullat the JSDO level and is available only on a table-ref. - data
- A property on a
JSRecordobject with the field values for the working record specified by:- jsdo-ref.table-ref
- jsdo-ref if the JSDO references only one table
- A jsrecord-ref returned for an associated JSDO table reference
Note: If a field-ref has the same name as a built-in property or method of the JSDO, you must use thedataproperty to reference its value in the working record.CAUTION: Never write directly to a field-ref using thisdataproperty; in this case, use field-ref only to read the data. Writing field values using thedataproperty does not mark the record for update when calling thesaveChanges( )method, nor does it re-sort the record in JSDO memory according to any order you have established using theautoSortproperty. To mark a record for update and automatically re-sort the record according to theautoSortproperty, you must assign a field value either by setting a jsdo-ref.table-ref.field-ref for a working record or by calling theassign( )method on a valid table-ref orJSRecordobject reference. - jsrecord-ref
- A reference to a
JSRecordobject for a table referenced in JSDO memory. You can return a jsrecord-ref for a working record as the value of therecordproperty or as a value returned by supported JSDO built-in methods that return a working record, such asadd( )andfind( ).
For more information on properties available to reference working record fields using this syntax, see the properties listed in this class description and in the description of the progress.data.JSRecord class. For more information on the methods for setting the working record for referenced tables, see the methods listed in this class description and in the description of the progress.data.JSRecord class.
- Many standard JSDO methods are actually invoked on a JSDO table reference, and can only be invoked on the JSDO itself when its JSDO memory is initialized with a single table.
- For a multi-table resource, such as an OpenEdge ProDataSet, the JSDO
accesses the data for all unrelated tables in JSDO memory as top-level tables of the JSDO.
Access to data for all related child tables depends on the working record of the parent
table in the JSDO and the setting of the
useRelationshipsproperty.
See also
progress.data.JSRecord class, record property, table reference property (JSDO class)