The get method retrieves a specific record. The get method calls the lower level read method. If you use the Bean/DAO methodology, as described in Writing the ColdFusion CFCs, you create the lower level read method separately in the DAO CFC.
The following examples shows the essential elements of a get method:
<cffunction name="get" output="no" returnType="samples.contact.Contact" access="remote"> <cfargument name="uid" type="struct" required="yes"> <cfset key = uid.contactId> <cfset ret=variables.dao.read(id=key)> <cfreturn ret[1]> </cffunction>
The returntype of a get method can be any of the following:
The sync method lets you keep track of synchronization conflicts by accepting a change list, which is an array of change objects. In the sync method, you pass in an array of changes, loop over the array and apply the changes, and then return the change objects, 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, which indicate success or failure. ---> <cfreturn newchanges> </cffunction>
The count method returns a number that indicates how many records are in a result set. If you use the Bean/DAO methodology, as described in Writing the ColdFusion CFCs, you create the lower level count method separately in the DAO CFC.
The count method contains the following essential elements, without any error handling:
<cffunction name="count" output="no" returntype="Numeric" access="remote"> <cfargument name="param" type="string" required="no"> <cfreturn variables.dao.count()> </cffunction>
This count method calls a different count method in the DAO CFC, which contains the following essential elements, without any error handling:
<cffunction name="count" output="false" access="public" returntype="Numeric"> <cfargument name="id" required="false"> <cfargument name="param" required="false"> <cfset var qRead=""> <cfquery name="qRead" datasource="FDSCFCONTACT"> select COUNT(*) as totalRecords from Contact </cfquery> <cfreturn qRead.totalRecords> </cffunction>