Flash Builder 4通過LCDS31 Data Management訪問Coldfusion的CFCs

Coldfusion901上已經集成LCDS31,現在通過LCDSData Management訪問CF的自定義組件。

1.      俺使用Mysql5,並建立一個用戶les001,用於CF的數據服務訪問Mysql的,使用的數據庫名稱爲xtjc,這個可以參考前文<<ColdfusionLCDS部署在JBOSS >>,使用表workcalendar,數據如圖;

 

2.      修改CF_WWWROOT/WEB-INF/flex目錄下文件services-config.xml,取消channel-definitio id="cf-rtmp"的節點註釋,寫法大致如下;

 

<channel-definition id="cf-rtmp" class="mx.messaging.channels.RTMPChannel">

            <endpoint uri="rtmp://{server.name}:2048" class="coldfusion.flash.messaging.CFRTMPEndPoint"/>

            <properties>

                <idle-timeout-minutes>20</idle-timeout-minutes>

                       <serialization>

                              <enable-small-messages>false</enable-small-messages>

                       </serialization>

                       <coldfusion>

 

                              <access>

                                     <use-mappings>true</use-mappings>

                                     <method-access-level>remote</method-access-level>

                              </access>

 

                              <use-accessors>true</use-accessors>

                             

                              <use-structs>false</use-structs>

                             

                              <property-case>

                        <force-cfc-lowercase>false</force-cfc-lowercase>

                        <force-query-lowercase>false</force-query-lowercase>

                        <force-struct-lowercase>false</force-struct-lowercase>

                    </property-case>

                       </coldfusion>

            </properties>

        </channel-definition>

 

 

3.      還要配置channel-definitio id="cf-polling-amf"的節點,寫法大致如下;

 

<channel-definition id="cf-polling-amf" class="mx.messaging.channels.AMFChannel">

            <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamfpolling" class="coldfusion.flash.messaging.CFAMFEndPoint"/>

            <properties>

                <polling-enabled>true</polling-enabled>

                <polling-interval-seconds>8</polling-interval-seconds>

                       <serialization>

                              <enable-small-messages>false</enable-small-messages>

                       </serialization>

     </properties>

 </channel-definition>

 

4.      修改CF_WWWROOT/WEB-INF/flex目錄下文件data-management-config.xml,增加俺的destination

 

  <destination id="workcalendar">

                <adapter ref="coldfusion-dao"/>

                <channels>

                    <channel ref="cf-polling-amf"/>

                </channels>

                <properties>

                    <component>com.les.visual.workcalendarAssembler</component>

                    <scope>request</scope>

                    <metadata>

                        <identity property="id"/>

                                          <query-row-type>com.les.visual.workcalendar</query-row-type>

                    </metadata>

                </properties>

    </destination>

標記<component>com.les.visual.workcalendarAssembler</component>指出俺的編譯類名稱,標記<query-row-type>com.les.visual.workcalendar</query-row-type>指出俺的行記錄集的映射類

 

 

5.      FB4暫時沒有創建CF901編譯類的Wizard,俺藉助FB3創建編譯類,分別是workcalendar.cfcworkcalendarAssembler.cfcworkcalendarDAO.cfcworkcalendar.as

 

6.      先介紹workcalendar.as文件,這個是flash的數據映射類

    package com.les.visual

{

[Managed]

[RemoteClass(alias="com.les.visual.workcalendar")]

 

public class workcalendar

{

 

        public var id:Number = 0;

        public var Name:String = "";

        public var Workdate:Date = null;

        public var Worktime:Date = null;

        public var Direction:Number = 0;

        public var Halfrest:Number = 0;

 

 

        public function workcalendar()

        {

        }

 

}

}

關鍵要加上類說明     [RemoteClass(alias="com.les.visual.workcalendar")]

 

 

7.      workcalendar.cfc這個Bean File也是說明表workcalendar字段(屬性)的。

<cfcomponent output="false" alias="com.les.visual.workcalendar">

    <!---

        These are properties that are exposed by this CFC object.

        These property definitions are used when calling this CFC as a web services,

        passed back to a flash movie, or when generating documentation

 

        NOTE: these cfproperty tags do not set any default property values.

    --->

    <cfproperty name="id" type="numeric" default="0">

    <cfproperty name="Name" type="string" default="">

    <cfproperty name="Workdate" type="date" default="">

    <cfproperty name="Worktime" type="date" default="">

    <cfproperty name="Direction" type="numeric" default="0">

    <cfproperty name="Halfrest" type="numeric" default="0">

 

    <cfscript>

       //Initialize the CFC with the default properties values.

       variables.id = 0;

       variables.Name = "";

       variables.Workdate = "";

       variables.Worktime = "";

       variables.Direction = 0;

       variables.Halfrest = 0;

    </cfscript>

 

    <cffunction name="init" output="false" returntype="workcalendar">

       <cfreturn this>

    </cffunction>

    <cffunction name="getId" output="false" access="public" returntype="any">

       <cfreturn variables.Id>

    </cffunction>

 

    <cffunction name="setId" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Id = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getName" output="false" access="public" returntype="any">

       <cfreturn variables.Name>

    </cffunction>

 

    <cffunction name="setName" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfset variables.Name = arguments.val>

    </cffunction>

 

    <cffunction name="getWorkdate" output="false" access="public" returntype="any">

       <cfreturn variables.Workdate>

    </cffunction>

 

    <cffunction name="setWorkdate" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsDate(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Workdate = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid date"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getWorktime" output="false" access="public" returntype="any">

       <cfreturn variables.Worktime>

    </cffunction>

 

    <cffunction name="setWorktime" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsDate(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Worktime = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid date"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getDirection" output="false" access="public" returntype="any">

       <cfreturn variables.Direction>

    </cffunction>

 

    <cffunction name="setDirection" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Direction = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getHalfrest" output="false" access="public" returntype="any">

       <cfreturn variables.Halfrest>

    </cffunction>

 

    <cffunction name="setHalfrest" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Halfrest = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

</cfcomponent>

 

8.      workcalendarDAO.cfc這個DAO,是負責與數據庫打交道的,提取數據,創建數據,修改數據和刪除數據等工作。

<cfcomponent output="false">

 

    <cffunction name="read" output="false" access="public" returntype="com.les.visual.workcalendar[]">

       <cfargument name="id" required="false">

       <cfargument name="param" required="false">

       <cfset var qRead="">

       <cfset var obj="">

       <cfset var ret = ArrayNew(1)>

 

       <cfquery name="qRead" datasource="MSSQL2008R2">

           select id, Name, Workdate, Worktime, Direction, Halfrest

                 

           from workcalendar

           <cfif structKeyExists(arguments, "id")>

              where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />

           <cfelseif structKeyExists(arguments, "param")>

              <!---

                  adjust this where clause to fit your needs (based on what you want to filter by

                  (ie if you wanted to filter by LastName, pass in what you want to filter by in

                  the "param" attribute of the function and change "where fieldname" to

                  "where LastName" below)

 

                  by default, it will probably throw an error as invalid SQL

              --->

              <!--- where fieldname LIKE '%' & <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.param#"/> & '%' --->

           </cfif>

       </cfquery>

 

       <cfloop query="qRead">

           <cfscript>

              obj = createObject("component", "com.les.visual.workcalendar").init();

              obj.setid(qRead.id);

              obj.setName(qRead.Name);

              obj.setWorkdate(qRead.Workdate);

              obj.setWorktime(qRead.Worktime);

              obj.setDirection(qRead.Direction);

              obj.setHalfrest(qRead.Halfrest);

              ArrayAppend(ret, obj);

           </cfscript>

       </cfloop>

       <cfreturn ret>

    </cffunction>

 

 

 

    <cffunction name="create" output="false" access="public">

       <cfargument name="bean" required="true" type="com.les.visual.workcalendar">

       <cfset var qCreate="">

 

       <cfset var qGetId="">

 

       <cfset var local1=arguments.bean.getName()>

       <cfset var local2=arguments.bean.getWorkdate()>

       <cfset var local3=arguments.bean.getWorktime()>

       <cfset var local4=arguments.bean.getDirection()>

       <cfset var local5=arguments.bean.getHalfrest()>

 

       <cftransaction isolation="read_committed">

           <cfquery name="qCreate" datasource="MSSQL2008R2">

              insert into workcalendar(Name, Workdate, Worktime, Direction, Halfrest)

              values (

                  <cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />,

                  <cfqueryparam value="#local2#" cfsqltype="CF_SQL_DATE" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIME" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local5#" cfsqltype="CF_SQL_INTEGER" null="#iif((local5 eq ""), de("yes"), de("no"))#" />

              )

           </cfquery>

 

           <!--- If your server has a better way to get the ID that is more reliable, use that instead --->

           <cfquery name="qGetID" datasource="MSSQL2008R2">

              select id

              from workcalendar

              where Name = <cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />

                and Workdate = <cfqueryparam value="#local2#" cfsqltype="CF_SQL_DATE" null="#iif((local2 eq ""), de("yes"), de("no"))#" />

                and Worktime = <cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIME" null="#iif((local3 eq ""), de("yes"), de("no"))#" />

                and Direction = <cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />

                and Halfrest = <cfqueryparam value="#local5#" cfsqltype="CF_SQL_INTEGER" null="#iif((local5 eq ""), de("yes"), de("no"))#" />

              order by id desc

           </cfquery>

       </cftransaction>

 

       <cfscript>

           arguments.bean.setid(qGetID.id);

       </cfscript>

       <cfreturn arguments.bean />

    </cffunction>

 

 

 

    <cffunction name="update" output="false" access="public">

       <cfargument name="oldBean" required="true" type="com.les.visual.workcalendar">

       <cfargument name="newBean" required="true" type="com.les.visual.workcalendar">

       <cfset var qUpdate="">

 

       <cfquery name="qUpdate" datasource="MSSQL2008R2" result="status">

           update workcalendar

           set Name = <cfqueryparam value="#arguments.newBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />,

              Workdate = <cfqueryparam value="#arguments.newBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" null="#iif((arguments.newBean.getWorkdate() eq ""), de("yes"), de("no"))#" />,

              Worktime = <cfqueryparam value="#arguments.newBean.getWorktime()#" cfsqltype="CF_SQL_TIME" null="#iif((arguments.newBean.getWorktime() eq ""), de("yes"), de("no"))#" />,

              Direction = <cfqueryparam value="#arguments.newBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.newBean.getDirection() eq ""), de("yes"), de("no"))#" />,

              Halfrest = <cfqueryparam value="#arguments.newBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.newBean.getHalfrest() eq ""), de("yes"), de("no"))#" />

           where id = <cfqueryparam value="#arguments.oldBean.getid()#" cfsqltype="CF_SQL_INTEGER" />

             and Name = <cfqueryparam value="#arguments.oldBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />

             and Workdate = <cfqueryparam value="#arguments.oldBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" />

             and Worktime = <cfqueryparam value="#arguments.oldBean.getWorktime()#" cfsqltype="CF_SQL_TIME" />

             and Direction = <cfqueryparam value="#arguments.oldBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" />

             and Halfrest = <cfqueryparam value="#arguments.oldBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" />

       </cfquery>

       <!--- if we didn't affect a single record, the update failed --->

       <cfquery name="qUpdateResult" datasource="MSSQL2008R2"  result="status">

           select id

           from workcalendar

           where id = <cfqueryparam value="#arguments.newBean.getid()#" cfsqltype="CF_SQL_INTEGER" />

             and Name = <cfqueryparam value="#arguments.newBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />

             and Workdate = <cfqueryparam value="#arguments.newBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" />

             and Worktime = <cfqueryparam value="#arguments.newBean.getWorktime()#" cfsqltype="CF_SQL_TIME" />

             and Direction = <cfqueryparam value="#arguments.newBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" />

             and Halfrest = <cfqueryparam value="#arguments.newBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" />

       </cfquery>

       <cfif status.recordcount EQ 0>

           <cfthrow type="conflict" message="Unable to update record">

       </cfif>

       <cfreturn arguments.newBean />

    </cffunction>

 

 

 

    <cffunction name="delete" output="false" access="public" returntype="void">

       <cfargument name="bean" required="true" type="com.les.visual.workcalendar">

       <cfset var qDelete="">

 

       <cfquery name="qDelete" datasource="MSSQL2008R2" result="status">

           delete

           from workcalendar

           where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.getid()#" />

       </cfquery>

 

       <!--- Did we delete the record? --->

       <cfquery name="qDeleteResult" datasource="MSSQL2008R2"  result="status">

           select id

           from workcalendar

           where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.getid()#" />

       </cfquery>

       <cfif status.recordcount NEQ 0>

           <cfthrow type="conflict" message="Unable to delete record">

       </cfif>

 

    </cffunction>

 

    <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="MSSQL2008R2">

           select COUNT(*) as totalRecords

           from workcalendar

           <cfif structKeyExists(arguments, "id")>

              where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />

           <cfelseif structKeyExists(arguments, "param")>

              <!---

                  adjust this where clause to fit your needs (based on what you want to filter by

                  (ie if you wanted to filter by LastName, pass in what you want to filter by in

                  the "param" attribute of the function and change "where fieldname" to

                  "where LastName" below)

 

                  by default, it will probably throw an error as invalid SQL

              --->

              <!--- where fieldname LIKE '%' & <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.param#"/> & '%' --->

           </cfif>

       </cfquery>

 

       <cfreturn qRead.totalRecords>

    </cffunction>

</cfcomponent>

 

9.      workcalendarAssembler.cfc認可fill(),Sync(),Get(),Count()方法,是FB4(編譯後Flash)調度函數。fill從數據庫提取數據集填充Flash組件,get從數據庫提取指定數據,

syncFlash組件和數據庫之間同步數據,count計算結果集數據量。

<cfcomponent output="false">

 

  <!--- Code executed when component is created --->

  <cfscript>

         // Create a Data Access Object for this assembler instance

         variables.dao = CreateObject("component", "com.les.visual.workcalendarDAO");

  </cfscript>

 

  <cffunction name="fill" output="no" returntype="com.les.visual.workcalendar[]" access="remote">

         <cfargument name="param" type="string" required="no">

 

         <cftry>

                <cfif structKeyExists(arguments, "param")>

                       <cfreturn variables.dao.read(param=arguments.param)>

                <cfelse>

                       <cfreturn variables.dao.read()>

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during fill: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during fill: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during fill: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

  <cffunction name="get" output="no" returnType="com.les.visual.workcalendar" access="remote">

         <cfargument name="uid" type="struct" required="yes">

 

         <cftry>

                <!--- This is the record to look up --->

                <cfset key = uid.id>

 

                <cfset ret="">

                <cfset ret=variables.dao.read(id=key)>

 

                <cfif ArrayLen(ret) EQ 1>

                       <cfreturn ret[1]>

                <cfelseif ArrayLen(ret) GT 1>

                       <cfset msg="get returned more than one record when id had a value of #key#.">

                       <cfthrow message="#msg#">

                <cfelse>

                       <cfset msg="get did not return anything when id had a value of #key#.">

                       <cfthrow message="#msg#">

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during get: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during get: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during get: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

  <cffunction name="sync" output="no" returnType="array" access="remote">

         <cfargument name="changes" type="array" required="yes">

 

         <!-- 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>

 

  <cffunction name="count" output="no" returntype="Numeric" access="remote">

         <cfargument name="param" type="string" required="no">

 

         <cftry>

                <cfif structKeyExists(arguments, "param")>

                       <cfreturn variables.dao.count(param=arguments.param)>

                <cfelse>

                       <cfreturn variables.dao.count()>

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during count: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during count: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during count: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

 

  <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()>

 

         <!--- TODO: Validate that all the required fields are set --->

 

         <cftry>

                <!--- create the record, create returns with the identity fields set --->

                <cfset variables.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()>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during create: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during create: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during create: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <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()>

 

         <cftry>

                <!--- update the record --->

                <cfset new = variables.dao.update(old, new)>

                <!--- mark this change as processed successfully --->

                <cfset co.processed()>

 

                <!--- If there was a conflict, mark the change object.

                      Include the current version of the record --->

                <cfcatch type="conflict">

                       <cfset co.conflict(variables.dao.read(id=new.getid()))>

                </cfcatch>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during update: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during update: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during update: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <cfreturn co>

 

  </cffunction>

 

  <cffunction name="doDelete" access="private" output="no">

         <cfargument name="co" required="yes" hint="The change object.">

 

         <!--- the record to delete --->

         <cfset var old = co.getPreviousVersion()>

 

         <cftry>

                <!--- delete the record --->

                <cfset variables.dao.delete(old)>

                <!--- mark this change as processed successfully --->

                <cfset co.processed()>

                <!--- If there was a conflict, mark the change object.

                      Include the current version of the record --->

                <cfcatch type="conflict">

                       <cfset arr = variables.dao.read(id=old.getperson_id())>

                       <cfset co.conflict(arr[1])>

                </cfcatch>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during delete: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during delete: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during delete: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <cfreturn co>

 

  </cffunction>

</cfcomponent>

 

10.   FB4創建一個Coldfusion+LCDSProject,命名爲Flex2006,新建一個測試mxml,命名爲flex2004.mxml

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

               xmlns:s="library://ns.adobe.com/flex/spark"

               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <s:layout>

        <s:BasicLayout/>

    </s:layout>

    <fx:Script>

        <![CDATA[

            import mx.collections.errors.ItemPendingError;

            private function createPendingItem(index:int, ipe:ItemPendingError):Object {

                return "[" + index + " ...]";

            }

            private function createFailedItem(index:int, info:Object):Object {

                return "[" + index + " failed]";

            }

        ]]>

    </fx:Script>

    <fx:Declarations>

        <!-- 將非可視元素(例如服務、值對象)放在此處 -->

        <s:DataService destination="workcalendar" id="ds"/>

        <mx:ArrayCollection id="products"/>

    </fx:Declarations>

    <s:SkinnableContainer>

        <s:layout>

            <s:VerticalLayout>

            </s:VerticalLayout>

        </s:layout>

        <s:Button label="Get Data" click="ds.fill(products);"/>

        <mx:DataGrid dataProvider="{products}" id="dg">

        </mx:DataGrid>

    </s:SkinnableContainer>

    </s:Application>

 

注意編譯選項 -services "CF_wwwroot/WEB-INF/flex/services-config.xml" -locale en_US

 

 

 

11.   workcalendar.cfcworkcalendarAssembler.cfcworkcalendarDAO.cfcworkcalendar.as拷貝到CF_wwwroot/com/les/visual目錄下面。

12.   運行結果。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章