Support loginTimeout on reified DataSource
This commit is contained in:
parent
eda9c93a1c
commit
f0c4159bff
3 changed files with 19 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ Only accretive/fixative changes will be made from now on.
|
|||
The following changes have been made to **master** since the 1.0.409 build:
|
||||
|
||||
* Fixes #101 by tightening the spec on a JDBC URL to correctly reflect that it must start with `jdbc:`.
|
||||
* Add support for calling `.getLoginTimeout`/`.setLoginTimeout` on the reified `DataSource` returned by `get-datasource` when called on a hash map "db-spec" or JDBC URL string.
|
||||
|
||||
## Stable Builds
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@
|
|||
(defn- get-driver-connection
|
||||
"Common logic for loading the designated JDBC driver class and
|
||||
obtaining the appropriate `Connection` object."
|
||||
[url etc]
|
||||
[url timeout etc]
|
||||
(when timeout (DriverManager/setLoginTimeout timeout))
|
||||
(DriverManager/getConnection url (as-properties etc)))
|
||||
|
||||
(def ^:private driver-cache
|
||||
|
|
@ -238,15 +239,18 @@
|
|||
"Given a JDBC URL and a map of options, return a `DataSource` that can be
|
||||
used to obtain a new database connection."
|
||||
[[url etc]]
|
||||
(let [login-timeout (atom nil)]
|
||||
(reify DataSource
|
||||
(getConnection [_]
|
||||
(get-driver-connection url etc))
|
||||
(get-driver-connection url @login-timeout etc))
|
||||
(getConnection [_ username password]
|
||||
(get-driver-connection url
|
||||
(get-driver-connection url @login-timeout
|
||||
(assoc etc
|
||||
:user username
|
||||
:password password)))
|
||||
(toString [_] url)))
|
||||
(getLoginTimeout [_] (or @login-timeout 0))
|
||||
(setLoginTimeout [_ secs] (reset! login-timeout secs))
|
||||
(toString [_] url))))
|
||||
|
||||
(defn- make-connection
|
||||
"Given a `DataSource` and a map of options, get a connection and update it
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@
|
|||
ds (p/get-datasource url)]
|
||||
(is (instance? javax.sql.DataSource ds))
|
||||
(is (str/index-of (pr-str ds) url))
|
||||
(.setLoginTimeout ds 0)
|
||||
(is (= 0 (.getLoginTimeout ds)))
|
||||
(with-open [con (p/get-connection ds {})]
|
||||
(is (instance? java.sql.Connection con)))))
|
||||
(testing "datasource via jdbcUrl"
|
||||
|
|
@ -113,6 +115,8 @@
|
|||
(is (str/index-of (pr-str ds) (str "jdbc:" (:dbtype db))))
|
||||
;; checks get-datasource on a DataSource is identity
|
||||
(is (identical? ds (p/get-datasource ds)))
|
||||
(.setLoginTimeout ds 1)
|
||||
(is (= 1 (.getLoginTimeout ds)))
|
||||
(with-open [con (p/get-connection ds {})]
|
||||
(is (instance? java.sql.Connection con)))))
|
||||
(testing "datasource via HikariCP"
|
||||
|
|
|
|||
Loading…
Reference in a new issue