Addresses #157 by using the volatile hack

This commit is contained in:
Sean Corfield 2021-01-29 17:16:35 -08:00
parent dc240652fc
commit e54044e1e6
4 changed files with 13 additions and 7 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@ pom.xml.asc
/.nrepl-history
/.rebl
/.nrepl-port
/.socket-repl-port
.hgignore
.hg/
/clojure_test*

View file

@ -4,6 +4,9 @@ Only accretive/fixative changes will be made from now on.
## Stable Builds
* 1.1.next in progress
* Address #157 by using a `volatile!` as a way to break the circular dependency (code that requires `next.jdbc.prepare` and uses `execute-batch!` without also requiring something that causes `next.jdbc.result-set` to be loaded will no longer return generated keys from `execute-batch!` but that's an almost impossible path since nearly all code that uses `execute-batch!` will have called `next.jdbc/prepare` to get the `PreparedStatement` in the first place). _[I'm leaning toward adding `execute-batch!` to `next.jdbc` and deprecating the one in `next.jdbc.prepare`]_
* 1.1.613 -- 2020-11-05
* Fix #144 by ensuring `camel-snake-case` is properly required before use in an uberjar context.

View file

@ -190,6 +190,8 @@
(j/set-properties stmt props))
stmt)))
(def ^:private d-r-s (volatile! nil))
(defn execute-batch!
"Given a `PreparedStatement` and a vector containing parameter groups,
i.e., a vector of vector of parameters, use `.addBatch` to add each group
@ -225,13 +227,10 @@
(execute-batch! ps param-groups {}))
([^PreparedStatement ps param-groups opts]
(let [gen-ks (when (:return-generated-keys opts)
(try
(let [drs (requiring-resolve
'next.jdbc.result-set/datafiable-result-set)]
#(drs (.getGeneratedKeys ^PreparedStatement %)
(p/get-connection ps {})
opts))
(catch Throwable _)))
(when-let [drs @d-r-s]
#(drs (.getGeneratedKeys ^PreparedStatement %)
(p/get-connection ps {})
opts)))
params (if-let [n (:batch-size opts)]
(if (and (number? n) (pos? n))
(partition-all n param-groups)

View file

@ -638,6 +638,9 @@
(.next rs))
(rs! builder rs'))))))
;; make it available to next.jdbc.prepare
(vreset! @#'prepare/d-r-s datafiable-result-set)
(defn- stmt->result-set
"Given a `PreparedStatement` and options, execute it and return a `ResultSet`
if possible."