Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 641

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
: An array of data that was in the client database before the change. There is no conflict in the
originalobjects
following circumstances:
• If your are updating a record and the data on the server is same as the data in the originalobject. The client before
the change had the same data as the server. In this case, the server updates its data source. If the old client data
differs from that on the server, the application must handle the conflict.
• If you are inserting a new record. In this case, there is no originalobject value and ColdFusion can insert the record
in the data store.
You use the ColdFusion ObjectEquals function to identify conflicts. Pass the function the new instance of cfc from the
client and the original instance to check if they are equal. If they are equal, the client has been working with the latest
data. If it is not, the server can raise a conflict by returning the sever version of the instance present on the server from
the sync method by creating an instance of
property) to the server value of the data, and returning the array of conflict objects to the AIR client.
The following code is an ideal example of sync method that uses ORM methods for syncing operations and also
handles conflicts.
<cffunction name="sync" returntype="any">
<cfargument name="operations" type="array" required="true">
<cfargument name="clientobjects" type="array" required="true">
<cfargument name="originalobjects" type="array" required="false">
<cfset conclits = ArrayNew(1)>
<cfset conflictcount = 1>
<cfloop index="i" from="1" to="#ArrayLen( operations )#">
<cfset operation = operations[i]>
<cfset clientobject = clientobjects[i]>
<cfset originalobject = originalobjects[i]>
<cfif operation eq "INSERT">
<cfset obj = ORMGetSession().merge(clientobject)>
<cfset EntitySave(obj)>
<cfelseif listfindnocase("UPDATE,DELETE",operation) neq 0>
<cfset serverobject = EntityLoadByPK("employee",originalobject.getId())>
<cfif not isdefined('serverobject') >
<cflog text="CONFLICT::SERVER OBJECT NOT FOUND, RECORD MAY BE DELETED ALREADY">
<cfset conflict = CreateObject("component","CFIDE.AIR.conflict")>
<cfset conflict.clientobject = clientobject>
<cfset conflict.originalobject = originalobject>
<cfset conflict.operation = operation>
<cfset conflicts[conflictcount++] = conflict>
<cfcontinue>
</cfif>
<cfset isNotConflict = ObjectEquals(originalobject, serverobject)>
<cfif isNotConflict>
<cfif operation eq "UPDATE">
CFIDE.AIR.conflict.cfc
<cfset obj = ORMGetSession().merge(clientobject)>
<cfset EntitySave(obj)>
Last updated 1/20/2012
, setting its
property (its only
serverobject
636

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents