Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 639

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
The following code expands on the session initialization code that was shown above. and shows an openSessionSuccess
event handler that uses the session to save the contents of the remote database in the local image. In this example, users
is the array collection fetched from server:
var dbFile:File = File.userDirectory.resolvePath("basic.db");
var token:SessionToken = syncmanager.openSession(dbFile, 113);
token.addResponder(new mx.rpc.Responder(openSessionSuccess, openSessionFault));
function openSessionSuccess(event:SessionResultEvent):void
{
//Initialize a variable for access to the session.
var session:Session = event.sessionToken.session;
//Save the remote database data in the local database.
//users is the array collection fetched from server
var saveToken:SessionToken = session.saveCache(users);
//Add responder event handlers for successful and failed saves.
saveToken.addResponder(new mx.rpc.Responder(saveSuccess, saveFault));
}
Once you have access to the session, you can get (load) data from the SQLite database, and insert, delete, and update
data database by calling the session objects methods. For details on the session object methods, see
Reference. Alternatively, you can see the standalone Adobe ColdFusion ActionScript Language Reference, which is
accessible through the Documentation link on the Resources page of the ColdFusion Administrator.
Notes:
• The SQLite database doesn't validate column types when it creates a table. If you give it an invalid value for column
data type, it creates the column with that type.
• When you pass a unique integer ID parameter (one that is not used in the application) to the
the method creates an intermediate database file, which tracks the client changes to be committed on the server. If
you use more than one database in a single application, use a unique ID for each database. Using a single ID ensures
that you use the correct database for each client-side transaction.
• For asynchronous calls (such as SaveCache) that save fetched data in the local database, the call result can be
available by using the session token when the call returns, before the responders are added. This situation occurs if
the SaveCache operation tries to save null data. That is, if the fetch operation returned null data. In such cases, a
responder is not required.
There are two ways to handle this situation:
Check whether the result property of the session token returned by the function is null:
1
if (token.result == null) {
Add the responder here
}
else {
Directly use the token.result
}
Check that the ArrayCollection that is input to the SaveCache function is not null. The null response indicates
2
that the fetch operation did not get a result from the server:
If (ArrayCollection != null) {
Call SaveCache() function
Add Responder to the SaveCache Token
}
else {
Handle the condition here.
}
Last updated 1/20/2012
634
ActionScript 3.0
method,
OpenSession

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents