01.06.2013 Views

OpenEdge Development: Mobile Applications - Product ...

OpenEdge Development: Mobile Applications - Product ...

OpenEdge Development: Mobile Applications - Product ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Comparing asynchronous and synchronous execution<br />

JSDO overview<br />

Asynchronous execution is mandatory for the methods that execute the built-in <strong>Mobile</strong><br />

CRUD operations. These operations usually involve AppServer access to its data<br />

sources, which are typically <strong>OpenEdge</strong> databases. The <strong>Mobile</strong> read operation<br />

executed by the fill( ) method can involve reading and returning hundreds to<br />

thousands (or more) records in multiple temp-tables of a ProDataSet across the<br />

network. The <strong>Mobile</strong> create, update, and delete operations, which require writes to and<br />

lock management of databases, are executed across the network by the<br />

saveChanges( ) method one record at a time, and for as many records as are marked<br />

as changed in JSDO local storage. This means that completion of these methods can<br />

require detectable wait times. If they were executed synchronously, the <strong>Mobile</strong> App<br />

user would be prevented from doing any work within the app while these methods were<br />

executing. With asynchronous execution, they can perform other tasks, such as setting<br />

application options, while waiting for a list of customers and orders, for example, to be<br />

displayed in a list view, or while waiting for notification that changes they have posted<br />

have been saved in the database.<br />

Asynchronous execution is the default for non-built-in invocation methods, again,<br />

because these operations execute across the network and can involve complex<br />

database interactions on the AppServer. However, it is also possible that an invocation<br />

method might perform a simple function and return a primitive value used in an<br />

expression—for example, an age or credit limit. In this case, you might prefer to<br />

execute the method synchronously in the expression to complete the calculation with<br />

its return value. This you can do by passing false as an additional Boolean parameter<br />

that indicates that the invocation method is to be executed synchronously. For more<br />

information on the execution options for invocation methods, see the “Accessing<br />

non-built-in invoke operations” section on page 115.<br />

Named events for asynchronous execution<br />

For all methods that execute asynchronously, the JSDO supports a set of named<br />

events to which you can subscribe event handler functions, functions that execute with<br />

a signature defined to receive the results of a particular event. The JSDO defines a set<br />

of unique before and after events for each <strong>Mobile</strong> operation and also for the<br />

saveChanges( ) method, itself, because in one call, this method can execute all three<br />

of the create, update, and delete operations for any number of records in JSDO local<br />

storage.<br />

In other words, there is a unique event that fires before a given <strong>Mobile</strong> operation<br />

executes across the network and one that fires after a given <strong>Mobile</strong> operation<br />

executes. In addition, there is one event that fires before the saveChanges( ) method<br />

executes any <strong>Mobile</strong> operations and another that fires after all <strong>Mobile</strong> operations<br />

executed by the saveChanges( ) method have completed. Note that the after events<br />

all fire (including for saveChanges( )) whether <strong>Mobile</strong> operations complete<br />

successfully or with an error.<br />

<strong>OpenEdge</strong> ® <strong>Development</strong>: <strong>Mobile</strong> <strong>Applications</strong> 99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!