Import fj private wrappers from clojure.core.reducers
This commit is contained in:
parent
c4430abe49
commit
99dd44c2ba
1 changed files with 42 additions and 23 deletions
|
|
@ -27,7 +27,8 @@
|
||||||
ResultSet ResultSetMetaData
|
ResultSet ResultSetMetaData
|
||||||
Statement
|
Statement
|
||||||
SQLException)
|
SQLException)
|
||||||
(java.util Locale)))
|
(java.util Locale)
|
||||||
|
(java.util.concurrent ForkJoinPool ForkJoinTask)))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
@ -603,6 +604,24 @@
|
||||||
init')))
|
init')))
|
||||||
(f init {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
(f init {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
||||||
|
|
||||||
|
;; ForkJoinTask wrappers copied in from clojure.core.reducers to avoid
|
||||||
|
;; relying on private functionality that might possibly change over time
|
||||||
|
|
||||||
|
(defn- fjtask [^Callable f]
|
||||||
|
(ForkJoinTask/adapt f))
|
||||||
|
|
||||||
|
(defn- fjinvoke
|
||||||
|
"For now, this still relies on clojure.core.reducers/pool which is
|
||||||
|
public but undocumented."
|
||||||
|
[f]
|
||||||
|
(if (ForkJoinTask/inForkJoinPool)
|
||||||
|
(f)
|
||||||
|
(.invoke ^ForkJoinPool @r/pool ^ForkJoinTask (fjtask f))))
|
||||||
|
|
||||||
|
(defn- fjfork [task] (.fork ^ForkJoinTask task))
|
||||||
|
|
||||||
|
(defn- fjjoin [task] (.join ^ForkJoinTask task))
|
||||||
|
|
||||||
(defn- fold-stmt
|
(defn- fold-stmt
|
||||||
"Execute the `PreparedStatement`, attempt to get either its `ResultSet` or
|
"Execute the `PreparedStatement`, attempt to get either its `ResultSet` or
|
||||||
its generated keys (as a `ResultSet`), and fold that using the supplied
|
its generated keys (as a `ResultSet`), and fold that using the supplied
|
||||||
|
|
@ -614,27 +633,27 @@
|
||||||
[^PreparedStatement stmt n combinef reducef connectable opts]
|
[^PreparedStatement stmt n combinef reducef connectable opts]
|
||||||
(if-let [rs (stmt->result-set stmt opts)]
|
(if-let [rs (stmt->result-set stmt opts)]
|
||||||
(let [rs-map (mapify-result-set rs opts)
|
(let [rs-map (mapify-result-set rs opts)
|
||||||
chunk (fn [batch] (#'r/fjtask #(r/reduce reducef (combinef) batch)))
|
chunk (fn [batch] (fjtask #(r/reduce reducef (combinef) batch)))
|
||||||
realize (fn [row] (datafiable-row row connectable opts))]
|
realize (fn [row] (datafiable-row row connectable opts))]
|
||||||
(loop [batch [] task nil]
|
(loop [batch [] task nil]
|
||||||
(if (.next rs)
|
(if (.next rs)
|
||||||
(if (= n (count batch))
|
(if (= n (count batch))
|
||||||
(recur [(realize rs-map)]
|
(recur [(realize rs-map)]
|
||||||
(let [t (#'r/fjfork (chunk batch))]
|
(let [t (fjfork (chunk batch))]
|
||||||
(if task
|
(if task
|
||||||
(#'r/fjfork
|
(fjfork
|
||||||
(#'r/fjtask #(combinef (#'r/fjjoin task)
|
(fjtask #(combinef (fjjoin task)
|
||||||
(#'r/fjjoin t))))
|
(fjjoin t))))
|
||||||
t)))
|
t)))
|
||||||
(recur (conj batch (realize rs-map)) task))
|
(recur (conj batch (realize rs-map)) task))
|
||||||
(if (seq batch)
|
(if (seq batch)
|
||||||
(let [t (#'r/fjfork (chunk batch))]
|
(let [t (fjfork (chunk batch))]
|
||||||
(#'r/fjinvoke
|
(fjinvoke
|
||||||
#(combinef (if task (#'r/fjjoin task) (combinef))
|
#(combinef (if task (fjjoin task) (combinef))
|
||||||
(#'r/fjjoin t))))
|
(fjjoin t))))
|
||||||
(if task
|
(if task
|
||||||
(#'r/fjinvoke
|
(fjinvoke
|
||||||
#(combinef (combinef) (#'r/fjjoin task)))
|
#(combinef (combinef) (fjjoin task)))
|
||||||
(combinef))))))
|
(combinef))))))
|
||||||
(reducef (combinef) {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
(reducef (combinef) {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
||||||
|
|
||||||
|
|
@ -680,27 +699,27 @@
|
||||||
[^Statement stmt sql n combinef reducef connectable opts]
|
[^Statement stmt sql n combinef reducef connectable opts]
|
||||||
(if-let [rs (stmt-sql->result-set stmt sql)]
|
(if-let [rs (stmt-sql->result-set stmt sql)]
|
||||||
(let [rs-map (mapify-result-set rs opts)
|
(let [rs-map (mapify-result-set rs opts)
|
||||||
chunk (fn [batch] (#'r/fjtask #(r/reduce reducef (combinef) batch)))
|
chunk (fn [batch] (fjtask #(r/reduce reducef (combinef) batch)))
|
||||||
realize (fn [row] (datafiable-row row connectable opts))]
|
realize (fn [row] (datafiable-row row connectable opts))]
|
||||||
(loop [batch [] task nil]
|
(loop [batch [] task nil]
|
||||||
(if (.next rs)
|
(if (.next rs)
|
||||||
(if (= n (count batch))
|
(if (= n (count batch))
|
||||||
(recur [(realize rs-map)]
|
(recur [(realize rs-map)]
|
||||||
(let [t (#'r/fjfork (chunk batch))]
|
(let [t (fjfork (chunk batch))]
|
||||||
(if task
|
(if task
|
||||||
(#'r/fjfork
|
(fjfork
|
||||||
(#'r/fjtask #(combinef (#'r/fjjoin task)
|
(fjtask #(combinef (fjjoin task)
|
||||||
(#'r/fjjoin t))))
|
(fjjoin t))))
|
||||||
t)))
|
t)))
|
||||||
(recur (conj batch (realize rs-map)) task))
|
(recur (conj batch (realize rs-map)) task))
|
||||||
(if (seq batch)
|
(if (seq batch)
|
||||||
(let [t (#'r/fjfork (chunk batch))]
|
(let [t (fjfork (chunk batch))]
|
||||||
(#'r/fjinvoke
|
(fjinvoke
|
||||||
#(combinef (if task (#'r/fjjoin task) (combinef))
|
#(combinef (if task (fjjoin task) (combinef))
|
||||||
(#'r/fjjoin t))))
|
(fjjoin t))))
|
||||||
(if task
|
(if task
|
||||||
(#'r/fjinvoke
|
(fjinvoke
|
||||||
#(combinef (combinef) (#'r/fjjoin task)))
|
#(combinef (combinef) (fjjoin task)))
|
||||||
(combinef))))))
|
(combinef))))))
|
||||||
(reducef (combinef) {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
(reducef (combinef) {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue