<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DAOs and Gateways in ColdFusion</title>
	<atom:link href="http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/</link>
	<description></description>
	<lastBuildDate>Sun, 08 Jan 2012 15:53:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-1004</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Sun, 23 May 2010 11:12:17 +0000</pubDate>
		<guid isPermaLink="false">#comment-1004</guid>
		<description>Thanks Mike, the single query approach is a great idea. I&#039;d love to see more people using this technique to reduce duplicate code in common queries. There is some more info about this over on the OOCF site:

http://www.objectorientedcoldfusion.org/wiki/Gateway#Minimising_duplication</description>
		<content:encoded><![CDATA[<p>Thanks Mike, the single query approach is a great idea. I&#8217;d love to see more people using this technique to reduce duplicate code in common queries. There is some more info about this over on the OOCF site:</p>
<p><a href="http://www.objectorientedcoldfusion.org/wiki/Gateway#Minimising_duplication" rel="nofollow">http://www.objectorientedcoldfusion.org/wiki/Gateway#Minimising_duplication</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Horne</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-964</link>
		<dc:creator>Michael Horne</dc:creator>
		<pubDate>Sat, 22 May 2010 09:51:38 +0000</pubDate>
		<guid isPermaLink="false">#comment-964</guid>
		<description>I know I&#039;m years behind this discussion but thought I&#039;d share my method.

I combine methods for getting single and multiple records into one CFC. Furthermore, my single getter calls the multiple getter and thru-passes the &#039;id&#039; argument. There are conditions inside the multiple getter to specify a WHERE clause if the argument is passed. This means that you just have a SINGLE query rather than one for each purpose.

In terms of returning data, I tend to lean towards returning a struct or an array of structs. I find it tends to make things a little easier in use. It also means I can add sub-structures to the result. (e.g. if I want a user record, I can add the info about the user type to the record. You can&#039;t do that in a query).

I use a conversion CFC that I put together to go from query to struct (or array of structs).

Just goes to prove that there are LOADS of different ways to do things in ColdFusion :-)
--
Mike</description>
		<content:encoded><![CDATA[<p>I know I&#8217;m years behind this discussion but thought I&#8217;d share my method.</p>
<p>I combine methods for getting single and multiple records into one CFC. Furthermore, my single getter calls the multiple getter and thru-passes the &#8216;id&#8217; argument. There are conditions inside the multiple getter to specify a WHERE clause if the argument is passed. This means that you just have a SINGLE query rather than one for each purpose.</p>
<p>In terms of returning data, I tend to lean towards returning a struct or an array of structs. I find it tends to make things a little easier in use. It also means I can add sub-structures to the result. (e.g. if I want a user record, I can add the info about the user type to the record. You can&#8217;t do that in a query).</p>
<p>I use a conversion CFC that I put together to go from query to struct (or array of structs).</p>
<p>Just goes to prove that there are LOADS of different ways to do things in ColdFusion <img src='http://blog.stannard.net.au/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
&#8211;<br />
Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-71</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Fri, 04 Jan 2008 00:50:58 +0000</pubDate>
		<guid isPermaLink="false">#comment-71</guid>
		<description>Yes, I believe that the array of structs is more efficient - particularly when you have a lot of fields. When you need to access the next &quot;record&quot; of data you can just access as a single entity from the array. With a query you would need to use a numeric index for the row and a named index for the field, which from memory is noticeably slower.

Good luck with Reactor. And keep in mind that you have Transfer available as well (http://www.transfer-orm.com). 

It would appear that Reactor is not getting much attention these days. Some important bugs remain unfixed even though patches have been submitted many months ago, and the Trac site has quite a bit of spam that is not being cleaned up :(

But I would be happy to know that I am wrong about this assumption!</description>
		<content:encoded><![CDATA[<p>Yes, I believe that the array of structs is more efficient &#8211; particularly when you have a lot of fields. When you need to access the next &quot;record&quot; of data you can just access as a single entity from the array. With a query you would need to use a numeric index for the row and a named index for the field, which from memory is noticeably slower.</p>
<p>Good luck with Reactor. And keep in mind that you have Transfer available as well (<a href="http://www.transfer-orm.com" rel="nofollow">http://www.transfer-orm.com</a>). </p>
<p>It would appear that Reactor is not getting much attention these days. Some important bugs remain unfixed even though patches have been submitted many months ago, and the Trac site has quite a bit of spam that is not being cleaned up <img src='http://blog.stannard.net.au/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>But I would be happy to know that I am wrong about this assumption!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominic Watson</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-70</link>
		<dc:creator>Dominic Watson</dc:creator>
		<pubDate>Thu, 03 Jan 2008 07:56:44 +0000</pubDate>
		<guid isPermaLink="false">#comment-70</guid>
		<description>Great minds think alike :p (and I am always at least 18 months behind), Peter&#039;s component is near identical to mine with a lot more methods thrown in.

I don&#039;t see the benefit of using an array of structs over a query though - is it to do with flexibility of data types?. At the moment, the component just uses the query and stores a pointer to the current row and the whole thing is about 50 lines of code so is very unbloated. It could be even less so because I think there should be a plain iterator base class and a BOI should inherit from that.

I&#039;ve just installed reactor so I&#039;m very interested to see what they do with their iterator (I saw the words GetIterator() somewhere and got excited, oh dear).

D :)</description>
		<content:encoded><![CDATA[<p>Great minds think alike :p (and I am always at least 18 months behind), Peter&#8217;s component is near identical to mine with a lot more methods thrown in.</p>
<p>I don&#8217;t see the benefit of using an array of structs over a query though &#8211; is it to do with flexibility of data types?. At the moment, the component just uses the query and stores a pointer to the current row and the whole thing is about 50 lines of code so is very unbloated. It could be even less so because I think there should be a plain iterator base class and a BOI should inherit from that.</p>
<p>I&#8217;ve just installed reactor so I&#8217;m very interested to see what they do with their iterator (I saw the words GetIterator() somewhere and got excited, oh dear).</p>
<p>D <img src='http://blog.stannard.net.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-69</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Thu, 03 Jan 2008 01:56:15 +0000</pubDate>
		<guid isPermaLink="false">#comment-69</guid>
		<description>Hi Dom

Great idea. This has some similarities with Peter Bells &quot;Iterating Business Object&quot; idea (http://www.pbell.com/index.cfm/2007/8/13/IBO-Sample-Code and the big brother version http://www.pbell.com/index.cfm/2007/6/20/IBO-20--Return-of-the-Iterating-Business-Object-Now-on-RIAForge)

The essence of Peter&#039;s idea is something along the lines of:

o_myIBO = myDAO.read(args)
while (o_myIBO.next()) {
o_myIBO.methodThatActsOnTheCurrentRow();
}

Initially I wasn&#039;t convinced that this was such a good idea, but thinking it through more I believe that it is particularly suited to ColdFusion development, primarily due to the potential performance gains, so makes it a good option for iteration. 

Incidentally, I understand that the best performance gains are provided when converting the query result to an array of structs inside the IBO (or DAO in your case) and maintaining a pointer to the &quot;current&quot; struct in the array. 

Thanks for your thoughts.</description>
		<content:encoded><![CDATA[<p>Hi Dom</p>
<p>Great idea. This has some similarities with Peter Bells &quot;Iterating Business Object&quot; idea (<a href="http://www.pbell.com/index.cfm/2007/8/13/IBO-Sample-Code" rel="nofollow">http://www.pbell.com/index.cfm/2007/8/13/IBO-Sample-Code</a> and the big brother version <a href="http://www.pbell.com/index.cfm/2007/6/20/IBO-20--Return-of-the-Iterating-Business-Object-Now-on-RIAForge)" rel="nofollow">http://www.pbell.com/index.cfm/2007/6/20/IBO-20&#8211;Return-of-the-Iterating-Business-Object-Now-on-RIAForge)</a></p>
<p>The essence of Peter&#8217;s idea is something along the lines of:</p>
<p>o_myIBO = myDAO.read(args)<br />
while (o_myIBO.next()) {<br />
o_myIBO.methodThatActsOnTheCurrentRow();<br />
}</p>
<p>Initially I wasn&#8217;t convinced that this was such a good idea, but thinking it through more I believe that it is particularly suited to ColdFusion development, primarily due to the potential performance gains, so makes it a good option for iteration. </p>
<p>Incidentally, I understand that the best performance gains are provided when converting the query result to an array of structs inside the IBO (or DAO in your case) and maintaining a pointer to the &quot;current&quot; struct in the array. </p>
<p>Thanks for your thoughts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominic Watson</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-68</link>
		<dc:creator>Dominic Watson</dc:creator>
		<pubDate>Wed, 02 Jan 2008 12:44:59 +0000</pubDate>
		<guid isPermaLink="false">#comment-68</guid>
		<description>I just looked this up on google because I am intersted in this topic (I realise it is old).

I have just created an iterator base class, that, with very little code under the hood will let you do like this:

o_myDAO.read(args); // depending on the args will get different result sets
while(o_myDAO.next()){
 o_myDAO.methodThatActsOnTheCurrentRow();
}

I think the tricky part is keeping the create, update and delete methods un-muddy but I think you could still do this AND have a seperate Gateway component for CUDding.

My temporary conclusion is that the iterator is useful in situations where you would need a seperate instance of an object for each record returned from a query but that this does not replace the &#039;need&#039; for a Gateway object.

Dom</description>
		<content:encoded><![CDATA[<p>I just looked this up on google because I am intersted in this topic (I realise it is old).</p>
<p>I have just created an iterator base class, that, with very little code under the hood will let you do like this:</p>
<p>o_myDAO.read(args); // depending on the args will get different result sets<br />
while(o_myDAO.next()){<br />
 o_myDAO.methodThatActsOnTheCurrentRow();<br />
}</p>
<p>I think the tricky part is keeping the create, update and delete methods un-muddy but I think you could still do this AND have a seperate Gateway component for CUDding.</p>
<p>My temporary conclusion is that the iterator is useful in situations where you would need a seperate instance of an object for each record returned from a query but that this does not replace the &#8216;need&#8217; for a Gateway object.</p>
<p>Dom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-83</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Mon, 29 Oct 2007 04:40:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-83</guid>
		<description>Hi Mike, these days I am heading in the same direction as you - keeping object persistance out of the bean. 

However, it did seem nice syntax to have code like

&lt;cfset person.save()&gt;
&lt;cfset postcode = person.getStreetAddress().getState()&gt;

where the &#039;person&#039; is my bean loaded up DAO and Gateway artillery. But I am trying some alternatives now.

I gave Reactor a run ( http://trac.reactorframework.com ) which also uses the Active Record pattern. This combines business objects with the data layer.

I am now looking into Transfer ( http://transfer.riaforge.org ) instead which separates out the business objects and the data layer. 

Sean wrote up a comparison of the two:
http://corfield.org/blog/index.cfm/do/blog.entry/entry/Comparing_Transfer_and_Reactor

I believe that generic get() and set() functions have special case uses rather than in common application beans. Peter Bell ( http://pbell.com) uses them in his application generator (they are not hand coded) and I would favour using them whenever an object has a range of general name/value properties. 

For the general approach I would still favour the setName()/getName() style. If typing all of those get and set statements is a problem, then Transfer or Reactor or something like Brian Rinaldi&#039;s CFCGenerator ( http://code.google.com/p/cfcgenerator ) might be just the ticket.</description>
		<content:encoded><![CDATA[<p>Hi Mike, these days I am heading in the same direction as you &#8211; keeping object persistance out of the bean. </p>
<p>However, it did seem nice syntax to have code like</p>
<p>&lt;cfset person.save()&gt;<br />
&lt;cfset postcode = person.getStreetAddress().getState()&gt;</p>
<p>where the &#8216;person&#8217; is my bean loaded up DAO and Gateway artillery. But I am trying some alternatives now.</p>
<p>I gave Reactor a run ( <a href="http://trac.reactorframework.com" rel="nofollow">http://trac.reactorframework.com</a> ) which also uses the Active Record pattern. This combines business objects with the data layer.</p>
<p>I am now looking into Transfer ( <a href="http://transfer.riaforge.org" rel="nofollow">http://transfer.riaforge.org</a> ) instead which separates out the business objects and the data layer. </p>
<p>Sean wrote up a comparison of the two:<br />
<a href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/Comparing_Transfer_and_Reactor" rel="nofollow">http://corfield.org/blog/index.cfm/do/blog.entry/entry/Comparing_Transfer_and_Reactor</a></p>
<p>I believe that generic get() and set() functions have special case uses rather than in common application beans. Peter Bell ( <a href="http://pbell.com)" rel="nofollow">http://pbell.com)</a> uses them in his application generator (they are not hand coded) and I would favour using them whenever an object has a range of general name/value properties. </p>
<p>For the general approach I would still favour the setName()/getName() style. If typing all of those get and set statements is a problem, then Transfer or Reactor or something like Brian Rinaldi&#8217;s CFCGenerator ( <a href="http://code.google.com/p/cfcgenerator" rel="nofollow">http://code.google.com/p/cfcgenerator</a> ) might be just the ticket.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Rankin</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-82</link>
		<dc:creator>Mike Rankin</dc:creator>
		<pubDate>Sun, 28 Oct 2007 19:57:37 +0000</pubDate>
		<guid isPermaLink="false">#comment-82</guid>
		<description>I&#039;ve sort of come full circle on this issue.  When I first started getting involved with oo cf, I would write a business object/bean and part of that cfc would have hooks to its associated DAO.  My DAO would handle all of the basic CRUD stuff as well as returning collections of objects and recordsets.  It really felt awkward that way, especially for the collections.  I would have to instantiate my bean in order to work with a recordset.  Pretty obvious that I had it wrong at that time.  I can&#039;t remember who to attribute this thought to (someone in the cf community said it before me), but getting a recordset this way felt like carrying a chair out the front door of your house and having the whole house follow you through the doorway.

Eventually, I read about this thing called a gateway object in cf and that seemed like it would be a good way to get rid of the door/house problem, so I put that in place.  The gateway would return either arrays of objects or recordsets as requested.  There was no direct coupling from the bean&#039;s point of view.  Any beans necessary would be instantiated in the gateway.  That seemed pretty good for a while.

After a while, I started feeling that the little CRUD wrappers I had in my beans to facilitate the use of the DAO started to feel strange to me.  I would look at those methods and think &quot;they have nothing to do with my business logic and add a lot of noise to my bean code&quot;.  So, I reworked things again.  Now, my beans are completely ignorant of storage mechanisms.  Instead of instantiating the DAO with the bean init function, I now pass in the bean to a separately created DAO.  It adds a little more code to the software that uses the objects, but you feel a little more in control.  You only need to deal with a DAO when you have to deal with your persistence technology.

Lastly, I noticed that now my DAOs and my Gateways where constructed in very similar manners.  It felt like I had little reason for keeping them as separate objects.  They pretty much do the same job - interact with my database.  So, I put them both together.  I now only use DAOs.  The only reason I chose to use the DAO term instead of the Gateway term is that it just seems a little more descriptive and it&#039;s easier to type.

So, that&#039;s my trip.  I basically ended up with what I started with, although they are built substantially different.  I pretty much like the way they work now.  Next for me is to look a little closer at the work Sean Corfield has done to create default get/set functions.  That will certainly remove a lot of clutter.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve sort of come full circle on this issue.  When I first started getting involved with oo cf, I would write a business object/bean and part of that cfc would have hooks to its associated DAO.  My DAO would handle all of the basic CRUD stuff as well as returning collections of objects and recordsets.  It really felt awkward that way, especially for the collections.  I would have to instantiate my bean in order to work with a recordset.  Pretty obvious that I had it wrong at that time.  I can&#8217;t remember who to attribute this thought to (someone in the cf community said it before me), but getting a recordset this way felt like carrying a chair out the front door of your house and having the whole house follow you through the doorway.</p>
<p>Eventually, I read about this thing called a gateway object in cf and that seemed like it would be a good way to get rid of the door/house problem, so I put that in place.  The gateway would return either arrays of objects or recordsets as requested.  There was no direct coupling from the bean&#8217;s point of view.  Any beans necessary would be instantiated in the gateway.  That seemed pretty good for a while.</p>
<p>After a while, I started feeling that the little CRUD wrappers I had in my beans to facilitate the use of the DAO started to feel strange to me.  I would look at those methods and think &quot;they have nothing to do with my business logic and add a lot of noise to my bean code&quot;.  So, I reworked things again.  Now, my beans are completely ignorant of storage mechanisms.  Instead of instantiating the DAO with the bean init function, I now pass in the bean to a separately created DAO.  It adds a little more code to the software that uses the objects, but you feel a little more in control.  You only need to deal with a DAO when you have to deal with your persistence technology.</p>
<p>Lastly, I noticed that now my DAOs and my Gateways where constructed in very similar manners.  It felt like I had little reason for keeping them as separate objects.  They pretty much do the same job &#8211; interact with my database.  So, I put them both together.  I now only use DAOs.  The only reason I chose to use the DAO term instead of the Gateway term is that it just seems a little more descriptive and it&#8217;s easier to type.</p>
<p>So, that&#8217;s my trip.  I basically ended up with what I started with, although they are built substantially different.  I pretty much like the way they work now.  Next for me is to look a little closer at the work Sean Corfield has done to create default get/set functions.  That will certainly remove a lot of clutter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-81</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Sat, 27 Oct 2007 06:31:21 +0000</pubDate>
		<guid isPermaLink="false">#comment-81</guid>
		<description>Thanks Sean. 

Whenever apparent &#039;rules&#039; present themselves it is easier to jump on board and use them rather than question them. And in the absence of experience or a guide it is as good a place to start as any. 

Overall though, I think the best idea to read out of the DAO and Gateway concepts is to separate out and encapsulate data access.</description>
		<content:encoded><![CDATA[<p>Thanks Sean. </p>
<p>Whenever apparent &#8216;rules&#8217; present themselves it is easier to jump on board and use them rather than question them. And in the absence of experience or a guide it is as good a place to start as any. </p>
<p>Overall though, I think the best idea to read out of the DAO and Gateway concepts is to separate out and encapsulate data access.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>http://blog.stannard.net.au/2007/02/10/daos-and-gateways-in-coldfusion/comment-page-1/#comment-80</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Sat, 27 Oct 2007 05:16:14 +0000</pubDate>
		<guid isPermaLink="false">#comment-80</guid>
		<description>I know this is an old entry but your blog just popped up on coldfusionbloggers so it&#039;s the first time I&#039;ve seen it...

The whole DAO/Gateway as separate CFCs thing dates back to a casual recommendation I made back in 2003 in the Mach-II Development Guide (on livedocs.adobe.com) when I was trying to help people structure their CFCs (when everyone was new to CFCs).

I hadn&#039;t intended it to become a rule cast in stone but unfortunately that&#039;s what happened.

I certainly don&#039;t advocate this separation as a default these days - in fact I tend to put everything in a XyzGateway.cfc (although my single object persistence is usually handled by Transfer ORM these days).

I&#039;ve constantly been surprised at how literally people have followed some of my old, old advice... :(</description>
		<content:encoded><![CDATA[<p>I know this is an old entry but your blog just popped up on coldfusionbloggers so it&#8217;s the first time I&#8217;ve seen it&#8230;</p>
<p>The whole DAO/Gateway as separate CFCs thing dates back to a casual recommendation I made back in 2003 in the Mach-II Development Guide (on livedocs.adobe.com) when I was trying to help people structure their CFCs (when everyone was new to CFCs).</p>
<p>I hadn&#8217;t intended it to become a rule cast in stone but unfortunately that&#8217;s what happened.</p>
<p>I certainly don&#8217;t advocate this separation as a default these days &#8211; in fact I tend to put everything in a XyzGateway.cfc (although my single object persistence is usually handled by Transfer ORM these days).</p>
<p>I&#8217;ve constantly been surprised at how literally people have followed some of my old, old advice&#8230; <img src='http://blog.stannard.net.au/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

