Is there a way to coerce the result row gotten from calling a stored procedure into a specific object so I can pass just a list of that object into the view?
I know I can use things like Node.list() to do this, but I am eventually going to replace getnodes() with a fairly complicated stored procedure that creates temp tables and does some optimised sql fu. But for now I am just working on the grails interaction.
So on MySQL side I have the following stored procedure:
CREATE DEFINER=`root`@`255.255.255.255` PROCEDURE `getnodes`()
BEGIN
select * from node;
END
On the grails controller I have the following:
def nodes = new ArrayList<Node>()
// collect all the nodes returned
sql.eachRow("{call getnodes()}") {
nodes.add(it as Node)
}
println "Nodes size is: " + nodes.size()
nodes.eachWithIndex { d, i ->
println "$i : $d"
}
My plan is to then pass the nodes to the view.
The problem is that it blows up on the line:
nodes.add(it as Node)
Is this even possible? I mean this should just coerce right? What am I doing wrong?