Baz,
I use an optional parameter, runAsTransaction (default = false), for my
save methods. Within the save, it will determine whether to wrap the
activity in the cftransaction accordingly. This is working well for
saves within the same db as it allows the parent object to enclose
dependent saves actions with cftransaction which will handle the
rollback for me automatically as Mihai described. One thing worth
noting is that I use the cftransaction action="begin|commit|rolleback"
since all my saves trap and log errors and return a boolean to indicate
success or failure. Below is the code.
<cfif arguments.runAsTransaction eq true>
<cftransaction action="begin">
<cfset retVal = saveBean(arguments.aBean, arguments.dbMgr,
arguments.userName, arguments.deleteFlag)>
<cfif retVal eq true>
<cftransaction action="commit"/>
<cfelse>
<cftransaction action="rollback"/>
</cfif>
</cftransaction>
<cfelse>
<cfset retVal = saveBean(arguments.aBean, arguments.dbMgr,
arguments.userName, arguments.deleteFlag)>
</cfif>
FYI, the saveBean method is a private method that actually does the
work. I know this doesn't help you in your multiple db save and as far
as I can tell you 'roll your own' transaction seems like the best way
around this issue at the moment.
-Jason
Baz wrote:
Hey Mihai, (does that rhyme?)
The AddCustomer() method actually creates other CFCs and calls *their* Add()
methods - there is no actual SQL on that page. Plus, more than 1 DB is being
accessed to complete the transaction. The contact info is stored in a
separate DB from the Customer info. You can't put 2 different DBs in 1
transaction can you?
Cheers,
Baz
_____
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Mihai Manuta
Sent: Friday, February 03, 2006 6:14 AM
To: CFCDev@cfczone.org
Subject: Re: [CFCDev] Inserting multiple records in 1 Method
You should create a transaction at the begining of the insert code and close
it at the end.
Do not delete anything if there is an error.
The transaction will roll back all data if there is a problem (all you need
is an exception when the error occurred).
Best regards,
Mihai
On Fri, 2006-02-03 at 05:57 -0500, Baz wrote:
Hi,
Lets say you have a method AddCustomer() that adds a customer into your DB.
A customer, however, is related to several other CFCs and DB tables such as
Addess, phone, email, etc. (each their own CFCs). So the AddCustomer()
method looks something like this:
. InsertCustomer()
. If error, exit
. InsertPhone()
. If error: DeleteCustomer(), exit
. InsertEmail()
. If error: DeletePhone(), DeleteCustomer(), exit
. etc...
If this goes on for a few more Inserts, you could see the last "If error"
having a lot of Deletes.
Is this a reasonable way of going about this? Anything I should?
Cheers,
Baz
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
cfcdev@cfczone.org 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/cfcdev@cfczone.org
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
cfcdev@cfczone.org 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/cfcdev@cfczone.org
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
cfcdev@cfczone.org 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/cfcdev@cfczone.org
--
Jason Daiger
URL: www.jdaiger.com
EML: [EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
cfcdev@cfczone.org 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/cfcdev@cfczone.org