Skip to content
Snippets Groups Projects
Commit e959e93b authored by Cam Saül's avatar Cam Saül
Browse files

Finish removing korma from main part of codebase :honey_pot:

parent 9ad9ca97
No related branches found
No related tags found
No related merge requests found
......@@ -135,39 +135,53 @@
;;; | DB CONNECTION / TRANSACTION STUFF |
;;; +------------------------------------------------------------------------------------------------------------------------+
(set! *warn-on-reflection* true)
(defn connection-pool
"Create a connection pool for the given database spec."
[{:keys [subprotocol subname classname], :as spec}]
[{:keys [subprotocol
subname
classname
excess-timeout
idle-timeout
initial-pool-size
minimum-pool-size
maximum-pool-size
test-connection-query
idle-connection-test-period
test-connection-on-checkin
test-connection-on-checkout]
:or {excess-timeout (* 30 60)
idle-timeout (* 3 60 60)
initial-pool-size 3
minimum-pool-size 3
maximum-pool-size 15
test-connection-query nil
idle-connection-test-period 0
test-connection-on-checkin false
test-connection-on-checkout false}
:as spec}]
{:datasource (doto (ComboPooledDataSource.)
(.setDriverClass classname)
(.setJdbcUrl (str "jdbc:" subprotocol ":" subname))
(.setMaxIdleTimeExcessConnections (* 30 60))
(.setMaxIdleTime (* 3 60 60))
(.setInitialPoolSize 3)
(.setMinPoolSize 3)
(.setMaxPoolSize 15)
(.setIdleConnectionTestPeriod 0)
(.setTestConnectionOnCheckin false)
(.setTestConnectionOnCheckout false)
(.setPreferredTestQuery nil)
(.setProperties (u/prog1 (java.util.Properties.)
(doseq [[k v] (dissoc spec
:make-pool? :classname :subprotocol :subname
:naming :delimiters :alias-delimiter
:excess-timeout :idle-timeout
:initial-pool-size :minimum-pool-size :maximum-pool-size
:test-connection-query
:idle-connection-test-period
:test-connection-on-checkin
:test-connection-on-checkout)]
(.setProperty <> (name k) (str v))))))})
(defn delay-pool
"Return a delay for creating a connection pool for the given spec."
[spec]
(delay (connection-pool spec)))
(.setDriverClass classname)
(.setJdbcUrl (str "jdbc:" subprotocol ":" subname))
(.setMaxIdleTimeExcessConnections excess-timeout)
(.setMaxIdleTime idle-timeout)
(.setInitialPoolSize initial-pool-size)
(.setMinPoolSize minimum-pool-size)
(.setMaxPoolSize maximum-pool-size)
(.setIdleConnectionTestPeriod idle-connection-test-period)
(.setTestConnectionOnCheckin test-connection-on-checkin)
(.setTestConnectionOnCheckout test-connection-on-checkout)
(.setPreferredTestQuery test-connection-query)
(.setProperties (u/prog1 (java.util.Properties.)
(doseq [[k v] (dissoc spec
:make-pool? :classname :subprotocol :subname
:naming :delimiters :alias-delimiter
:excess-timeout :idle-timeout
:initial-pool-size :minimum-pool-size :maximum-pool-size
:test-connection-query
:idle-connection-test-period
:test-connection-on-checkin
:test-connection-on-checkout)]
(.setProperty <> (name k) (str v))))))})
(defn create-db
"Create a db connection object manually instead of using defdb. This is often
......@@ -179,7 +193,7 @@
If the spec includes `:make-pool? true` makes a connection pool from the spec."
[spec]
{:pool (if (:make-pool? spec)
(delay-pool spec)
(delay (connection-pool spec))
spec)})
(def _connection
......
......@@ -5,13 +5,13 @@
[clojure.tools.logging :as log]
(honeysql [core :as hsql]
[format :as hformat])
[korma.db :as kdb]
[metabase.driver :as driver]
[metabase.sync-database.analyze :as analyze]
metabase.query-processor.interface
(metabase [db :as db]
[driver :as driver])
(metabase.models [field :as field]
raw-table
[table :as table])
metabase.query-processor.interface
[metabase.sync-database.analyze :as analyze]
[metabase.util :as u]
[metabase.util.honeysql-extensions :as hx])
(:import java.sql.DatabaseMetaData
......@@ -117,11 +117,12 @@
[{:keys [id engine details]}]
(log/debug (u/format-color 'magenta "Creating new connection pool for database %d ..." id))
(let [spec (connection-details->spec (driver/engine->driver engine) details)]
(kdb/connection-pool (assoc spec :minimum-pool-size 1
;; prevent broken connections closed by dbs by testing them every 3 mins
:idle-connection-test-period (* 3 60)
;; prevent overly large pools by condensing them when connections are idle for 15m+
:excess-timeout (* 15 60)))))
(db/connection-pool (assoc spec
:minimum-pool-size 1
;; prevent broken connections closed by dbs by testing them every 3 mins
:idle-connection-test-period (* 3 60)
;; prevent overly large pools by condensing them when connections are idle for 15m+
:excess-timeout (* 15 60)))))
(defn- notify-database-updated
"We are being informed that a DATABASE has been updated, so lets shut down the connection pool (if it exists) under
......
(ns metabase.models.interface
(:require [clojure.tools.logging :as log]
[cheshire.core :as json]
[korma.core :as k]
(metabase [config :as config]
[util :as u])
[metabase.models.common :as common]))
......@@ -296,7 +295,6 @@
:arglists ''([] [id] [& kvs])
:doc (or docstr
(format "Entity for '%s' table; instance of %s." (name table-name) instance)))
(-> (k/create-entity ~(name entity))
(k/table ~table-name)
(assoc ::entity true)
~map->instance)))))
(~map->instance {:table ~table-name
:name ~(name entity)
::entity true})))))
......@@ -6,8 +6,6 @@
(honeysql [core :as hsql]
[format :as hformat]
[helpers :as h])
(korma [core :as k]
[db :as kdb])
[medley.core :as m]
[metabase.driver :as driver]
[metabase.driver.generic-sql :as sql]
......
......@@ -3,8 +3,7 @@
;; TODO - rework this namespace to use `u/drop-first-arg` where appropriate
(:require [clojure.core.reducers :as r]
[clojure.string :as s]
(korma [core :as k]
[db :as kdb])
[metabase.db.spec :as dbspec]
metabase.driver.h2
(metabase.test.data [generic-sql :as generic]
[interface :as i])
......@@ -66,7 +65,7 @@
(merge mixin
{:create-db-sql (constantly create-db-sql)
:create-table-sql create-table-sql
:database->spec (comp kdb/h2 i/database->connection-details) ; Don't use the h2 driver implementation, which makes the connection string read-only & if-exists only
:database->spec (comp dbspec/h2 i/database->connection-details) ; Don't use the h2 driver implementation, which makes the connection string read-only & if-exists only
:drop-db-if-exists-sql (constantly nil)
:execute-sql! (fn [this _ dbdef sql]
;; we always want to use 'server' context when execute-sql! is called
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment