It should work for both, though if you have a transaction inside your store
proc, things won't happen the way you want.

Also, if you're using the ACTION attribute to CFTRANSACTION, you have to
manually rollback the transaction.  The auto-rollback only happens within an
open/close CFTRANSACTION block.  John made this point, which I neglected to
make explicitly, though I'm pretty sure the psuedo code from the original
discussion did it this way.

These two blocks are equivalent

<cftransaction>
  <cfquery name="whatever" ...></cfquery>
  <cfquery name="this_wil_fail" ...></cfquery>
</cftransaction>

<cftransaction action="begin" />
<cftry>
  <cfquery name="whatever" ...></cfquery>
  <cfquery name="this_wil_fail" ...></cfquery>
  <cftransaction action="commit" />
  <cfcatch type="database">
    <cftransaction action="rollback" />
  </cfcatch>
</cftry>

But this block is NOT equvalent (because the two CFTRANSACTION tags are not
related in any way):

<cftransaction action="begin" />
  <cfquery name="whatever" ...></cfquery>
  <cfquery name="this_wil_fail" ...></cfquery>
<cftransaction action="commit" />


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Justin Balog
> Sent: Thursday, December 04, 2003 12:56 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: [CFCDev] cftransaction with CFC's
> 
> I had the same question myself.  Is CFTransaction only for 
> grouping queries,
> or does it allow for the grouping of storedprocs?
> 
> -----Original Message-----
> From: Jon Gunnip [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 04, 2003 1:57 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [CFCDev] cftransaction with CFC's
> 
> 
> 
> Justin,
> 
> >From my understanding, it only makes sense to use 
> <cftransaction> when you
> want to group multiple database operations and be assured 
> that together they
> either all success or are all rolled back.
> 
> If you can't put 2 procedures in your transaction block and 
> have both of
> them rolled back if the second one fails, then the 
> transaction is not doing
> much for you.  Maybe I am not understanding you correctly?
> 
> I saw on another newsgroup that in MX 6.0, a CFC method call inside a
> transaction implicitly called "commit" upon return, thereby making it
> useless to have more than one CFC method call that does 
> database work inside
> a single transaction.  I haven't seen that problem in 6.1.
> 
> This is the only way I can get cftransaction to work with 
> CFC's in MX 6.1:
> 
> <cftransaction action="begin">
> 
> <cftry>
>   <cfset Page.DoInsert("OK") > // succeeds; does a database insert
>   <cfset Page.DoInsert() > // fails; so "rollback" in catch 
> block rolls back
> database insert on previous line
> 
>   <cfcatch type="any" >
>     <cftransaction action="rollback">
>   </cfcatch>
> </cftry>
> 
> </cftransaction>
> 
> Jon
> 
> >>> [EMAIL PROTECTED] 12/04/03 01:27PM >>>
> I think the solution is to implement it in a persistent cfc?  
> I use what
> Barney suggested in my Mach-ii apps, and have not encountered 
> any problems.
> Well, I don't think it works quite right becuase if in that 
> transaction
> block I call two storedprocs, and one fials, the transaction 
> does not get
> rolled back?  But I think that is due to my misunderstanding of
> <cftransaction>?
> 
> Here is my listener code...
> 
> <cfscript>
>       variables.model.beginTransAction();
>       try {
>       ///this calls the indivicual DAO which calls the schema 
> and inserts
> the individual
>       
> arguments.event.getArg("individual").getIndividualAddress().se
> tIndividualID(
> variables.individualDAO.create        
> (arguments.event.getArg("individual")));
>       //This calls the individual DAO adds the address (would like to
> announce a new event, but not sure how to handle
>       //in a single transaction
>       
> variables.individualDAO.addAddress(arguments.event.getArg("ind
> ividual").getI
> ndividualAddress());
>       variables.model.commitTransaction();
>                                       
>       } catch (any e){
>       errorMsg = "An Error Has Occured, Did We Roll Back The
> Transaction?";
>       variables.model.rollbackTransaction();
>       variables.model.throwError(e,errorMsg);
>                                       }
> </cfscript>
> 
> Here are the methods from my transaction manager
> 
> 
> Thanks,
> 
> Jusitn
> 
> -----Original Message-----
> From: Ben Curtis [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, December 04, 2003 1:15 PM
> To: [EMAIL PROTECTED] 
> Subject: Re: [CFCDev] cftransaction with CFC's
> 
> 
> 
> 
> > I have tried to implement this but when I try to write the
> PersonPersisotr.beginTransaction() and 
> PersonPersistor.endTransaction() with
> functions like this:
> > 
> > <cffunction name="beginTransaction" >
> >   <cftransaction>
> > </cffunction>
> > 
> > <cffunction name="endTransaction" >
> >   </cftransaction>
> > </cffunction>
> > 
> > I get a CF parsing error: "Context validation error for tag 
> cftransaction:
> The end tag </cftransaction> encoutered on line 253 at column 
> 19 requires a
> matching start tag."
> > 
> > I hope that if I could get by the CF parser, then the code 
> would function
> as expected.  Does anyone know how to "trick" the parser into 
> allowing a
> lone </cftransaction> tag?  Or is this hopeless?
> 
> I too encountered this problem. I haven't tested my solution 
> yet, but I've been thinking that what I'll need to do is 
> avoid cftransaction altogether and just code the transaction 
> commands directly in SQL in a cfquery tag. This, of course, 
> makes it database-specific, but at least the code is 
> extracted into a centralized location.
> 
> -- 
> 
>      Ben Curtis
>      WebSciences International
>      http://www.websciences.org/ 
>      v: 310 478 6648
>      f: 310 235 2067
> 
> 
> 
> 
> 
> 
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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' 
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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' 
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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' 
> in the message of the email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to