<< Back to previous view

[JDBC-80] Add support for generic java.sql.DatabaseMetaData use now connection management is more explicit. Created: 11/Dec/13  Updated: 01/Jun/16  Resolved: 12/Dec/13

Status: Closed
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Niels van Klaveren Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None


In clojure.java.jdbc 0.2.3 it was easy to call methods on the connection, like .getDatabaseMetaData.

Now connection management has changed, and finding, reaching and keeping connections (and accompanying DatabaseMetaData) is a lot harder.

It would be good to have two new functions that would give access to all database metadata information in a minimalistic way, and keeps connection management in line with the new clojure.java.jdbc 0.3.0 ideals.

The first is a function that gets / sets up a connection by the new connection rules (find-, get-, add-connection), and provides a local binding for the DatabaseMetaData object resulting from calling .getDatabaseMetaData on that connection.
Of course, like a transaction, this also means the actions done within that binding needs a single connection that's kept open for the duration of the binding block.

The second is a function (or enhancement of result-set-seq) that calls result-set-seq if the argument is (instance? java.sql.ResultSet) or else the argument itself; this is because metadata method calls can either give back a resultset that needs to be clojurized (f.i. .getTables)or an object by themselves (f.i. .getDriverName). Let's call it meta-result as an example.

That would make things like the following possible:

[m db]
#(meta-result (.getIndexInfo m nil nil (% :table_name) false false))
(meta-result (.getTables m nil schema nil (into-array String ["TABLE"])))))

As far as I can see that's a pretty minimalistic set of functions that unlocks all DatabaseMetaData possibilities. Also, because it integrates with the new connection rules, it would integrate nicely with transactions, in case of queries that are dynamically generated on metadata within the same transaction.

Comment by Sean Corfield [ 11/Dec/13 11:00 AM ]

Nice suggestion. Thanx. with-db-metadata is probably more in line with the current naming and perhaps metadata-result to tie back to that name, rather than cause any confusion with Clojure's built-in meta?

Comment by Niels van Klaveren [ 11/Dec/13 11:27 AM ]

Glad you like it. For my use it was the only basic option still missing from clojure.java.jdbc.
The names sounds fine to me, I agree any possible confusion with core's meta should be evaded.

Comment by Sean Corfield [ 12/Dec/13 7:56 PM ]

Added with-db-metadata and metadata-result. Will be in RC1.

Generated at Tue Sep 19 06:53:01 CDT 2017 using JIRA 4.4#649-r158309.