Macromedia coldfusion mx 7.0.2-using coldfusion mx with flex 2 Manuel D’Utilisation
50
Using the Flex Data Service Assembler
The
sync
method calls the private methods
doCreate
,
doUpdate
, and
doDelete
. If an error
occurs, the method updates the change object with the failure to inform the Flex application
that the change was not processed. The ChangeObject has two APIs,
that the change was not processed. The ChangeObject has two APIs,
processed()
and
fail()
. The
fail()
API takes an optional string argument, which contains the description
of what went wrong. The
doCreate
,
doUpdate
, and
doDelete
methods appear as follows:
<cffunction name="doCreate" access="private" output="no">
<cfargument name="co" required="yes" hint="The change object.">
<!--- The record to create. --->
<cfset var new = co.getNewVersion()>
<cfset var new = co.getNewVersion()>
<cftry>
<cfset dao = CreateObject("component", "samples.contact.ContactDAO")>
<!--- Create the record; create returns with the identity fields
<!--- Create the record; create returns with the identity fields
set --->
<cfset dao.create(new)>
<!--- Set the new version in to the change object. --->
<cfset co.setNewVersion(new)>
<!--- Mark this change as processed successfully. --->
<cfset co.processed()>
<!--- Set the new version in to the change object. --->
<cfset co.setNewVersion(new)>
<!--- Mark this change as processed successfully. --->
<cfset co.processed()>
<!--- If the SQL failed, mark this change with the error. --->
<cfcatch type="database">
<cfcatch type="database">
<cfset msg = "Error during create: " & cfcatch.queryError &
". SQL was :" & cfcatch.sql>
<cfset co.fail(msg)>
</cfcatch>
<!--- If anything else happened, mark this change with the error. --->
<cfcatch type="any">
<!--- If anything else happened, mark this change with the error. --->
<cfcatch type="any">
<cfset co.fail(cfcatch.message & " " & cfcatch.detail)>
</cfcatch>
</cftry>
<!--- Return the change object. --->
<cfreturn co>
<cfreturn co>
</cffunction>
<cffunction name="doUpdate" access="private" output="no">
<cfargument name="co" required="yes" hint="The change object.">
<!--- The record to update. --->
<cfset var new = co.getNewVersion()>
<cfset var old = co.getPreviousVersion()>
<cfset var new = co.getNewVersion()>
<cfset var old = co.getPreviousVersion()>
<cftry>
<cfset dao = CreateObject("component", "samples.contact.ContactDAO")>
<!--- Update the record. --->
<!--- Update the record. --->