?

Log in

No account? Create an account
Passing ColdFusion Query objects to Java - Nick [entries|archive|friends|userinfo]
Nick

[ website | gagravarr.org ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Passing ColdFusion Query objects to Java [Jul. 12th, 2006|05:27 pm]
Nick
With ColdFusion CFX tags written in Java, you can get Queries that have been passed in to you, and set them back into the page that called you. This all happens with objects that implement com.allaire.cfx.Query. As long as you remember that the columns and rows are 1 based, all is fine.

Then, you try just passing a Query object to some java code (not a Tag). You assume that you can just accept a com.allaire.cfx.Query as a method argument, but it doesn't work.

It turns out that ColdFusion query objects are really a coldfusion.sql.QueryTable. This implements a number of useful interfaces (including javax.sql.RowSet, which many would argue is much nicer to work with than com.allaire.cfx.Query). What it doesn't do is implement com.allaire.cfx.Query.


This leaves you with two choices for passing ColdFusion queries into java. One is to accept a coldfusion.sql.QueryTable. This will give you lots more interesting methods to play with, but it means you can't easily share code between CFX and non CFX stuff.

The other option is to do what ColdFusion seems to do when you call a custom tag. Simply wrap all your coldfusion.sql.QueryTable in a coldfusion.runtime.QueryVector, which does implement the all important com.allaire.cfx.Query. (Just pass the real query object in to the constructor, and then use the resulting object as a com.allaire.cfx.Query).


Personally, I'm using method overloading. The main code accepts a com.allaire.cfx.Query, but there's another method that takes a coldfusion.sql.QueryTable, and wraps it up before calling the normal method.

Note: The above was tested on CFMX 6.1 and CFMX 7.0. I suspect the same will apply on 6.0, no idea about earlier.
linkReply

Comments:
[User Picture]From: brindy
2006-08-30 03:03 pm (UTC)
it would be nicer if your object took javax.sql.RowSet, i guess it depends how re-usable you want the code - if you're gonna stick with coldfusion and nothing else i guess it doesn't matter.

but if you did want something more generic, you could use a facade which has your method that takes javax.sql.RowSet as the argument then delegates to an object that is specifically designed to work with coldfusion (loaded through configuration, perhaps) and simply cast it to your coldfusion object that implements the RowSet interface.

spring application framework is nice for this kind of thing, but i still see it as over-engineering in most cases.

i like your blog, mind if i add you?

i found you through edparsonsblog
(Reply) (Thread)