Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add with-transaction-config #39

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/neo4j_clj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ to your project?" {} t)))))
(finally
(.close ~tx)))))

;;; TODO other parameters:
;;; "SessionParameters{bookmarks=null, defaultAccessMode=WRITE, database='mydb', fetchSize=null, impersonatedUser=null, bookmarkManager=null}"
(defn db-session-config [db]
(-> (org.neo4j.driver.SessionConfig/builder)
(.withDatabase db)
(.build)))

(defn get-session-config [^Driver connection config]
(.session (:db connection) config))

;;; A modified version of with-transaction that takes a config (can generate with db-session-config)
(defmacro with-transaction-config [connection config tx & body]
`(with-open [~tx (transaction (get-session-config ~connection ~config))]
(try
(let [r# (do ~@body)]
(.commit ~tx)
r#)
(finally
(.close ~tx)))))

(defmacro with-retry [[connection tx & {:keys [max-times] :or {max-times 1000}}] & body]
`(retry-times ~max-times
(fn []
Expand Down