Commits

Anonymous committed 360a7fc

api and unit tests for setting custom parameters on datasource

Comments (0)

Files changed (2)

src/main/clj/org/bituf/clj_dbcp.clj

   :classname :url :username :password)
 
 
+(defn set-max-active!
+  "Set max active connections at a time in the pool. You should call this before
+  creating any connection from the datasource."
+  [^BasicDataSource datasource max-active]
+  (doto datasource
+    (.setMaxActive max-active))
+  datasource)
+
+
+(defn set-min-max-idle!
+  "Set min and max idle connections count in the pool. You should call this
+  before creating any connection from the datasource."
+  [^BasicDataSource datasource min-idle max-idle]
+  (doto datasource
+    (.setMinIdle min-idle)
+    (.setMaxIdle max-idle))
+  datasource)
+
+
 (defn set-validation-query!
-  "Sets validation query for the datasource. You must call this *before*
+  "Set validation query for the datasource. You must call this *before*
   creating any connection from the datasource."
   [^BasicDataSource datasource ^String validation-query]
   (doto datasource

src/test/clj/org/bituf/test_clj_dbcp.clj

 (ns org.bituf.test-clj-dbcp
   (:use org.bituf.clj-dbcp)
-  (:use org.bituf.clj-dbcp.util)
+  (:use org.bituf.clj-argutil)
   (:use org.bituf.dbserver-util)
   (:use [clojure.contrib.sql :as sql :only ()])
   (:use clojure.contrib.java-utils)
 
 
 (deftest test-mysql
-  (if (true-value? (:mysql.testconn dbcred))
+  (if (is-true? (:mysql.testconn dbcred))
     (test-network-datasource "mysql" mysql-datasource)
     (fail "MySQL not tested")))
 
 
 (deftest test-pgsql
-  (if (true-value? (:pgsql.testconn dbcred))
+  (if (is-true? (:pgsql.testconn dbcred))
     (test-network-datasource "pgsql" pgsql-datasource)
     (fail "PostgreSQL not tested")))
 
        (catch org.apache.commons.dbcp.SQLNestedException ~'_))))
 
 
-(deftest untested-datasources
+(deftest smoketest-untested-datasources
   ;; Oracle
   (ig (oracle-datasource "localhost" "cljdbcp" "root" "root"))
   ;; IBM DB2
   (ig (sybase-datasource "localhost" "root" "root"))) ; no database name
 
 
+(deftest test-custom-datasource-parameters
+  (test-datasource
+    (let [ds (h2-memory-datasource)]
+      ;; set custom validation query
+      (set-validation-query! ds "SELECT 1;")
+      ;; set maximum number of active connections on the datasource at a time
+      (set-max-active! ds 15)
+      ;; set minimum and maximum number of idle connections on the datasource
+      (set-min-max-idle! ds 3 8)
+      ds)))
+
+
 (defn test-ns-hook []
   (test-derby)
   (test-h2)
   (test-hsql)
   (test-mysql)
   (test-pgsql)
-  (untested-datasources)
-  (test-jndi))
+  (smoketest-untested-datasources)
+  (test-jndi)
+  (test-custom-datasource-parameters))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.