Skip to content

Commit

Permalink
[mongodb] Upgrade DB driver, add more type handlings, fix QuantityTyp…
Browse files Browse the repository at this point in the history
…e handling (#16333)

* #16308 #16310 Upgraded MongoDB driver, added initial unit tests
* #16308 #16310 Refactored the MongoDBPersistence adding helper, fixing type handling for HSBType, RawType and QuantityType
* #16308 Added backwardcompatibility for the old way of writting the data where possible
* #16308 Added test for larger ImageItems and the limit of 16 MB

Signed-off-by: René Ulbricht <rene_ulbricht@outlook.com>
  • Loading branch information
ulbi committed Feb 17, 2024
1 parent 2db9fb0 commit 956b8e4
Show file tree
Hide file tree
Showing 11 changed files with 2,427 additions and 196 deletions.
60 changes: 57 additions & 3 deletions bundles/org.openhab.persistence.mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,66 @@

<name>openHAB Add-ons :: Bundles :: Persistence Service :: MongoDB</name>

<properties>
<bnd.importpackage>!sun.nio.ch;!org.bson.codecs.kotlin*;!jnr.unixsocket*;!javax.annotation*;!com.google*;!io.netty*;com.oracle*;resolution:=optional;com.aayushatharva*;resolution:=optional;com.mongodb.crypt*;resolution:=optional;com.amazon*;resolution:=optional;software.amazon*;resolution:=optional</bnd.importpackage>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.13.1</version>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.11.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.11.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.11.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.10.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
<version>1.5.5-3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson-record-codec</artifactId>
<version>4.11.1</version>
<scope>compile</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>de.bwaldvogel</groupId>
<artifactId>mongo-java-server</artifactId>
<version>1.44.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>1.19.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.persistence.mongodb.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* This class defines constant field names used in MongoDB documents.
* These field names are used to ensure consistent access to document properties.
*
* @author René Ulbricht - Initial contribution
*/
@NonNullByDefault
public final class MongoDBFields {
public static final String FIELD_ID = "_id";
public static final String FIELD_ITEM = "item";
public static final String FIELD_REALNAME = "realName";
public static final String FIELD_TIMESTAMP = "timestamp";
public static final String FIELD_VALUE = "value";
public static final String FIELD_UNIT = "unit";
public static final String FIELD_VALUE_DATA = "value.data";
public static final String FIELD_VALUE_TYPE = "value.type";

private MongoDBFields() {
// Private constructor to prevent instantiation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.text.DateFormat;
import java.time.ZonedDateTime;
import java.util.Date;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.persistence.HistoricItem;
Expand Down Expand Up @@ -54,6 +55,7 @@ public ZonedDateTime getTimestamp() {

@Override
public String toString() {
return DateFormat.getDateTimeInstance().format(timestamp) + ": " + name + " -> " + state.toString();
Date date = Date.from(timestamp.toInstant());
return DateFormat.getDateTimeInstance().format(date) + ": " + name + " -> " + state.toString();
}
}

0 comments on commit 956b8e4

Please sign in to comment.