I create a Filter object, or Criteria as you call it, that essentially
contains all the possible WHERE options for the SQL and then pass this into
a DAO.  I've found this approach to be helpful as it separates the
filter/criteria from a directly link to the DAO or Gateway.  Also, I don't
use the Bean/Gateway data objects as I like having all my SQL in 1 DAO. I
like having 1 place to review all SQL code for a table or group of tables.
Regardless of the Bean/Gateway approach the concept would work the same.
Pass in a Filter/Criteria object to the DAO/Gateway and let it roll. 

-Jason

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Seth Johnson (KW)
Sent: Tuesday, January 10, 2006 12:03 PM
To: [email protected]
Subject: [CFCDev] Ad-hoc queries using Data Gateway objects

I'm trying to set up a data gateway object as part of a new project I'm
working on, but I don't really know what its methods should look like.

I have a getAll() method that returns all rows from the database and a
getById() method that accepts one or more ID values and returns the
corresponding rows. This works fine for simple tables, but I also have a
large search form where users fill in their criteria for running ad-hoc
queries.  How should I implement this in the DG object?

The approach I'm exploring uses a method called getByCriteria() which
accepts a GatewayCriteria object.  This object contains all of the ad-hoc
criteria definitions including the data member to match (i.e.
fieldname), search type (exact match, pattern match, etc) and value(s) look
for.  The data gateway object loops through the criteria and creates the
dynamic SQL for running that query.

Is there a better way?  

Thanks in advance for any suggestions,
Seth


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

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






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

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


Reply via email to