[jdbc] Upgrade H2 to 2.2.224 (#15726)

Upgrades H2 database from 1.4.191 to 2.2.224.

Add ';NON_KEYWORDS=VALUE' to the JDBC URL because the add-on uses 'value' (which is also a keyword) as column name.

Also fixes some queries used by the command extension because H2 always uses upper case table names.

For the change log, see:

https://h2database.com/html/changelog.html

For migration notes, see:

https://h2database.com/html/migration-to-v2.html

Fixes #13115

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2023-10-10 13:14:48 +02:00 committed by GitHub
parent 06d8e750f2
commit 1759058921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 18 deletions

View File

@ -7,16 +7,16 @@ It is designed for a maximum of scalability, to store very large amounts of data
The generic design makes it relatively easy for developers to integrate other databases that have JDBC drivers.
The following databases are currently supported and tested:
| Database | Tested Driver / Version |
| -------------------------------------------- | ------------------------------------------------------------ |
| [Apache Derby](https://db.apache.org/derby/) | [derby-10.14.2.0.jar](https://mvnrepository.com/artifact/org.apache.derby/derby) |
| [H2](https://www.h2database.com/) | [h2-1.4.191.jar](https://mvnrepository.com/artifact/com.h2database/h2) |
| [HSQLDB](http://hsqldb.org/) | [hsqldb-2.3.3.jar](https://mvnrepository.com/artifact/org.hsqldb/hsqldb) |
| Database | Tested Driver / Version |
| -------------------------------------------- |----------------------------------------------------------------------------------------------------------|
| [Apache Derby](https://db.apache.org/derby/) | [derby-10.14.2.0.jar](https://mvnrepository.com/artifact/org.apache.derby/derby) |
| [H2](https://www.h2database.com/) | [h2-2.2.224.jar](https://mvnrepository.com/artifact/com.h2database/h2) |
| [HSQLDB](http://hsqldb.org/) | [hsqldb-2.3.3.jar](https://mvnrepository.com/artifact/org.hsqldb/hsqldb) |
| [MariaDB](https://mariadb.org/) | [mariadb-java-client-3.0.8.jar](https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client) |
| [MySQL](https://www.mysql.com/) | [mysql-connector-j-8.0.33.jar](https://mvnrepository.com/artifact/com.mysql/mysql-connector-j) |
| [PostgreSQL](https://www.postgresql.org/) | [postgresql-42.4.3.jar](https://mvnrepository.com/artifact/org.postgresql/postgresql) |
| [SQLite](https://www.sqlite.org/) | [sqlite-jdbc-3.42.0.0.jar](https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc) |
| [TimescaleDB](https://www.timescale.com/) | [postgresql-42.4.3.jar](https://mvnrepository.com/artifact/org.postgresql/postgresql) |
| [MySQL](https://www.mysql.com/) | [mysql-connector-j-8.0.33.jar](https://mvnrepository.com/artifact/com.mysql/mysql-connector-j) |
| [PostgreSQL](https://www.postgresql.org/) | [postgresql-42.4.3.jar](https://mvnrepository.com/artifact/org.postgresql/postgresql) |
| [SQLite](https://www.sqlite.org/) | [sqlite-jdbc-3.42.0.0.jar](https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc) |
| [TimescaleDB](https://www.timescale.com/) | [postgresql-42.4.3.jar](https://mvnrepository.com/artifact/org.postgresql/postgresql) |
## Table of Contents

View File

@ -26,7 +26,7 @@
<!-- JDBC database driver versions -->
<derby.version>10.14.2.0</derby.version>
<h2.version>1.4.191</h2.version>
<h2.version>2.2.224</h2.version>
<hsqldb.version>2.3.3</hsqldb.version>
<mariadb.version>3.0.8</mariadb.version>
<mysql.version>8.0.33</mysql.version>

View File

@ -13,7 +13,7 @@
<feature name="openhab-persistence-jdbc-h2" description="JDBC Persistence H2" version="${project.version}">
<configfile finalname="${openhab.conf}/services/jdbc.cfg" override="false">mvn:org.openhab.addons.features.karaf/org.openhab.addons.features.karaf.openhab-addons-external/${project.version}/cfg/jdbc</configfile>
<feature prerequisite="false" dependency="false">openhab-runtime-base</feature>
<bundle start-level="80">mvn:com.h2database/h2/1.4.191</bundle>
<bundle start-level="80">mvn:com.h2database/h2/2.2.224</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.persistence.jdbc/${project.version}</bundle>
</feature>

View File

@ -321,7 +321,7 @@ public class JdbcConfiguration {
warn += "\tDerby: version >= 10.14.2.0 from https://mvnrepository.com/artifact/org.apache.derby/derby\n";
break;
case "h2":
warn += "\tH2: version >= 1.4.189 from https://mvnrepository.com/artifact/com.h2database/h2\n";
warn += "\tH2: version >= 2.2.224 from https://mvnrepository.com/artifact/com.h2database/h2\n";
break;
case "hsqldb":
warn += "\tHSQLDB: version >= 2.3.3 from https://mvnrepository.com/artifact/org.hsqldb/hsqldb\n";

View File

@ -52,6 +52,8 @@ public class JdbcH2DAO extends JdbcBaseDAO {
private void initSqlQueries() {
logger.debug("JDBC::initSqlQueries: '{}'", this.getClass().getSimpleName());
sqlIfTableExists = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='#searchTable#'";
sqlGetItemTables = "SELECT LOWER(table_name) AS table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='PUBLIC' AND NOT table_name=UPPER('#itemsManageTable#')";
sqlGetTableColumnTypes = "SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema='#jdbcUriDatabaseName#' AND table_name='#tableName#'";
// SQL_INSERT_ITEM_VALUE = "INSERT INTO #tableName# (TIME, VALUE) VALUES( NOW(), CAST( ? as #dbType#) )";
// http://stackoverflow.com/questions/19768051/h2-sql-database-insert-if-the-record-does-not-exist
sqlInsertItemValue = "MERGE INTO #tableName# (TIME, VALUE) VALUES( #tablePrimaryValue#, CAST( ? as #dbType#) )";
@ -69,8 +71,6 @@ public class JdbcH2DAO extends JdbcBaseDAO {
private void initDbProps() {
// Properties for HikariCP
databaseProps.setProperty("driverClassName", DRIVER_CLASS_NAME);
// driverClassName OR BETTER USE dataSourceClassName
// databaseProps.setProperty("dataSourceClassName", DATA_SOURCE_CLASS_NAME);
}
/**************

View File

@ -26,7 +26,7 @@
# Some URL-Examples, 'service' identifies and activates internally the correct jdbc driver.
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
# jdbc:url=jdbc:derby:./testDerby;create=true
# jdbc:url=jdbc:h2:./testH2
# jdbc:url=jdbc:h2:./testH2;NON_KEYWORDS=VALUE
# jdbc:url=jdbc:hsqldb:./testHsqlDb
# jdbc:url=jdbc:mariadb://192.168.0.1:3306/testMariadb
# jdbc:url=jdbc:mysql://192.168.0.1:3306/testMysql
@ -40,7 +40,7 @@
Parameter 'service' is used as identifier for the selected jdbc driver.
URL-Examples:<br>
jdbc:derby:./testDerby;create=true<br>
jdbc:h2:./testH2<br>
jdbc:h2:./testH2;NON_KEYWORDS=VALUE<br>
jdbc:hsqldb:./testHsqlDb<br>
jdbc:mariadb://192.168.0.1:3306/testMariadb<br>
jdbc:mysql://192.168.0.1:3306/testMysql<br>

View File

@ -49,7 +49,7 @@ persistence.config.jdbc.tableUseRealItemNames.description = Enables Tablename pr
persistence.config.jdbc.tableUseRealItemNames.option.true = Enable
persistence.config.jdbc.tableUseRealItemNames.option.false = Disable
persistence.config.jdbc.url.label = Database URL
persistence.config.jdbc.url.description = Defines required database URL and optional path and parameters.<br> Required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'<br> Parameter 'service' is used as identifier for the selected jdbc driver. URL-Examples:<br> jdbc:derby:./testDerby;create=true<br> jdbc:h2:./testH2<br> jdbc:hsqldb:./testHsqlDb<br> jdbc:mariadb://192.168.0.1:3306/testMariadb<br> jdbc:mysql://192.168.0.1:3306/testMysql<br> jdbc:postgresql://192.168.0.1:5432/testPostgresql<br> jdbc:sqlite:./testSqlite.db
persistence.config.jdbc.url.description = Defines required database URL and optional path and parameters.<br> Required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'<br> Parameter 'service' is used as identifier for the selected jdbc driver. URL-Examples:<br> jdbc:derby:./testDerby;create=true<br> jdbc:h2:./testH2;NON_KEYWORDS=VALUE<br> jdbc:hsqldb:./testHsqlDb<br> jdbc:mariadb://192.168.0.1:3306/testMariadb<br> jdbc:mysql://192.168.0.1:3306/testMysql<br> jdbc:postgresql://192.168.0.1:5432/testPostgresql<br> jdbc:sqlite:./testSqlite.db
persistence.config.jdbc.user.label = Database User
persistence.config.jdbc.user.description = Defines the database user.

View File

@ -15,7 +15,7 @@
# Some URL-Examples, 'service' identifies and activates internally the correct jdbc driver.
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
# url=jdbc:derby:./testDerby;create=true
# url=jdbc:h2:./testH2
# url=jdbc:h2:./testH2;NON_KEYWORDS=VALUE
# url=jdbc:hsqldb:./testHsqlDb
# url=jdbc:mariadb://192.168.0.1:3306/testMariadb
# url=jdbc:mysql://192.168.0.1:3306/testMysql