CF Wishlist: named transactions

Published By: Jared Rypka-Hauer on Nov 28, 2007 at 12:44 AM

Times Viewed: 3395

Categories: ColdFusion, General, OO Development, Programming, Reactor For ColdFusion, ColdSpring

OK so it's time to start sharing our ColdFusion wishlists again, now that CF8 is out and being used around the world. So what do I want to see in CF9?

This:

<cftransaction name="trans1" action="begin" result="trans1rslt" />
<cftransaction name="trans2" action="begin" />

<cfquery name="foo" datasource="foo" transaction="trans1">
...sql here///
</cfquery>

<cfquery name="foo" datasource="foo" transaction="trans2">
...sql here///
</cfquery>

<cftransaction name="trans1" action="rollback" />
<cftransaction name="trans2" action="commit" />

<cfdump var="#trans1rslt#" /> 

 

This would allow us to handle any arbitrary number of queries in a request by handing the control of queries over to a named transaction... it allows us to create transaction objects, have multiple simultaneous transactions, and, well, in general it gives us near total control over our transactions.

If you like it, please leave a comment so Adobe can see the support? Blog links to this post if you like the idea too? Thanks!

16 Comments

Apparently when I edited this I lost some existing comments... Jeff's reposting his, but Barney said:

- Comment Made By: -
Barney Boisvert

- Comment: -
Not as obvious, but in my opinion more useful, is that this syntax would remove the requirements that CFQUERYs be nested within a CFTRANSACTION tag. That's a really harsh limitation for certain scenarios with no real workaround (aside from managing your transactions in the DB directly via CFQUERY and raw SQL, relying on the undocumented feature that CF single threads requests on a DB connection - this is a behaviour BD doesn't share).

With AOP via ColdSpring this problem is a bit less of an issue, but I've been wanting that silly nesting requirement to go away for years and years, and it'd still be nice.

Posted By: Jared Rypka-Hauer on Nov 28, 2007

reposting from earlier (not sure what happened)
---------

+1

This is an awesome idea.

My question, would this only work in certain DBs that could support it or is this something that CF can handle under the hood (so to speak)?

Posted By: Jeff Coughlin on Nov 28, 2007

My comment become a blog post:
http://www.compoundtheory.com/?action=displayPost&ID=269

Count me in on this feature!!!

Posted By: Mark Mandel on Nov 28, 2007

Excellent request!

Posted By: Mike Kelp on Nov 28, 2007

I like the goal, but I've got a small bone to pick with the implementation: I'm not a fan of the transaction="stringLiteral" bit on the <cfquery /> and <cftransaction /> tags. Sure, it could be a variable that's the name of the transaction, but why not treat the transaction as an instance that can be passed around? I've always found it a better design to pass a data structure / object than a string, because something else will always popup.

What I'm saying is this:

<cftransaction name="transactionOne" />

<cfquery transaction="#transactionOne#">
do stuff
</cfquery>

<!--- Invoke some object that does something that may / may not be in a transaction --->
<cfset someObject.doSomethingTransactional(transactionOne) />

<cftransaction action="commit" transaction="#transactionOne#" />


-Joe

Posted By: Joe RInehart on Nov 28, 2007

Anything that allows nested transactions would be helpfull.

Posted By: Michael on Nov 28, 2007

Joe,

As far as that goes, it's really neither here nor there. It may end up being useful to do it one way or the other.

ColdFusion data sets are referenced via strings, scopes by reference... there's precedent for either. I think it depends on if the transaction becomes an object or if it's simply a pointer that can be referenced via a string. It's up to the CF team to figure out which is best for this situation.

I'm mostly with you, though, and I wish things like cfoutput could use either query="myQuery" or query="#myObject.getQuery()#" too... it would make many things much easier (like pulling data out of the MG event).

Posted By: Jared Rypka-Hauer on Nov 28, 2007

What's extra annoying is that I saw nested transactions demoed during the Scorpio beta tour, so I know they were working on it. No idea why they didn't add it though. It's really annoying to work around this though so hopefully they'll add it.

Posted By: Brian Kotek on Nov 28, 2007

++1. I have a case right now where this would be handy.

Posted By: Jake Munson on Nov 28, 2007

This is definitely a great request and I am suprised we don't have this kind of control over our transactions yet in CF. I am thinking it would also be nice to be able to scope the transaction so that we can carry a transaction to the end point of say a checkout process and then commit it.

Posted By: John Brunelle on Nov 28, 2007

Coldfusion should also support native ORM functionality, this will Increase development time by 20% using Hibernate or iBatis at the JAVA level this could be done pretty easy

Posted By: Elias J. Perez on Dec 4, 2007

Elias,

Hibernate is supported "natively" - I do some ColdFusion work with the model in Java, persisted via Hibernate. Just drop the .jar's into /lib and go...

I imagine iBatis wouldn't be much different.

Posted By: Joe Rinehart on Dec 4, 2007

Sweet!!!
Do you know where I can find resources to implement Hibernate with CF?

Thanks Joe

Posted By: Elias on Dec 4, 2007

A wish for ColdFusion 9 is a useful ternary operator similar to that of Javascript.

If expression one is true, expression two is returned, else expression three is returned.
expression one ? expression two : expression 3

I know we have IIf, but it requires so much other effort that it might as well not be in there.

Posted By: Andy Matthews on Dec 8, 2007

@Andy,

right, I agree with ya for sure... But I also agree having some transactions that I could rollback would be schweet!

cheers

Posted By: sal on Dec 12, 2007

This definitely looks like a good feature but this may make request processing slow because of change in transaction context. Here is why

- A single web request/page request is processed by a single web server (or CF) thread.
- Most transaction managers maintain a 1:1 relation b/w thread and tx object, via threadlocal.

In the above case, when trans1 is encountered in the current web thread, lets call it web-1, a trans1 object is associated with web-1. When trans2 is encountered, trans1 has to be suspended from web-1 and a new trans2 has to be associated.

And when cfquery ends, you are essentially running in an unspecified tx context, so CF has to do tx switching on every cfquery.

Thanks,
Hemant

Posted By: Hemant on Feb 8, 2008

Add a Comment

Please provide your email address if you want to subscribe to this blog entry. An unsubscribe link is provided in notification emails. Your email address is never shown on this website.
Processing... Please wait
We are adding your comment.