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

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: