|Passing ColdFusion Query objects to Java
||[Jul. 12th, 2006|05:27 pm]
com.allaire.cfx.Query. As long as you remember that the columns and rows are 1 based, all is fine.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 |
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.