Eric,

> * It is always better to have the class which creates a resource
> manage its cleanup rather than scattering that between disconnected
> classes. To not close the connection in this class creates a hidden
> dependency to on something else far away.

Yes, I agree with that. Letting some dependency (that might be
configured correctly) do some magic under jOOQ's hood doesn't seem
right to me either. This is OK in some contexts, but the default for
jOOQ should be to explicitly close any connection that was actively
obtained from a DataSource.

Without DataSources (i.e. the regular jOOQ Factory), this can be
safely ignored, as it will be up to client code to handle.

> [...]
> I can't find an authoritative source for this, but I think the best
> practice with DataSources and Connections is ALWAYS close the
> Connection when you are done with it, regardless of what kind of
> infrastructure you have going on at a higher level--it is the
> infrastructure's responsibility to ensure that your closing of the
> connection does not interfere with what it is doing.

That is how I understand it, too. At least when the connection
originates from a connection pool or from a distributed transaction -
i.e. from a DataSource. If the connection is obtained from a
DriverManager, then we're likely to be in some test or batch mode,
where you're not going to use a DataSource anyway.

Cheers
Lukas

Reply via email to