Flash Builder tools allow you to implement data management
functionality for remote services. Data management is the synchronization
of updates to data on a server from the client application.
Flash Builder requires a combination of specific function signatures
to implement data management. The following code example provides
an example of one way to implement a ColdFusion service for data
management.
The following EmployeeServiceDM example is based on the code
generated by Flash Builder when accessing a database table. See Generating a sample ColdFusion service from a database table.
Important: Example services are for prototyping only.
Use the example service only in a trusted development environment.
Before deploying this service, be sure to increase security and
restrict access appropriately. For information on writing secure ColdFusion
services, see the ColdFusion documentation
About
User Security.
<cfcomponent output="false">
<!---
This sample service contains functions that illustrate typical service operations.
This code is for prototyping only.
Authenticate the user prior to allowing them to call these methods. You can find more
information at http://www.adobe.com/go/cf9_usersecurity
--->
<cffunction name="getAllemployees" output="false" access="remote" returntype="any" >
<!--- Auto-generated method
Retrieve set of records and return them as a query or array.
Add authorization or any logical checks for secure access to your data --->
<cfset var qAllItems="">
<cfquery name="qAllItems" datasource="employees">
SELECT * FROM employees
</cfquery>
<cfreturn qAllItems>
</cffunction>
<cffunction name="getemployees" output="false" access="remote" returntype="any" >
<cfargument name="emp_no" type = "numeric" required="true" />
<!---
Retrieve a single record and return it as a query or array.
Add authorization or any logical checks for secure access to your data --->
<cfset var qItem="">
<cfquery name="qItem" datasource="employees">
SELECT *
FROM employees
WHERE emp_no = <CFQUERYPARAM CFSQLTYPE="CF_SQL_INTEGER" VALUE="#ARGUMENTS.emp_no#">
</cfquery>
<cfreturn qItem>
</cffunction>
<cffunction name="createemployees" output="false" access="remote" returntype="any" >
<cfargument name="item" required="true" />
<!--- Insert a new record in the database.
Add authorization or any logical checks for secure access to your data --->
<cfquery name="createItem" datasource="employees" result="result">
INSERT INTO employees (birth_date, first_name, last_name, gender, hire_date)
VALUES (<CFQUERYPARAM cfsqltype="CF_SQL_DATE" VALUE="#item.birth_date#">,
<CFQUERYPARAM cfsqltype="CF_SQL_VARCHAR" VALUE="#item.first_name#">,
<CFQUERYPARAM cfsqltype="CF_SQL_VARCHAR" VALUE="#item.last_name#">,
<CFQUERYPARAM cfsqltype="CF_SQL_CHAR" VALUE="#item.gender#">,
<CFQUERYPARAM cfsqltype="CF_SQL_DATE" VALUE="#item.hire_date#">)
</cfquery>
<!--- The GENERATED_KEY is valid for mysql database only, you can modify it for your database --->
<cfreturn result.GENERATED_KEY/>
</cffunction>
<cffunction name="updateemployees" output="false" access="remote" returntype="void" >
<cfargument name="item" required="true" />
<!--- Update an existing record in the database.
Add authorization or any logical checks for secure access to your data --->
<cfquery name="updateItem" datasource="employees">
UPDATE employees SET birth_date = <CFQUERYPARAM cfsqltype=CF_SQL_DATE VALUE="#item.birth_date#">,
first_name = <CFQUERYPARAM cfsqltype=CF_SQL_VARCHAR VALUE="#item.first_name#">,
last_name = <CFQUERYPARAM cfsqltype=CF_SQL_VARCHAR VALUE="#item.last_name#">,
gender = <CFQUERYPARAM cfsqltype=CF_SQL_CHAR VALUE="#item.gender#">,
hire_date = <CFQUERYPARAM cfsqltype=CF_SQL_DATE VALUE="#item.hire_date#">
WHERE emp_no = <CFQUERYPARAM CFSQLTYPE="CF_SQL_INTEGER" VALUE="#item.emp_no#">
</cfquery>
</cffunction>
<cffunction name="deleteemployees" output="false" access="remote" returntype="void" >
<cfargument name="emp_no" type="numeric" required="true" />
<!--- Delete a record in the database.
Add authorization or any logical checks for secure access to your data --->
<cfquery name="delete" datasource="employees">
DELETE FROM employees
WHERE emp_no = <CFQUERYPARAM CFSQLTYPE="CF_SQL_INTEGER" VALUE="#ARGUMENTS.emp_no#">
</cfquery>
</cffunction>
</cfcomponent>
The EmployeeServiceDM service returns untyped data. Use the Flash
Builder tools to configure the return type for getAllEmployeess() and getEmployees().
Use Employee for the custom data type returned by these operations.
After configuring the return type, enable data management on
the Employee data type.