Jared Rypka-Hauer wrote his first from-scratch application in Commodore Basic at the age of 9. In his teens, he dabbled in everything from dBase to HyperCard and was instrumental in the development of several commercial software products. In 1990, he began his professional IT career, spending the first 8 years primarily in end-user support and Infrastructure. Since 1998, his interests have revolved around ColdFusion and dynamic web applications. Finally making the jump to using OO methods for web development in January of 2005, he's become a presence in the web-development blogging community and has written for outlets such as FusionAuthority and ColdFusion Developer's Journal. Jared is also the primary organizer of the CF.Objective conference.
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!
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)?
My comment become a blog post:
http://www.compoundtheory.com/?action=displayPost&ID=269
Count me in on this feature!!!
Excellent request!
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
Anything that allows nested transactions would be helpfull.
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).
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.
++1. I have a case right now where this would be handy.
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.
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
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.
Sweet!!!
Do you know where I can find resources to implement Hibernate with CF?
Thanks Joe
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.
@Andy,
right, I agree with ya for sure... But I also agree having some transactions that I could rollback would be schweet!
cheers
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
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 at 12:00 AM