Skip to content

Commit

Permalink
[jdbc] Upgrade H2 to 2.2.224 (openhab#15726)
Browse files Browse the repository at this point in the history
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 openhab#13115

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn authored and pat-git023 committed Oct 13, 2023
1 parent 4af6830 commit 46a4bfc
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions bundles/org.openhab.persistence.jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.persistence.jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private void testJDBCDriver(String driver) {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public JdbcH2DAO() {
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#) )";
Expand All @@ -69,8 +71,6 @@ private void initSqlTypes() {
private void initDbProps() {
// Properties for HikariCP
databaseProps.setProperty("driverClassName", DRIVER_CLASS_NAME);
// driverClassName OR BETTER USE dataSourceClassName
// databaseProps.setProperty("dataSourceClassName", DATA_SOURCE_CLASS_NAME);
}

/**************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46a4bfc

Please sign in to comment.