Skip to content

Commit 9c337d6

Browse files
committed
Update HikariCP to 7.0.2
1 parent 1468ba4 commit 9c337d6

File tree

5 files changed

+95
-13
lines changed

5 files changed

+95
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## unreleased
22

3+
* updated `HikariCP` to `7.0.2`
4+
* bumped Clojure dependency to `1.12.4`
5+
36
## 3.3.0
47

58
* updated `HikariCP` to `6.3.1`

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You'll also need to add the JDBC driver needed for your database.
3030
| `:maximum-pool-size` | No | `10` | This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend. |
3131
| `:pool-name` | No | Auto-generated | This property represents a user-defined name for the connection pool and appears mainly in logging and JMX management consoles to identify pools and pool configurations. |
3232
| `:jdbc-url` | **Yes¹** | None | This property sets the JDBC connection URL. Please note the `h2` adapter expects `:url` instead of `:jdbc-url`. |
33-
| `:driver-class-name` | No | None | This property sets the JDBC driver class. |
33+
| `:driver-class-name` | No | None | This property sets the JDBC driver class. The class must exist on the classpath and implement `java.sql.Driver`. Note: Do not use DataSource class names here (e.g., use `org.postgresql.Driver`, not `org.postgresql.ds.PGSimpleDataSource`). |
3434
| `:adapter` | **Yes¹** | None | This property sets the database adapter. Please check [Adapters and corresponding datasource class names](#adapters-and-corresponding-datasource-class-names) for the full list of supported adapters and their datasource class names. The value should be provided as a string. |
3535
| `:username` | No | None | This property sets the default authentication username used when obtaining Connections from the underlying driver. |
3636
| `:password` | No | None | This property sets the default authentication password used when obtaining Connections from the underlying driver. |
@@ -245,7 +245,7 @@ Custom translations of properties can be added by extending the
245245
:max-lifetime 300000
246246
:pool-name "clickhouse-conn-pool"})
247247

