Skip to content

niwinz/clojure.jdbc-dbcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clojure.jdbc-dbcp

Apache Commons JDBC connection pool implementation for clojure.jdbc.

Note: only works on >= jdk7

Install

Leiningen

[clojure.jdbc/clojure.jdbc-dbcp "0.3.2"]

Gradle

compile "clojure.jdbc:clojure.jdbc-dbcp:0.3.2"

Maven

<dependency>
  <groupId>clojure.jdbc</groupId>
  <artifactId>clojure.jdbc-dbcp</artifactId>
  <version>0.3.2</version>
</dependency>

Doc

In order to use a connection pool, you should convert your plain dbspec into a datasource-dbspec using the helper function provided in each extension.

Example using DBCP connection pool
;; Import the desired implementation
(require '[jdbc.pool.dbcp :as pool])

;; Convert the standard dbspec to an other dbspec with `:datasource` key
(def dbspec (pool/make-datasource-spec {:subprotocol "postgresql"
                                        :subname "//localhost:5432/dbname"}))

Now, dbspec should be used like a plain dbspec for creating connections.

Configuration options

DBCP comes with "good" defaults that should work in majority standard environments, but obviously, it exposes set of options for customize it:

Option Description

:min-pool-size

Minimum number of Connections a pool will maintain at any given time.

:max-pool-size

Maximum number of Connections a pool will maintain at any given time.

:initial-pool-size

Number of Connections a pool will try to acquire upon startup.

:max-wait

The number of milliseconds a client calling getConnection() will wait for a Connection to be checked-in or acquired when the pool is exhausted.

:max-connection-lifetime

The maximum lifetime in milliseconds of a connection.

:test-connection-query

The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. If not specified, connections will be validation by calling the isValid() method.

:test-connection-on-borrow

The indication of whether objects will be validated before being borrowed from the pool.

:test-connection-on-return

The indication of whether objects will be validated before being returned to the pool.

:test-idle-connections-period

The number of milliseconds to sleep between runs of the idle object evictor thread.

:max-connection-idle-lifetime

The minimum amount of time (in milliseconds) an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).

Additional notes

Since clojure.jdbc 0.4.0-beta1, packages like this is not the recommended way to setup the connection pool. It provides the basic setup. If you want more controll and access to all options, consider using the dbcp directly as documented in http://niwibe.github.io/clojure.jdbc/latest/#connection-pool

About

Apache commons DBCP (JDBC) connection pool implementation for clojure.jdbc

Resources

License

Stars

Watchers

Forks

Packages

No packages published