Skip to content

Commit

Permalink
#43 Read JDBC driver version via reflection (#46)
Browse files Browse the repository at this point in the history
* #43 Read JDBC driver version via reflection

* #43 Update changelog
  • Loading branch information
kaklakariada authored May 30, 2022
1 parent 0993812 commit 850b2af
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
5 changes: 2 additions & 3 deletions doc/changes/changes_1.0.1.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# metabase-driver 1.0.1, released 2022-05-??
# metabase-driver 1.0.1, released 2022-05-30

Code name: Adapt to Metabase 0.43.1

## Summary

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.

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).

## Features

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

* #40: Implemented reading driver version from metabase-plugin.yaml
* #43: Implemented reading JDBC driver version via reflection
15 changes: 13 additions & 2 deletions src/metabase/driver/exasol.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
[metabase.util.i18n :refer [trs]]
[yaml.core :as yaml]))

(defn get-jdbc-driver-version []
"(unknown)") ; Will be implemented in https://github.com/exasol/metabase-driver/issues/43
(defn- invoke-static-method
"Invoke a static method via reflection"
[class-name method-name]
(let [class (java.lang.Class/forName class-name)
method (.getMethod class method-name (make-array Class 0))
result (.invoke method nil (make-array Object 0))]
result))

(defn get-jdbc-driver-version
"Get the JDBC driver's version number via reflection. This avoids having a runtime dependency on the driver"
[]
(try (invoke-static-method "com.exasol.jdbc.EXADriver" "getVersionInfo")
(catch Exception e (log/warn (str "Error getting JDBC driver version: " e)))))

(defn get-driver-version
"Reads the driver version from the plugin yaml file on the classpath."
Expand Down
18 changes: 13 additions & 5 deletions test/metabase/driver/exasol_test.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
(ns metabase.driver.exasol-test
(:require [clojure.test :refer [deftest testing is]]
(:require [clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[metabase.driver.exasol :as exasol]
[metabase.query-processor :as qp]
[metabase.query-processor-test :as qp.test]
[metabase.query-processor-test.alternative-date-test :as alt-date-test]
[metabase.test :as mt]
[metabase.test.util :as tu]
[metabase.test.data :as td]
[metabase.test.data.dataset-definitions :as dataset]
[metabase.test.data.exasol-dataset-definitions :as exasol-dataset]
[metabase.query-processor :as qp]
[metabase.query-processor-test :as qp.test]
[metabase.query-processor-test.alternative-date-test :as alt-date-test])
[metabase.test.util :as tu])
(:import (java.util TimeZone)))

(deftest get-jdbc-driver-version-test
(testing "Getting JDBC driver version succeeds"
(is (not (str/blank? (exasol/get-jdbc-driver-version)))))
(testing "Getting JDBC driver version returns expected value"
(is (= "7.1.10" (exasol/get-jdbc-driver-version)))))

(deftest timezone-id-test
(mt/test-driver :exasol
(is (= "UTC"
Expand Down
4 changes: 0 additions & 4 deletions test/metabase/driver/exasol_unit_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@
(testing (format "Unprepare %s" (.getClass value))
(is (= expected (unprepare/unprepare-value :exasol value))))))

(deftest get-jdbc-driver-version-test
(testing "JDBC driver version is not empty"
(is (not (str/blank? (exasol/get-jdbc-driver-version))))))

(deftest get-driver-version-test
(testing "Reading driver version from non existing resource returns nil"
(is (= nil (exasol/get-driver-version "non-existing-resource.yaml"))))
Expand Down

0 comments on commit 850b2af

Please sign in to comment.