Example application
49
<cfif structKeyExists(arguments, "param")>
<cfreturn dao.read(param=arguments.param)>
<cfelse>
<cfreturn dao.read()>
</cfif>
<!--- If the SQL failed, mark this change with the error. --->
<cfcatch type="database">
<cfset msg = "Error during fill: " & cfcatch.queryError &
". SQL was :" & cfcatch.sql>
</cfcatch>
<!--- If anything else happened, mark this change with --->
<!--- the error. --->
<cfcatch type="any">
<!--- <cfset co.fail(cfcatch.message & " " & cfcatch.detail)> --->
</cfcatch>
</cftry>
</cffunction>
Creating the sync method
The
sync
method has a specific signature. The
sync
method accepts an array as its argument
and have a return value of an array. The arrray that the sync method accepts contains Java
ChangeObjects, which Flex creates and documents. The
sync
method appears as follows:
<cffunction name="sync" output="no" returnType="array" access="remote">
<cfargument name="changes" type="array" required="yes">
<!-- Create the array for the returned changes. -->
<cfset var newchanges=ArrayNew(1)>
<!-- Loop over the changes and apply them. --->
<cfloop from="1" to="#ArrayLen(changes)#" index="i" >
<cfset co = changes[i]>
<cfif co.isCreate()>
<cfset x = doCreate(co)>
<cfelseif co.isUpdate()>
<cfset x = doUpdate(co)>
<cfelseif co.isDelete()>
<cfset x = doDelete(co)>
</cfif>
<cfset ArrayAppend(newchanges, x)>
</cfloop>
<!-- Return the change objects, as this is how success or failure
is indicated. --->
<cfreturn newchanges>
</cffunction>