Skip to content

Commit 850b2af

Browse files
authored
#43 Read JDBC driver version via reflection (#46)
* #43 Read JDBC driver version via reflection * #43 Update changelog
1 parent 0993812 commit 850b2af

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

doc/changes/changes_1.0.1.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# metabase-driver 1.0.1, released 2022-05-??
1+
# metabase-driver 1.0.1, released 2022-05-30
22

33
Code name: Adapt to Metabase 0.43.1
44

55
## Summary
66

77
In this release we adapted the driver to Metabase version 0.43.1 and migrated the build system to deps.edn. This release was only tested with Metabase 0.43.1. If you use an older version of Metabase please use metabase-driver 1.0.0.
88

9-
Note: During implementation of #35 and #41 the logging of the version for the driver and the Exasol JDBC driver was removed. These features will be added again in [#40](https://github.com/exasol/metabase-driver/issues/40) and [#43](https://github.com/exasol/metabase-driver/issues/43).
10-
119
## Features
1210

1311
* #38: Adapted driver to Metabase version 0.43.0
@@ -17,3 +15,4 @@ Note: During implementation of #35 and #41 the logging of the version for the dr
1715
## Bugfixes
1816

1917
* #40: Implemented reading driver version from metabase-plugin.yaml
18+
* #43: Implemented reading JDBC driver version via reflection

src/metabase/driver/exasol.clj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@
2020
[metabase.util.i18n :refer [trs]]
2121
[yaml.core :as yaml]))
2222

23-
(defn get-jdbc-driver-version []
24-
"(unknown)") ; Will be implemented in https://github.com/exasol/metabase-driver/issues/43
23+
(defn- invoke-static-method
24+
"Invoke a static method via reflection"
25+
[class-name method-name]
26+
(let [class (java.lang.Class/forName class-name)
27+
method (.getMethod class method-name (make-array Class 0))
28+
result (.invoke method nil (make-array Object 0))]
29+
result))
30+
31+
(defn get-jdbc-driver-version
32+
"Get the JDBC driver's version number via reflection. This avoids having a runtime dependency on the driver"
33+
[]
34+
(try (invoke-static-method "com.exasol.jdbc.EXADriver" "getVersionInfo")
35+
(catch Exception e (log/warn (str "Error getting JDBC driver version: " e)))))
2536

2637
(defn get-driver-version
2738
"Reads the driver version from the plugin yaml file on the classpath."

test/metabase/driver/exasol_test.clj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
(ns metabase.driver.exasol-test
2-
(:require [clojure.test :refer [deftest testing is]]
2+
(:require [clojure.string :as str]
3+
[clojure.test :refer [deftest is testing]]
4+
[metabase.driver.exasol :as exasol]
5+
[metabase.query-processor :as qp]
6+
[metabase.query-processor-test :as qp.test]
7+
[metabase.query-processor-test.alternative-date-test :as alt-date-test]
38
[metabase.test :as mt]
4-
[metabase.test.util :as tu]
59
[metabase.test.data :as td]
610
[metabase.test.data.dataset-definitions :as dataset]
711
[metabase.test.data.exasol-dataset-definitions :as exasol-dataset]
8-
[metabase.query-processor :as qp]
9-
[metabase.query-processor-test :as qp.test]
10-
[metabase.query-processor-test.alternative-date-test :as alt-date-test])
12+
[metabase.test.util :as tu])
1113
(:import (java.util TimeZone)))
1214

15+
(deftest get-jdbc-driver-version-test
16+
(testing "Getting JDBC driver version succeeds"
17+
(is (not (str/blank? (exasol/get-jdbc-driver-version)))))
18+
(testing "Getting JDBC driver version returns expected value"
19+
(is (= "7.1.10" (exasol/get-jdbc-driver-version)))))
20+
1321
(deftest timezone-id-test
1422
(mt/test-driver :exasol
1523
(is (= "UTC"

test/metabase/driver/exasol_unit_test.clj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@
174174
(testing (format "Unprepare %s" (.getClass value))
175175
(is (= expected (unprepare/unprepare-value :exasol value))))))
176176

177-
(deftest get-jdbc-driver-version-test
178-
(testing "JDBC driver version is not empty"
179-
(is (not (str/blank? (exasol/get-jdbc-driver-version))))))
180-
181177
(deftest get-driver-version-test
182178
(testing "Reading driver version from non existing resource returns nil"
183179
(is (= nil (exasol/get-driver-version "non-existing-resource.yaml"))))

0 commit comments

Comments
 (0)