Hi Aaron,
Thanks for these contributions.
> I have written a patch which uses composition over inhertiance. All objects
> now have a reference to the configuration instead of inheriting from it.
> That makes a lot of code much more simple and allows to get rid of many
> constructors and some methods. The patch for ExecuteListeners would fit
> perfectly into the new approach.
So you agree with Sergey's contribution?
Looks interesting at first sight. However...
Would it be possible to create one branch / pull-request per idea? I
would like to have a look at your improvements to the Configuration /
Factory relationship without the side-effects of a ConnectionProvider.
I'm still not convinced by this ConnectionProvider. jOOQ users should
not bother with an additional non-JDBC type that does almost the same
as a JDBC DataSource when they already have JDBC Connections and
DataSources. Even if we'd introduce this, it should not be the only
way to interact with jOOQ's Factory. The existing operation modes
involving Connection and DataSource must be maintained.
Regarding your JDBC compatibility concerns: The JDK 7 is the last one
to contain an incompatible API upgrade (from JDBC 4.0 to 4.1). With
Java 8 extension methods, JDBC 4.2 or 5.0 or whatever it will be
called can be expected to be compatible with JDBC 4.1. While you argue
that JDBC API upgrades had been incompatible in the past and that this
had led to issues with your source code, you promote incompatible
upgrades of the jOOQ API instead. I'm sure, most users will find the
JDBC API upgrades less painful.
At the same time, I have fixed #1498. With this, it should be possible
to compile (and run) jOOQ and the jOOQ Console against JDBC 4.1. Did
you try it?
https://sourceforge.net/apps/trac/jooq/ticket/1498
> The second commit allows to use any kind of provider to get a connection -
> at lest it should. Right now, the source of the connection leaks into
> several places in the jOOQ codebase (DataSourceConnection, ConnectionProxy,
> DataSourceStatement, ...). My approach avoid this. You just ask the
> Configuration for the connection provider which gives you the connection.
jOOQ's internals can live with a "leaking connection source", I think.
The current implementation seems robust enough to me. But client code
should not be bothered with leaks of jOOQ's internals (=
ConnectionProvider). Some users on this group wouldn't be happy with
that... Some sample discussions:
-
https://groups.google.com/d/topic/jooq-user/q6Yf7voPaqQ/discussion
-
https://groups.google.com/d/topic/jooq-user/SPq6lKX-BtM/discussion
> The only open end here is that I don't know where jOOQ closes the
> connections that it got from the DataSource but Lukas can probably add the
> call to ConnectionProvider.close() in a few minutes.
DataSourceStatement closes DataSource-generated connections on
Statement.close() invocation. That is the typical moment when you'd
return (close) a Connection that was obtained from a DataSource.
Standalone Connections are never closed by jOOQ.
> Now back to the meat. Instead of inheriting from Configuration, I pass a
> reference to a Configuration around, possibly wrapping an existing
> Configuration when necessary. So instead of 5-6 constructors, the DB
> specific factories just have two:
>
> public H2Factory(Configuration configuration) {
> super(new DefaultConfiguration(configuration, SQLDialect.H2));
> }
> public H2Factory() {
> super(new DefaultConfiguration(SQLDialect.H2));
> }
Yes, that makes sense. I can see how composition instead of
inheritance will improve the overall design here. Note though, your
suggested changes in their current state are too fundamental to be
merged as a whole for the jOOQ 2.x stream. Incompatible API changes
will have to be postponed to jOOQ 3.0... I'll track this as #1533:
https://sourceforge.net/apps/trac/jooq/ticket/1533
Maybe there is a compatible way to implement this, though? I could
give it a shot, myself. Of course, this would lead to even more
constructors. The existing constructors could remain, as convenience
constructors.
> But since I'm unsure whether this patch has any chance to be
> included in the release, I didn't want to spend move than 8 hours on it.
No problem.
> There are these questions left:
>
> 1. When do I pass the configuration on and when do I clone?
> 2. When I clone, how deep do I clone? Should I clone the ConnectionProvider,
> too? How about the data map? Settings?
I'm not sure why cloning of Configuration attributes should be done...?
> 3. Factory has a method "attach" which I don't understand. [...]
I hope that this "attach" method will become obsolete at some point.
Some rather remote org.jooq.QueryPart and org.jooq.Store objects need
live Connections to fulfill their API. attach() takes care of that,
recursively. This is a legacy "feature" from pre-2.0 implementations
> The original code
> was:
>
> attachable.attach(this);
>
> Now, it is:
>
> attachable.attach(configuration);
>
> which might be wrong.
Seems right to me.