Hey all,

I've generally approached this by applying transactions at the
business level (usually in a Service or Manager component) that wrap
multiple calls to persistence methods across multiple persistence
objects.

> A third option that I haven't tried would be to use a service method
> dispatcher that all method calls run through.  So you call
> dispatcher.runMethod(obj, methodName, args)

I've hit a situation where I've needed something like this (had to
create ad-hoc transactions at the business level), so I created a FIFO
TransactionalQueue CFC.  Sorry I can't share the code for it, but I'll
recreate it and blog it if there's interest.  Not much to it, really,
here's how the api would work if I needed to transactionally save a
Contact and their Address  (Barney's probably guessed it all by now,
but what the heck):

<!--- Assumes I have "contact" and "address" beans to persist --->

<!--- Get DAOs from factory --->
<cfset contactDAO = createDAO("contact") />
<cfset addressDAO = createDAO("address") />

<!--- Create a transaction queue --->
<cfset tQueue = createObject("component", "TransactionalQueue").init() />

<!--- Queue the address save() />
<cfset args = structNew() />
<cfset args.address = address />
<cfset tQueue.add(addressDAO, "save", args) />

<!--- Queue the contact save() />
<cfset args = structNew() />
<cfset args.contact = contact />
<cfset tQueue.add(contactDAO, "save", args) />

<!--- Run 'em --->
<cfset tQueue.run() />

All the TransactionalQueue really does is manage an array of structs,
where each contains a reference, method name, and argument collection,
and then run() wraps a loop over the array in <cftransaction> tags,
making <cfinvoke> calls.

-Joe

--
Get Glued!
The Model-Glue ColdFusion Framework
http://www.model-glue.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:230080
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to