Jason, Patrick,
Thanks for the advice – you guys
gave me a lot to play with.
Cheers,
Baz
From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Branley
Sent: Friday, February 03, 2006
9:40 PM
To: CFCDev@cfczone.org
Subject: Re: [CFCDev] Inserting
multiple records in 1 Method
assuming you are rolling
your own transactions by deleting the records if you encounter an error instead
of cftransaction, you could use a little queue.cfc that did the work and
dynamically called the add / delete methds. eg.
q = createObject('queue')
//set the object u want the node to do the work on, and the names of the
functions that do the commit / rollback operations.
q.addNode( customer, 'insertCustomer', 'deleteCustomer', params.. );
//keep creating and adding nodes into queue for each operation.
q.addNode( contact, 'insertContact', 'deleteConctact', params... );
//the queue processes each of its nodes calling inserts and if any return
errors calling the delete on each previous element it has processed.
q.run();
CFINVOKE will help u building the nodes an the queue so u can dynamically call
methods on the objects u pass into the node/queue.
hope this helps.
Pat
On 2/4/06, Jason
Daiger <[EMAIL PROTECTED]>
wrote:
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=""
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=""
<cfset
retVal = saveBean(arguments.aBean, arguments.dbMgr,
arguments.userName, arguments.deleteFlag)>
<cfif
retVal eq true>
<cftransaction action=""
<cfelse>
<cftransaction action="">
</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
----------------------------------------------------------
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
|