Skip to content

Commit

Permalink
Update h2db to 2.1.210 (#3728)
Browse files Browse the repository at this point in the history
* Updated version numbers

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Updated VARBINARY columns with the new maximum allowed size 1048576 (=1MB) instead of 16777216 (=16MB)

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Modified VARCHAR unit from CHAR to CHARACTERS

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* IDENTITY columns need more clauses if type is specified

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* DATEADD function does no more accept ? parameter in dateAndTime field

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* IDENTITY() function no more supported, using MAX(ID) instead

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Fixed security hotspot

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Updated version numbers to 2.0.206

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Updated copyright headers

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Fixed tests

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Updated version numbers to 2.1.210

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>

* Replaced VARBINARY with BLOB

Signed-off-by: Marcello Martina <martina.marcello.rinaldo@outlook.com>
  • Loading branch information
marcellorinaldo committed Jan 21, 2022
1 parent 2b9c4a8 commit 4df89ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions kura/org.eclipse.kura.core/META-INF/MANIFEST.MF
Expand Up @@ -46,10 +46,10 @@ Import-Package: javax.crypto,
org.eclipse.kura.system;version="[1.4,2.0)",
org.eclipse.kura.util.configuration;version="[1.0,2.0)",
org.eclipse.kura.watchdog;version="[1.0,2.0)",
org.h2;version="1.4.199",
org.h2.api;version="1.4.199",
org.h2.jdbcx;version="1.4.199",
org.h2.tools;version="1.4.199",
org.h2;version="2.1.210",
org.h2.api;version="2.1.210",
org.h2.jdbcx;version="2.1.210",
org.h2.tools;version="2.1.210",
org.osgi.framework;version="1.5.0",
org.osgi.service.component;version="1.2.0",
org.osgi.service.event;version="1.4.0",
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.kura.core.data.store;

import java.io.ByteArrayInputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -90,6 +91,7 @@ public class DbDataStore implements DataStore {
private final String sqlDropPrimaryKey;
private final String sqlDeleteDuplicates;
private final String sqlCreatePrimaryKey;
private final String sqlGetGreatestId;

// package level constructor to be invoked only by the factory
public DbDataStore(String table) {
Expand All @@ -100,9 +102,9 @@ public DbDataStore(String table) {
this.sanitizedTableName = sanitizeSql(table);

this.sqlCreateTable = "CREATE TABLE IF NOT EXISTS " + this.sanitizedTableName
+ " (id INTEGER IDENTITY PRIMARY KEY, topic VARCHAR(32767 CHAR), qos INTEGER, retain BOOLEAN, "
+ " (id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, topic VARCHAR(32767 CHARACTERS), qos INTEGER, retain BOOLEAN, "
+ "createdOn TIMESTAMP, publishedOn TIMESTAMP, publishedMessageId INTEGER, confirmedOn TIMESTAMP, "
+ "payload VARBINARY(16777216), priority INTEGER, sessionId VARCHAR(32767 CHAR), droppedOn TIMESTAMP);";
+ "payload BLOB, priority INTEGER, sessionId VARCHAR(32767 CHARACTERS), droppedOn TIMESTAMP);";
this.sqlCreateIndex = "CREATE INDEX IF NOT EXISTS " + sanitizeSql(this.tableName + "_nextMsg") + " ON "
+ this.sanitizedTableName + " (publishedOn ASC NULLS FIRST, priority ASC, createdOn ASC, qos);";
this.sqlMessageCount = "SELECT COUNT(*) FROM " + this.sanitizedTableName + ";";
Expand Down Expand Up @@ -144,6 +146,7 @@ public DbDataStore(String table) {
this.sqlDeleteDuplicates = DELETE_FROM + this.sanitizedTableName + " WHERE id IN (SELECT id FROM "
+ this.sanitizedTableName + " GROUP BY id HAVING COUNT(*) > 1);";
this.sqlCreatePrimaryKey = ALTER_TABLE + this.sanitizedTableName + " ADD PRIMARY KEY (id);";
this.sqlGetGreatestId = "SELECT MAX(ID) FROM " + this.sanitizedTableName + ";";
}

private String sanitizeSql(final String string) {
Expand Down Expand Up @@ -317,15 +320,15 @@ private synchronized DataMessage storeInternal(String topic, byte[] payload, int
pstmt.setTimestamp(5, null); // publishedOn
pstmt.setInt(6, -1); // publishedMessageId
pstmt.setTimestamp(7, null); // confirmedOn
pstmt.setBytes(8, payload); // payload
pstmt.setBinaryStream(8, new ByteArrayInputStream(payload)); // payload
pstmt.setInt(9, priority); // priority
pstmt.setString(10, null); // sessionId
pstmt.setTimestamp(11, null); // droppedOn
pstmt.execute();
}

// retrieve message id
try (PreparedStatement cstmt = c.prepareStatement("CALL IDENTITY();");
try (PreparedStatement cstmt = c.prepareStatement(this.sqlGetGreatestId);
ResultSet rs = cstmt.executeQuery()) {
if (rs != null && rs.next()) {
result = rs.getInt(1);
Expand Down Expand Up @@ -544,10 +547,16 @@ private synchronized void execute(String sql, Integer... params) throws KuraStor

private synchronized void executeDeleteMessagesQuery(String sql, Timestamp timestamp, int purgeAge)
throws KuraStoreException {
/*
* H2 v2.0.202 does not more support ? parameter in dateAndTime fields
* so the timestamp is directly copied into the sql string
*/
final String sqlWithTimestamp = sql.replace("DATEADD('ss', -?, ?)",
"DATEADD('ss', -?, TIMESTAMP '" + timestamp.toString() + "')");

withConnection(c -> {
try (final PreparedStatement stmt = c.prepareStatement(sql)) {
try (final PreparedStatement stmt = c.prepareStatement(sqlWithTimestamp)) {
stmt.setInt(1, purgeAge);
stmt.setTimestamp(2, timestamp, this.utcCalendar);

stmt.execute();
c.commit();
Expand Down
4 changes: 2 additions & 2 deletions kura/test/org.eclipse.kura.core.db.test/META-INF/MANIFEST.MF
Expand Up @@ -9,8 +9,8 @@ Fragment-Host: org.eclipse.kura.core
Import-Package: org.eclipse.kura;version="[1.2,2.0)",
org.eclipse.kura.core.testutil,
org.eclipse.kura.db;version="[2.0,3.0)",
org.h2;version="1.4.199",
org.h2.jdbc;version="1.4.199",
org.h2;version="2.1.210",
org.h2.jdbc;version="2.1.210",
org.junit;version="4.12.0",
org.junit.runner;version="4.12.0",
org.junit.runners;version="4.12.0",
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Eurotech and/or its affiliates and others
* Copyright (c) 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -44,7 +44,7 @@ public class H2DbWireRecordFilterTest {
@Test
public void shouldNotEmitPropertyOfUnsupportedType()
throws KuraException, InvalidSyntaxException, InterruptedException, ExecutionException, TimeoutException {
givenAColumnWithData("test", 1, 2, 3, 4, 5);
givenAColumnWithData("test", 1, 2, 3, 4, 5, 6);

whenQueryIsPerformed("SELECT MEDIAN(\"test\") FROM \"" + tableName + "\";");

Expand Down
Expand Up @@ -21,7 +21,7 @@ javax.usb.api.version=1.0.2
javax.usb.common.version=1.0.2
javax.usb.linux.version=1.0.3
org.apache.commons.net.version=3.1.0.v201205071737
com.h2database.h2.version=1.4.199
com.h2database.h2.version=2.1.210
slf4j.api.version=1.7.32
jcl.over.slf4j.version=1.7.32
log4j.version=2.17.1
Expand Down

0 comments on commit 4df89ae

Please sign in to comment.