Skip to content

Commit

Permalink
Merge pull request #2 from metabase/improve-destroy-connection-pool
Browse files Browse the repository at this point in the history
Tweak destroy-connection-pool! so it handles either specs or DataSources
  • Loading branch information
camsaul authored Jul 8, 2019
2 parents 42832a0 + 4eb5938 commit 8ac66b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metabase/connection-pool "1.0.1-SNAPSHOT"
(defproject metabase/connection-pool "1.0.1"
:description "Connection pools for JDBC databases. Simple wrapper around C3P0."
:url "https://github.com/metabase/connection-pool"
:min-lein-version "2.5.0"
Expand All @@ -22,7 +22,7 @@
:profiles
{:dev
{:dependencies
[[org.clojure/clojure "1.10.0"]
[[org.clojure/clojure "1.10.1"]
[expectations "2.2.0-beta2"]]

:injections
Expand Down
22 changes: 18 additions & 4 deletions src/metabase/connection_pool.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,28 @@
([spec, ^Map pool-properties]
(DataSources/pooledDataSource (unpooled-data-source spec), pool-properties)))

(def ^{:arglists '([spec] [spec pool-properties-map])} connection-pool-spec
(defn connection-pool-spec
"Create a new connection pool for a JDBC `spec` and return a spec for it. Optionally pass a map of connection pool
properties -- see https://www.mchange.com/projects/c3p0/#configuration_properties for a description of valid options
and their default values."
(comp (fn [x] {:datasource x}) pooled-data-source))
([spec]
{:datasource (pooled-data-source spec)})

([spec pool-properties-map]
{:datasource (pooled-data-source spec pool-properties-map)}))


(defn destroy-connection-pool!
"Immediately release all resources held by a connection pool."
[^DataSource pooled-data-source]
(DataSources/destroy pooled-data-source))
[spec-or-data-source]
(cond
(map? spec-or-data-source)
(recur (:datasource spec-or-data-source))

(instance? DataSource spec-or-data-source)
(DataSources/destroy ^DataSource spec-or-data-source)

:else
(throw
(IllegalArgumentException.
"Don't know how to destroy conn pool: expected JDBC spec with `:datasource` or instance of `DataSource`."))))

0 comments on commit 8ac66b3

Please sign in to comment.