alrightttttttttttttt
There are all these cfc generators for the cfc, bean & gateways but have no 
idea how to interact with them. (thats the basic question here......)


trying to learn my way into doing cfcs better and right now im trying the rds 
cfc generated code in eclipse. Starting with the active record one.

I'm also trying to learn cfscript a bit but am kinda lost on how you call the 
cfc this way to do the usual crud stuff. I can get it partially functioning on 
the inserts (if you dont count any data going in!! haha but the rows are being 
made). Im sure I can get it but id rather see some of the better practices.

what would my main starting points be?



if my cfc is:

<cfcomponent output="false" alias="components.test1.test">
        <!---
                 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="theName" type="string" default="">
        <cfproperty name="theEmail" type="string" default="">

        <cfscript>
                //Initialize the CFC with the default properties values.
                variables.id = 0;
                variables.theName = "";
                variables.theEmail = "";
        </cfscript>

        <cffunction name="init" output="false" returntype="test">
                <cfargument name="id" required="false">
                <cfscript>
                        if( structKeyExists(arguments, "id") )
                        {
                                load(arguments.id);
                        }
                        return this;
                </cfscript>
        </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="getTheName" output="false" access="public" 
returntype="any">
                <cfreturn variables.TheName>
        </cffunction>

        <cffunction name="setTheName" output="false" access="public" 
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.TheName = arguments.val>
        </cffunction>

        <cffunction name="getTheEmail" output="false" access="public" 
returntype="any">
                <cfreturn variables.TheEmail>
        </cffunction>

        <cffunction name="setTheEmail" output="false" access="public" 
returntype="void">
                <cfargument name="val" required="true">
                <cfset variables.TheEmail = arguments.val>
        </cffunction>



        <cffunction name="save" output="false" access="public" 
returntype="void">
                <cfscript>
                        if(getid() eq 0)
                        {
                                create();
                        }else{
                                update();
                        }
                </cfscript>
        </cffunction>



        <cffunction name="load" output="false" access="public" 
returntype="void">
                <cfargument name="id" required="true" >
                <cfset var qRead="">
                <cfquery name="qRead" datasource="ddddddd">
                        select  id, theName, theEmail
                        from test
                        where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" 
value="#arguments.id#" />
                </cfquery>

                <cfscript>
                        setid(qRead.id);
                        settheName(qRead.theName);
                        settheEmail(qRead.theEmail);
                </cfscript>
        </cffunction>



        <cffunction name="create" output="false" access="private" 
returntype="void">
                <cfset var qCreate="">

                <cfset var local1=gettheName()>
                <cfset var local2=gettheEmail()>

                <cftransaction isolation="read_committed">
                        <cfquery name="qCreate" datasource="ddddd">
                                insert into test(theName, theEmail)
                                values (
                                        <cfqueryparam value="#local1#" 
cfsqltype="CF_SQL_VARCHAR" />,
                                        <cfqueryparam value="#local2#" 
cfsqltype="CF_SQL_VARCHAR" />
                                )
                        </cfquery>

                        <!--- If your server has a better way to get the ID 
that is more reliable, use that instead --->
                        <cfquery name="qGetID" datasource="dddddd">
                                select id
                                from test
                                where theName = <cfqueryparam value="#local1#" 
cfsqltype="CF_SQL_VARCHAR" />
                                  and theEmail = <cfqueryparam value="#local2#" 
cfsqltype="CF_SQL_VARCHAR" />
                                order by id desc
                        </cfquery>
                </cftransaction>

                <cfset variables.id = qGetID.id>
        </cffunction>



        <cffunction name="update" output="false" access="private" 
returntype="void">
                <cfset var qUpdate="">

                <cfquery name="qUpdate" datasource="ddddd" result="status">
                        update test
                        set theName = <cfqueryparam value="#gettheName()#" 
cfsqltype="CF_SQL_VARCHAR" />,
                                theEmail = <cfqueryparam 
value="#gettheEmail()#" cfsqltype="CF_SQL_VARCHAR" />
                        where id = <cfqueryparam value="#getid()#" 
cfsqltype="CF_SQL_INTEGER">
                </cfquery>
        </cffunction>



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

                <cfquery name="qDelete" datasource="ddddd" result="status">
                        delete
                        from test
                        where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" 
value="#getid()#" />
                </cfquery>
        </cffunction>


</cfcomponent>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:259200
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to