Ok, I've got a <cftransaction> construct such as the pseudo code below.
<cftransaction action="begin">
<cfquery name=one/>
<cfquery name=two/>
<cfquery name=three/>
<cfquery name=four/>
<cfif Success>
<cftransaction action="commit"/>
<cfelse>
<cftransaction action="rollback"/>
</cfif>
</cftransaction>
The problem is that I have over a dozen transaction sets like this where
only query two changes, the other three are the same. In the interest of
code reuse, and my personal sanity, I would like to somehow use common code
for the three unchanging queries. I'm wondering what is the best way to do
this?
What is most important is that all the queries succeed or fail as a group.
It would be very bad for the database if query one and two succeeded and
input data into the database, but query three fails and query four is not
even tried because of the failure.
The idea one I'm most confident will work, but is it really the best?
<cftransaction action="begin">
<cfinclude template=query_one.cfm>
<cfinclude template=query_two.cfm>
<cfinclude template=query_three.cfm>
<cfinclude template=query_four.cfm>
<cfif Success>
<cftransaction action="commit"/>
<cfelse>
<cftransaction action="rollback"/>
</cfif>
</cftransaction>
Are there any other ways to do this? Could one somehow use custom tags or
components? Would these actually be better even if they are useable?
<cftransaction action="begin">
<cf_queryOne>
<cf_queryTwo>
<cf_queryThree>
<cf_queryFour>
<cfif Success>
<cftransaction action="commit"/>
<cfelse>
<cftransaction action="rollback"/>
</cfif>
</cftransaction>
OR
<cftransaction action="begin">
<cfinvoke component=query method=one>
<cfinvoke component=query method=two>
<cfinvoke component=query method=three>
<cfinvoke component=query method=four>
<cfif Success>
<cftransaction action="commit"/>
<cfelse>
<cftransaction action="rollback"/>
</cfif>
</cftransaction>
Is there an entirely another way to be thinking about this problem?
Something that is simple and straightforward that I'm overlooking?
Thanks
--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/lists.cfm?link=t:4
Subscription: http://www.houseoffusion.com/lists.cfm?link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community.
http://www.fusionauthority.com/ads.cfm