Server-side code

Create the following cfc files - Application.cfc, Customer.cfc, Address.cfc, and Cusmanager.cfc with code like the following. The AIR client interacts with the Cusmanager.cfc file, in which you specify the code to fetch and sync the data back to the server.

Application.cfc

<cfcomponent> 
        <cfset this.name = "OneTonOneExample"> 
        <cfset this.datasource="testorm"> 
        <cfset this.ormenabled="true"> 
        <cfset this.ormsettings={dialect = "MicrosoftSQLServer"}> 
</cfcomponent>

Customer.cfc

<cfcomponent persistent="true"> 
        <cfproperty name="cid" fieldtype="id" > 
        <cfproperty name="name" > 
        <cfproperty name="address" fieldType='one-to-one' 
        CFC="address" fkcolumn='aid' cascade='all' > 
</cfcomponent>

Address.cfc

<cfcomponent persistent="true"> 
        <cfproperty name="aid" fieldtype="id" > 
        <cfproperty name="street" > 
</cfcomponent>

Cusmanager.cfc

<cfcomponent implements="CFIDE.AIR.ISyncManager"> 
<!----Fetch method---> 
<cffunction name="fetch" returnType="Array" access="remote"> 
<cfset cus = ArrayNew(1)> 
<cfset cus = EntityLoad("customer")> 
<cfreturn cus> 
</cffunction> 
<!----SYNC method---> 
<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.getcid())> 
        <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"> 
                          <cfset obj = ORMGetSession().merge(clientobject)> 
                          <cfset EntitySave(obj)>           
                    <cfelseif operation eq "DELETE"> 
                          <cfset obj = ORMGetSession().merge(originalobject)> 
                          <cfset EntityDelete(obj)> 
                    </cfif> 
                         
            <cfelse><!----Conflict---> 
                    <cflog text = "is a conflict"> 
                    <cfset conflict = CreateObject("component","CFIDE.AIR.conflict")> 
                    <cfset conflict.serverobject = serverobject> 
                    <cfset conflict.clientobject = clientobject> 
                    <cfset conflict.originalobject = originalobject> 
                    <cfset conflict.operation = operation> 
                    <cfset conflicts[conflictcount++] = conflict> 
                    <cfcontinue> 
            </cfif> 
    </cfif> 
        </cfloop> 
<cfif conflictcount gt 1> 
<cfreturn conflicts> 
</cfif> 
</cffunction> 
</cfcomponent>