You've got it.  Though I'd recommend the constructor, that's what it's
there for.  No real need to have get/set methods; how often do you
change datasources without reloading your application?  Easier to just
set it as an immutable property at instantiation time and forget about
it.  And don't forget to scope your query name.  Here's how I do it
(with lot of tag attributes missing for brevity):

<cfcomponent>

  <cffunction name="init">
    <cfargument name="dsn" />
    <cfset variables.my.dsn = dsn />
    <cfreturn this />
  </cffunction>

  <cffunction name="getEmployees">
    <cfset var getEmployees = "" />
    <cfquery datasource="#variables.my.dsn#" name="getEmployees">
      SELECT ....
    </cfquery>
    <cfreturn getEmployees />
  </cffunction>

</cfcomponent>

cheers,
barneyb

On 9/9/05, Jason Davey <[EMAIL PROTECTED]> wrote:
> Barney:
> 
> I like the idea of creating methods with no parameters e.g.
> getGasRemaining() thereby abstracting the interface from the caller. This
> raises the following question. In the case where you are calling a Gateway
> method (SQL SELECT calls), how do you create a clean method e.g.
> getEmployees() without passing in a datasource parameter? E.g.
> objGateway.getEmployees(APPLICATION.DataSource)
> 
> My answer: the gateway component itself has a property called "datasource"?
> Therefore, would the following be the right approach?
> 
> objGW = CreateObject("component","someObjGW").init();
> objGW.datasource = APPLICATION.DataSource;
> objGW.getEmployees();
> 
> Inside the Gateway component, there is the following:
> 
> The component 'setter / getter' functions...
> 
> <!--- set --->
> <cffunction name="setDataSource" access="private" returntype="void"
> output="false">
> 
> <cfargument name="datasource" type="string" required="true" />
> <cfset variables.datasource = ARGUMENTS.datasource />
> </cffunction>
> 
> <!--- get --->
> <cffunction name="getDataSource" access="private" returntype="string"
> output="false">
> <cfreturn variables.datasource />
> </cffunction>
> 
> 
> And then the getEmployees function...
> 
> <cffunction
>                 name="getEmployees"
>                 access="public"
>                 returntype="query"
>                 displayname=""
>                 hint="returns a list of all employees"
>                 output="false">
> 
> 
> 
>                 <cfquery name="qryGetEmployees"
> datasource="#THIS.datasource#">
> 
>                 SELECT *
>                 FROM people where category = 'employee'
> 
>                 </cfquery>
> 
> 
>                 <cfreturn qryGetEmployees />
>         </cffunction>
> 
> Jason D
> 

-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 100 invites.


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to