Reputation: 825
How would one metaClass a method that takes an object(s) and a closure?
Specifically say,
public void eachRow(GString gstring, Closure closure)
I'd like to metaClass eachRow() such that it prints the gstring parameter, and ignores the Closure. The goal is to create an app, that when passed a certain parameter does a sort of 'dry run' execution using groovy.sql.Sql, where instead of executing the queries, it just prints the statements it would have normally executed.
Upvotes: 0
Views: 226
Reputation: 825
So I think my issue wasn't how I was defining the method, but what I was (or wasn't returning). This appears to work ...
sql.metaClass.eachRow = { String qry, Closure c ->
println qry
new GroovyRowResult([:]) // I was returning null, adding this fixed me.
}
Upvotes: 1