Hi,
It seems that groovy.sql.Sql's cacheConnection {} and withTransaction {}
both close the used connection on returning, regardless of the
surrounding context, and if using a data source the currently used
connection is set to NULL. E.g. if you do:
sql.cacheConnection { cc ->
sql.withTransaction { tc -> /* tc is same object as cc */
}
/* connection closed/null here */
}
You'll get an error if trying to execute any database queries using the
cc-connection after the withTransaction closure.
Also, for the same reason, you cannot have nested cacheConnection {}
closures (if you wanted to for some reason).
Looking at the source code for these methods it seems that they both
purposely ignore the current cacheConnection state during resource
clean-up and therefore end up closing/nulling the connection regardless
of context.
To me this seems incorrect - am I missing something here?
---
Regards,
Alex