I'm not the expert on DAO, but this is my take on it: It does hit the DB a harder and perhaps does more work than writing customized queries. However, I don't deal with the DB specifics at all when using the DAO/DG. I have three components to my DAO implementation.
1) Object - This is the definition of a structure that is represented in a table. Simple objects can be represented by a single row. Complex objects are represented by linked tables. Your end product will ALWAYS use a single object or collection of these objects. 2) DataMapper - this deals specifically with converting returned data from the datasource - whether it be a DB, XML, flatfile, or whatever - into a collection of above said objects. The Datagateway will send its data to this component (usually in table form) to be transformed into objects. 3) DataGateway - this component actually talks to the datasource. Like I said above, it can be a DB, XML file, Flatfile, excel file, or whatever. I grab the data from wherever, sort it into a table, and sends it to the DataMapper. The datamapper has a base of functions it performs, which are used by the end processes: 1) Store(object) - If an object is created, it can be passed around your process, changed, and then stored using this method. 2) Delete(object) - it removes the object from the datastore. 3) Get(NumberOfObjects) - This will retrieve a collection of objects from your datastore. I use a parameter if I only want a certain number (like the 10 most recent). The method by which it chooses those 10 is up to you. 4) GetById (Id) - This returns a specific instance of an object if you know its id. Every object you plan on persisting should have a unique identifier. If its id is 0 - meaning a new object - the DG will know to add it and set its id to the newly generated id from the datastore. If it is other than 0, then the DG updates the existing object in the datastore. The above functions accomplish 95% of what I need from the DAO. I write the queries that get my objects from the DB once and use them continually throughout my code. This is a pure OOP style of accomplishing this work - write once, reuse often. Here's a snippet of .NET code that would get the last 10 objects from a DB. // Mapper declaration ObjectDataMapper mapper = new ObjectDataMapper(new ObjectDataGateway(SqlConnection); // Get the list of objects from the DB and bind this list to a dropdown list // Title and ID are is a property of the object RepeaterControl.DataSource = mapper.Get(10); RepeaterControl.DataTextField = "Title"; RepeaterControl.ValueTextField = "Id"; See - no queries were written, a single sql connection was established, and a complete listing of objects was grabbed from a db. I have complete .NET code if you're interested in it. Any questions? - Matt Small -----Original Message----- From: Kevin Graeme [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 18, 2005 12:32 PM To: CF-Community Subject: Re: ASP.net 2.0 On 5/18/05, Matthew Small <[EMAIL PROTECTED]> wrote: > On that subject, does anybody here use DAO/DG methods for sending objects > to/from a database? It has simplified my code writing tremendously. When we took Helm's class on CFCs he talked quite a bit about using a DAO but never provided a working example. And we haven't quite figured out how to write an abstracted DAO that still provides the power of highly complicated SQL queries. From the stuff we've looked at, it seems that either we would either have to just create a dedicated CFC wrapper for every complicated SQL query, which doesn't do much for abstraction, or have a DAO that hammers the database over and over with simple queries and requires a lot more application code to assemble the results into what we need. So I'm a little confused on DAOs. Conceptually they sound great, but practically I just haven't figured them out. -Kevin ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:5:158086 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/5 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:5 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