248-
(defonce datasource
248+
(defonce datasource
249249
(delay (make-datasource datasource-options)))
250250

251251
(defn -main
@@ -283,7 +283,7 @@ Custom translations of properties can be added by extending the
283283
(close-datasource @datasource))
284284
```
285285

286-
### Notice
286+
## Notice
287287

288288
`make-datasource` will throw `IllegalArgumentException` when invalid
289289
arguments are provided:
@@ -293,8 +293,43 @@ arguments are provided:
293293
;; IllegalArgumentException: Invalid configuration options: (:username :database-name)
294294
```
295295

296+
`make-datasource` will also validate that the `:driver-class-name` (if provided) is a valid JDBC Driver class:
297+
298+
```clojure
299+
(make-datasource {:jdbc-url "jdbc:postgresql://localhost:5432/test"
300+
:driver-class-name "org.postgresql.ds.PGSimpleDataSource"})
301+
;; IllegalArgumentException: "org.postgresql.ds.PGSimpleDataSource" - failed: valid-driver-class?
302+
;; This class is a DataSource, not a Driver. Use "org.postgresql.Driver" instead.
303+
```
304+
305+
The driver class must:
306+
- Exist on the classpath
307+
- Implement the `java.sql.Driver` interface
308+
- Not be a DataSource class (DataSource classes should use `:datasource` or `:datasource-class-name` instead)
309+
310+
## Troubleshooting
311+
312+
### Driver class validation errors
313+
314+
If you receive an error like `"failed: valid-driver-class?"`, check that:
315+
316+
1. **The JDBC driver is in your dependencies** - Make sure you've added the appropriate JDBC driver to your `project.clj` or `deps.edn`
317+
2. **You're using a Driver class, not a DataSource class** - Common mistake:
318+
- ❌ Wrong: `"org.postgresql.ds.PGSimpleDataSource"` (this is a DataSource)
319+
- ✅ Correct: `"org.postgresql.Driver"` (this is a Driver)
320+
3. **The class name is spelled correctly** - Check the documentation for your specific JDBC driver
321+
322+
### Common driver class names
323+
324+
| Database | Correct Driver Class Name | Common Mistake (DataSource) |
325+
|------------|----------------------------------|------------------------------------------|
326+
| PostgreSQL | `org.postgresql.Driver` | `org.postgresql.ds.PGSimpleDataSource` |
327+
| MySQL | `com.mysql.cj.jdbc.Driver` | `com.mysql.cj.jdbc.MysqlDataSource` |
328+
| H2 | `org.h2.Driver` | `org.h2.jdbcx.JdbcDataSource` |
329+
| SQLite | `org.sqlite.JDBC` | `org.sqlite.SQLiteDataSource` |
330+
296331
## License
297332

298-
Copyright © 2014 - 2024 [Tomek Wałkuski](https://github.com/tomekw) and [Jan Stępień](https://github.com/jstepien)
333+
Copyright © 2014 [Tomek Wałkuski](https://github.com/tomekw) and [Jan Stępień](https://github.com/jstepien)
299334

300335
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

project.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:scm {:name "git"
77
:url "https://github.com/tomekw/hikari-cp"}
8-
:dependencies [[org.clojure/clojure "1.11.3" :scope "provided"]
8+
:dependencies [[org.clojure/clojure "1.12.4" :scope "provided"]
99
[org.tobereplaced/lettercase "1.0.0"]
10-
[com.zaxxer/HikariCP "6.3.1"]]
10+
[com.zaxxer/HikariCP "7.0.2"]]
1111
:deploy-repositories [["clojars" {:sign-releases false :url "https://clojars.org/repo"}]]
1212
:profiles {:dev {:dependencies [[org.slf4j/slf4j-nop "2.0.17"]
1313
[org.clojure/java.jdbc "0.7.12"]
14+
[com.h2database/h2 "2.4.240"]
1415
[mysql/mysql-connector-java "8.0.33"]
15-
[org.neo4j.driver/neo4j-java-driver "5.28.9"]
16-
[org.postgresql/postgresql "42.7.7"]
17-
[io.dropwizard.metrics/metrics-core "4.2.33"]
18-
[io.dropwizard.metrics/metrics-healthchecks "4.2.33"]
16+
[org.neo4j.driver/neo4j-java-driver "6.0.2"]
17+
[org.postgresql/postgresql "42.7.8"]
18+
[io.dropwizard.metrics/metrics-core "4.2.37"]
19+
[io.dropwizard.metrics/metrics-healthchecks "4.2.37"]
1920
[io.prometheus/simpleclient "0.16.0"]
2021

2122
; The Oracle driver is only accessible from maven.oracle.com

src/hikari_cp/core.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,22 @@
130130
(s/def ::jdbc-url
131131
string?)
132132

133+
(defn- valid-driver-class?
134+
"Returns true if the class name is a valid JDBC Driver class.
135+
Checks that:
136+
1. The class exists on the classpath
137+
2. The class implements java.sql.Driver interface"
138+
[class-name]
139+
(try
140+
(let [clazz (Class/forName class-name)]
141+
(.isAssignableFrom java.sql.Driver clazz))
142+
(catch ClassNotFoundException _
143+
false)
144+
(catch Exception _
145+
false)))
146+
133147
(s/def ::driver-class-name
134-
string?)
148+
(s/and string? valid-driver-class?))
135149

136150
(s/def ::jdbc-url-options
137151
(s/keys :req-un [::jdbc-url]

test/hikari_cp/core_test.clj

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:transaction-isolation "TRANSACTION_SERIALIZABLE"})
2929

3030
(def alternate-valid-options
31-
{:driver-class-name "org.postgresql.ds.PGPoolingDataSource"
31+
{:driver-class-name "org.postgresql.Driver"
3232
:jdbc-url "jdbc:postgresql://localhost:5433/test"})
3333

3434
(def alternate-valid-options2
@@ -191,7 +191,7 @@
191191

192192
(deftest datasource-config-alternate-test
193193
(testing "driver class name with alternate options"
194-
(is (= "org.postgresql.ds.PGPoolingDataSource"
194+
(is (= "org.postgresql.Driver"
195195
(.getDriverClassName datasource-config-with-overrides-alternate))))
196196

197197
(testing "jdbc url with alternate options"
@@ -373,3 +373,32 @@
373373
(testing "translate-property is extensible"
374374
(defmethod translate-property ::extend-translate-test [_] 42)
375375
(is (= 42 (translate-property ::extend-translate-test)))))
376+
377+
(deftest driver-class-name-validation-test
378+
(testing "valid PostgreSQL driver class is accepted"
379+
(is (map? (validate-options (merge (dissoc valid-options :adapter)
380+
{:jdbc-url "jdbc:postgresql://localhost:5432/test"
381+
:driver-class-name "org.postgresql.Driver"})))))
382+
383+
(testing "valid MySQL driver class is accepted"
384+
(is (map? (validate-options (merge (dissoc valid-options :adapter)
385+
{:jdbc-url "jdbc:mysql://localhost:3306/test"
386+
:driver-class-name "com.mysql.cj.jdbc.Driver"})))))
387+
388+
(testing "DataSource class is rejected as driver class"
389+
(is (thrown? IllegalArgumentException
390+
(validate-options (merge (dissoc valid-options :adapter)
391+
{:jdbc-url "jdbc:postgresql://localhost:5432/test"
392+
:driver-class-name "org.postgresql.ds.PGSimpleDataSource"})))))
393+
394+
(testing "non-existent driver class is rejected"
395+
(is (thrown? IllegalArgumentException
396+
(validate-options (merge (dissoc valid-options :adapter)
397+
{:jdbc-url "jdbc:postgresql://localhost:5432/test"
398+
:driver-class-name "com.fake.NonExistentDriver"})))))
399+
400+
(testing "random class name that's not a driver is rejected"
401+
(is (thrown? IllegalArgumentException
402+
(validate-options (merge (dissoc valid-options :adapter)
403+
{:jdbc-url "jdbc:postgresql://localhost:5432/test"
404+
:driver-class-name "java.lang.String"}))))))

0 commit comments

Comments
 (0)