From e54044e1e68b05b96744ebc4f302acb69fa93881 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 29 Jan 2021 17:16:35 -0800 Subject: [PATCH] Addresses #157 by using the volatile hack --- .gitignore | 1 + CHANGELOG.md | 3 +++ src/next/jdbc/prepare.clj | 13 ++++++------- src/next/jdbc/result_set.clj | 3 +++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6b4ac3b..4519b52 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ pom.xml.asc /.nrepl-history /.rebl /.nrepl-port +/.socket-repl-port .hgignore .hg/ /clojure_test* diff --git a/CHANGELOG.md b/CHANGELOG.md index cc098ca..b5f9bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/next/jdbc/prepare.clj b/src/next/jdbc/prepare.clj index 1c1599c..9785bcf 100644 --- a/src/next/jdbc/prepare.clj +++ b/src/next/jdbc/prepare.clj @@ -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) diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 35d8b05..96a0b31 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -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."