java.jdbc

Add support for generic java.sql.DatabaseMetaData use now connection management is more explicit.

Details

  • Type: Enhancement Enhancement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

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:

(db-metadata
[m db]
(map
#(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.

Activity

Hide
Sean Corfield added a comment -

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

Show
Sean Corfield added a comment - Added with-db-metadata and metadata-result. Will be in RC1.
Hide
Niels van Klaveren added a comment - - edited

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.

Show
Niels van Klaveren added a comment - - edited 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.
Hide
Sean Corfield added a comment -

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?

Show
Sean Corfield added a comment - 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?

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: