Commits

Shantanu Kumar committed d0dbdc5

add :fetch-size and query-timeout keys to default dbspec,
add support for olumn collection in `clj-to-db`

Comments (0)

Files changed (3)

 * [TODO] More introspection fns
 
 
+## 0.3 / 2011-July-??
+
+* Support for column names collection in `clj-to-db`
+* Additional keys in spec
+  * :fetch-size     Number of rows to fetch in one DB roundtrip (default 1000)
+  * :query-timeout  Query timeout in seconds (depends on JDBC driver and DB)
+
+
 ## 0.2 / 2011-Apr-01
 
 * Default spec as a static var `default-dbspec`
   <groupId>org.bituf</groupId>
   <artifactId>clj-dbspec</artifactId>
   <packaging>jar</packaging>
-  <version>0.2</version>
+  <version>0.3-SNAPSHOT</version>
   <name>Clj-DBSpec</name>
   <description>
 Clj-DBSpec is a common configuration spec for dealing with relational databases
     <dependency>
       <groupId>org.clojure</groupId>
       <artifactId>clojure</artifactId>
-      <version>1.2.0</version>
+      <version>1.3.0-beta1</version>
       <optional>true</optional>
     </dependency>
     <!--
       <plugin>
         <groupId>com.theoryinpractise</groupId>
         <artifactId>clojure-maven-plugin</artifactId>
-        <version>1.3.6</version>
+        <version>1.3.7</version>
         <executions>
           <execution>
             <id>compile</id>

src/main/clj/org/bituf/clj_dbspec.clj

   "DB-Spec related functions and vars to provide only the building blocks.
   Usually only libraries would use this."
   (:import
-    (java.util            List)
+    (java.util            List Properties)
     (java.sql             Connection DatabaseMetaData DriverManager ResultSet)
     (javax.sql            DataSource)
     (org.bituf.clj_dbspec WriteNotAllowedException))
   (:require
+    [clojure.set]
     [clojure.string :as sr]
     [clojure.pprint :as pp]
     [org.bituf.clj-dbspec.internal :as in]))
 
 
 (def ^{:doc "Clj-DBSpec version (only major and minor)"}
-      version [0 2])
+      version [0 3])
 
 
 (defn ^Connection make-connection
 
 (def ^{:doc "Default dbspec; see also: *dbspec*"} default-dbspec
   (array-map
-   :datasource  nil
-   :connection  nil
-   :dbmetadata  (array-map)
-   :catalog     nil
-   :schema      nil
-   :read-only   false
-   :show-sql    true
-   :show-sql-fn (fn [^String sql] (println sql))
-   :clj-to-db   (fn [iden]
-                  (if (string? iden) iden
-                    (apply str (replace {\- \_}
-                                 (in/as-string iden)))))
-   :db-to-clj   (fn [^String iden]
-                  (keyword (apply str (replace {\_ \-}
-                                        (sr/lower-case iden)))))))
+   :datasource    nil
+   :connection    nil
+   :dbmetadata    (array-map)
+   :catalog       nil
+   :schema        nil
+   :read-only     false
+   :show-sql      true
+   :show-sql-fn   (fn [^String sql] (pp/pprint sql))
+   :clj-to-db     (fn c2d [iden]
+                    (cond
+                      (string? iden) iden
+                      (coll?   iden) (into [] (map c2d iden))
+                      :else          (apply str (replace {\- \_}
+                                                         (in/as-string iden)))))
+   :db-to-clj     (fn [^String iden]
+                    (keyword (apply str (replace {\_ \-}
+                                          (sr/lower-case iden)))))
+   :fetch-size    1000
+   :query-timeout 0))
 
 
 (def ^{:doc "Database configuration specification - map of values with the following
   Well-known keys:
-    :datasource  (javax.sql.DataSource, default: nil)
-                  1. When you rebind this var with :datasource you SHOULD also
-                     include a cached :dbmetadata value.
-                  2. Everytime a connection is taken from the datasource you
-                     SHOULD re-bind this var to include the :connection object.
-    :connection  (java.sql.Connection, default: nil)
-                  1. If the connection is not taken from a datasource you SHOULD
-                     include a cached :dbmetadata value while re-binding.
-    :dbmetadata  (map, default: empty map)
-                  1. This is usually result of dbmeta function.
-    :catalog     (Clojure form - String, Keyword etc.; default nil)
-                  1. Catalog name - SHOULD be converted using db-iden
-    :schema      (Clojure form - String, Keyword etc.; default nil)
-                  1. Schema name - SHOULD be converted using db-iden
-    :read-only   (Boolean default false)
-                  1. If true, all READ operations should execute as usual and
-                     all WRITE operations should throw WriteNotAllowedException.
-                  2. I false, both READ and WRITE operations execute fine
-    :show-sql    (Boolean default true)
-                  1. If true, SQL statements should be printed.
-    :show-sql-fn (function, default: to print SQL statement using `println`)
-                  You may like to rebind this to fn that prints via a logger
-    :clj-to-db   (function, default: to string, replace '-' => '_')
-                  1. Dictates how are identifiers converted from Clojure to
-                     the Database.
-                  2. The default value is the least common denominator that
-                     works with most databases. Override as necessary.
-    :db-to-clj   (function, default: to lower-case keyword, replace '_' => '-')
-                  1. Dictates how are identifiers are converted from the
-                     Database to Clojure.
-                  2. The default value is the least common denominator that
-                     works with most databases. Override as necessary.
+    :datasource    (javax.sql.DataSource, default: nil)
+                    1. When you rebind this var with :datasource you SHOULD also
+                       include a cached :dbmetadata value.
+                    2. Everytime a connection is taken from the datasource you
+                       SHOULD re-bind this var to include the :connection object.
+    :connection    (java.sql.Connection, default: nil)
+                    1. If the connection is not taken from a datasource you SHOULD
+                       include a cached :dbmetadata value while re-binding.
+    :dbmetadata    (map, default: empty map)
+                    1. This is usually result of dbmeta function.
+    :catalog       (Clojure form - String, Keyword etc.; default nil)
+                    1. Catalog name - SHOULD be converted using db-iden
+    :schema        (Clojure form - String, Keyword etc.; default nil)
+                    1. Schema name - SHOULD be converted using db-iden
+    :read-only     (Boolean default false)
+                    1. If true, all READ operations should execute as usual and
+                       all WRITE operations should throw WriteNotAllowedException.
+                    2. I false, both READ and WRITE operations execute fine
+    :show-sql      (Boolean default true)
+                    1. If true, SQL statements should be printed.
+    :show-sql-fn   (function, default: to print SQL statement using `println`)
+                    You may like to rebind this to fn that prints via a logger
+    :clj-to-db     (function, default: to string, replace '-' => '_')
+                    1. Dictates how are identifiers converted from Clojure to
+                       the Database.
+                    2. The default value is the least common denominator that
+                       works with most databases. Override as necessary.
+    :db-to-clj     (function, default: to lower-case keyword, replace '_' => '-')
+                    1. Dictates how are identifiers are converted from the
+                       Database to Clojure.
+                    2. The default value is the least common denominator that
+                       works with most databases. Override as necessary.
+    :fetch-size    (Integer, default: 1000)
+                    1. Number of rows to fetch per DB roundtrip. Helps throttle
+                       as well as optimize large DB reads. 0 means unlimited.
+    :query-timeout (Integer, default: 0)
+                    1. Number of seconds to wait for query to execute, after
+                       which timeout occurs raising SqlException. Not all JDBC
+                       drivers support this so check driver manual before use.
 
   Libraries MAY expose their own API to re-bind this var to new values - they
   MUST NOT alter the type/semantics of the well-defined keys. They MAY introduce