Permalink
Browse files

Changed the behavior of open-global to be safe if there's no :unsafe …

…key.
  • Loading branch information...
1 parent 7a815a3 commit ee1219c4f9b3b74e7cd10bb912d372379d2c0ce0 @budu budu committed Aug 20, 2011
Showing with 10 additions and 10 deletions.
  1. +8 −8 src/lobos/connectivity.clj
  2. +2 −2 test/lobos/test/connectivity.clj
View
@@ -85,22 +85,22 @@
If a global connection by that name already exists and the db-spec is
safe (see below), then an exeption will be thrown. When the db-spec is
- not safe it will be closed if the old db-spec is different and the
+ unsafe it will be closed if the old db-spec is different and the
original connection is left untouched.
- A safe db-spec is a a map containing a :safe key set to a non-false
- value."
+ A safe db-spec is a map that does not contain an :unsafe key set to a
+ truthful value."
([db-spec] (open-global :default-connection db-spec))
([connection-name db-spec]
(if-let [cnx (connection-name @global-connections)]
- (if (:safe (:db-spec cnx))
+ (if (:unsafe (:db-spec cnx))
+ (when-not (= (:db-spec cnx) db-spec)
+ (close-global connection-name)
+ (open-global* connection-name db-spec))
(throw
(Exception.
(format "A global connection by that name already exists (%s)"
- connection-name)))
- (when-not (= (:db-spec cnx) db-spec)
- (close-global connection-name)
- (open-global* connection-name db-spec)))
+ connection-name))))
(open-global* connection-name db-spec))))
;; -----------------------------------------------------------------------------
@@ -34,10 +34,10 @@
(close-global :foo)
(is (= @global-connections {})
"Closing a named global connection")
+ (open-global :foo {:unsafe true})
(open-global :foo {})
- (open-global :foo {:safe true})
(is (= @global-connections
- {:foo {:connection *cnx* :db-spec {:safe true}}})
+ {:foo {:connection *cnx* :db-spec {}}})
"Re-opening a named global connection")
(is (thrown? Exception
(open-global :foo nil))

0 comments on commit ee1219c

Please sign in to comment.