Detailed instructions for use are in the User's Guide.
[. . . ] Developing Applications
ADOBE COLDFUSION 9
® ®
© 2009 Adobe Systems Incorporated. All rights reserved.
Copyright
Developing Adobe® ColdFusion® 9 Applications This guide is licensed for use under the terms of the Creative Commons Attribution Non-Commercial 3. 0 License. This License allows users to copy, distribute, and transmit the guide for noncommercial purposes only so long as (1) proper attribution to Adobe is given as the owner of the guide; and (2) any reuse or distribution of the guide contains a notice that use of the guide is governed by these terms. To view a copy of this license, visit http://creativecommons. org/licenses/by-nc-sa/3. 0/ Adobe, the Adobe logo, ColdFusion, and Flash are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. [. . . ] sessiontoken. addResponder(new mx. rpc. Responder(connectSuccess, connectFault)); }
Fetching data from the server
Use the SyncManager fetch method to fetch data from the ColdFusion server by calling the fetch method of the server data object. The syncManager. fetch method takes the name of the CFC fetch method (typically fetch) as its first parameter, followed by any CFC fetch method parameters. The syncManager. fetch method returns an AsyncToken object that provides access to the data. Therefore, call the token's addResponder method to specify a responder that handles the responses for successful and failed fetches. To fetch the initial data from the server, you can include the following code in the Application init() method.
// fetch the data. var token:AsyncToken = syncmanager. fetch("fetch"); //Specify the responder to handle the fetch results. token. addResponder(new mx. rpc. Responder(fetchSuccess, fetchFault));
Managing the local database
You use a Session object to manage the data in the local SQLite database. You call the syncmanager. openSession method to create a session with a specific database file. The method returns a SessionToken token, and the SessionToken. session property provides access to the session. You use code in the token's openSessionSuccess responder event handler to provide access to the session object. This way, you do not access the session, and therefore the database, until it is successfully opened.
Last updated 8/5/2010
DEVELOPING COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
634
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 ActionScript 3. 0 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 OpenSession method,
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. [. . . ] 6 (Optional) Select the Primary Key column if a primary key is not defined in the database. 7 (Optional) To specify the primary key column in addition to the other values specified in the CFC, select the
Primary Key is Controlled by the User option. If the primary key is automatically generated by the database (the identity field), do not select this option.
8 To replace existing files, select the Overwrite Files If They Already Exist option. 9 Select one of the following CFC Types:
· Active Record CFC
Last updated 8/5/2010
DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
1343
· Bean CFC & DAO CFC · Flex Data Service Assembler CFCs
10 Enter the names of the CFCs in the appropriate text boxes. [. . . ]