diff --git a/kura/org.eclipse.kura.core/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.core/META-INF/MANIFEST.MF index 93e378915d..87d5b107d1 100644 --- a/kura/org.eclipse.kura.core/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.core/META-INF/MANIFEST.MF @@ -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", diff --git a/kura/org.eclipse.kura.core/src/main/java/org/eclipse/kura/core/data/store/DbDataStore.java b/kura/org.eclipse.kura.core/src/main/java/org/eclipse/kura/core/data/store/DbDataStore.java index 3a48015e29..88c721fd38 100644 --- a/kura/org.eclipse.kura.core/src/main/java/org/eclipse/kura/core/data/store/DbDataStore.java +++ b/kura/org.eclipse.kura.core/src/main/java/org/eclipse/kura/core/data/store/DbDataStore.java @@ -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 @@ -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; @@ -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) { @@ -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 + ";"; @@ -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) { @@ -317,7 +320,7 @@ 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 @@ -325,7 +328,7 @@ private synchronized DataMessage storeInternal(String topic, byte[] payload, int } // 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); @@ -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(); diff --git a/kura/test/org.eclipse.kura.core.db.test/META-INF/MANIFEST.MF b/kura/test/org.eclipse.kura.core.db.test/META-INF/MANIFEST.MF index 5cd9df07d7..bb645ce435 100644 --- a/kura/test/org.eclipse.kura.core.db.test/META-INF/MANIFEST.MF +++ b/kura/test/org.eclipse.kura.core.db.test/META-INF/MANIFEST.MF @@ -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", diff --git a/kura/test/org.eclipse.kura.wire.h2db.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/h2db/filter/test/H2DbWireRecordFilterTest.java b/kura/test/org.eclipse.kura.wire.h2db.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/h2db/filter/test/H2DbWireRecordFilterTest.java index 15c6d67b7b..a83b46d779 100644 --- a/kura/test/org.eclipse.kura.wire.h2db.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/h2db/filter/test/H2DbWireRecordFilterTest.java +++ b/kura/test/org.eclipse.kura.wire.h2db.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/h2db/filter/test/H2DbWireRecordFilterTest.java @@ -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 @@ -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 + "\";"); diff --git a/target-platform/config/kura.target-platform.build.properties b/target-platform/config/kura.target-platform.build.properties index e9252c9563..7ae8c89987 100644 --- a/target-platform/config/kura.target-platform.build.properties +++ b/target-platform/config/kura.target-platform.build.properties @@ -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