 The database handle is only valid for the dynamic scope of the call,
 so nothing should be returned that is bound to database results."
   [& forms]
-  `(sql/with-connection (.getConnection *bonecp*)
+  `(sql/with-connection {:datasource *bonecp*}
      ~@forms))

BoneCP is internally thread-safe, so no internal locking is required.

The global is initialized during servlet setup, and will be torn down
again during servlet destruction."}
  *bonecp*)

(defn- new-connection-pool-instance
  "Create a new connection pool for the SCF database, configured appropriately,

    (when username (.setUsername config username))
    (when password (.setPassword config password))
    ;; ...aaand, create the pool.
    (BoneCPDataSource. config)))

(defn- replace-bonecp
  "Replace the current BoneCP var root instance, shutting down the
previous instance, if any.  For use with `alter-var-root'."
  [new]
  (log/debug (format "Replacing %s with %s" *bonecp* new))
  (alter-var-root (var *bonecp*) (fn [old]
                                   (when old (.close old))
                                   new)))

(defn initialize-connection-pool
  "Initialize the connection pool with a new object.  This will shut down
any existing connection pool."
  []
  (replace-bonecp (new-connection-pool-instance *db*)))

(defn shutdown-connection-pool
  "Shut down the current connection pool entirely."
  []
  (replace-bonecp nil))

(defmacro with-scf-connection
  "Run enclosed forms with an SQL connection established to the SCF
