diff --git a/bom/openhab-core/pom.xml b/bom/openhab-core/pom.xml index 0ab56b4fc..9f75e7c8b 100644 --- a/bom/openhab-core/pom.xml +++ b/bom/openhab-core/pom.xml @@ -532,12 +532,6 @@ ${project.version} compile - - org.openhab.core.bundles - org.openhab.core.storage.mapdb - ${project.version} - compile - diff --git a/bundles/org.openhab.core.storage.mapdb/.classpath b/bundles/org.openhab.core.storage.mapdb/.classpath deleted file mode 100644 index 3721ade03..000000000 --- a/bundles/org.openhab.core.storage.mapdb/.classpath +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bundles/org.openhab.core.storage.mapdb/.project b/bundles/org.openhab.core.storage.mapdb/.project deleted file mode 100644 index 497cb5f13..000000000 --- a/bundles/org.openhab.core.storage.mapdb/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - org.openhab.core.storage.mapdb - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/bundles/org.openhab.core.storage.mapdb/NOTICE b/bundles/org.openhab.core.storage.mapdb/NOTICE deleted file mode 100644 index 6c17d0d8a..000000000 --- a/bundles/org.openhab.core.storage.mapdb/NOTICE +++ /dev/null @@ -1,14 +0,0 @@ -This content is produced and maintained by the openHAB project. - -* Project home: https://www.openhab.org - -== Declared Project Licenses - -This program and the accompanying materials are made available under the terms -of the Eclipse Public License 2.0 which is available at -https://www.eclipse.org/legal/epl-2.0/. - -== Source Code - -https://github.com/openhab/openhab-core - diff --git a/bundles/org.openhab.core.storage.mapdb/pom.xml b/bundles/org.openhab.core.storage.mapdb/pom.xml deleted file mode 100644 index 5929625bf..000000000 --- a/bundles/org.openhab.core.storage.mapdb/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - 4.0.0 - - - org.openhab.core.bundles - org.openhab.core.reactor.bundles - 3.0.0-SNAPSHOT - - - org.openhab.core.storage.mapdb - - openHAB Core :: Bundles :: MapDB Storage - - - - org.openhab.core.bundles - org.openhab.core.config.core - ${project.version} - - - - diff --git a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorage.java b/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorage.java deleted file mode 100644 index 906f5f37b..000000000 --- a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorage.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * Copyright (c) 2010-2020 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.core.storage.mapdb.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.mapdb.DB; -import org.openhab.core.items.ManagedItemProvider.PersistedItem; -import org.openhab.core.items.ManagedItemProvider.PersistedItemInstanceCreator; -import org.openhab.core.storage.DeletableStorage; -import org.openhab.core.storage.Storage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonSyntaxException; - -/** - * The MapDbStorage is concrete implementation of the {@link Storage} interface. - * It stores the key-value pairs in files. This Storage serializes and deserializes - * the given values using their JSON representation (generated by {@code Gson}. - * This transformation should help maintaining version compatibility of the stored - * data. - * - * @author Thomas Eichstaedt-Engelen - Initial contribution - * @author Alex Tugarev - Loading with Class.forName() if classLoader is null - * @author Markus Rathgeb - Made the MapDB storage a disposable one - */ -@NonNullByDefault -public class MapDbStorage implements DeletableStorage { - - static final String TYPE_SEPARATOR = "@@@"; - - private final Logger logger = LoggerFactory.getLogger(MapDbStorage.class); - - private final String name; - private final DB db; - private final @Nullable ClassLoader classLoader; - private Map map; - - private transient Gson mapper; - - /** - * Constructor. - * - * @param db the database - * @param name the name - * @param classLoader the classloader used for deserialization - */ - public MapDbStorage(final DB db, final String name, final @Nullable ClassLoader classLoader) { - this.name = name; - this.db = db; - this.classLoader = classLoader; - this.map = db.createTreeMap(name).makeOrGet(); - this.mapper = new GsonBuilder().registerTypeAdapterFactory(new PropertiesTypeAdapterFactory()) - .registerTypeAdapter(PersistedItem.class, new PersistedItemInstanceCreator()).create(); - } - - @Override - public void delete() { - // Use an unmodifiable map. After deletion no operation / modification should be called anymore. - map = Collections.emptyMap(); - db.delete(name); - } - - @Override - public @Nullable T put(String key, @Nullable T value) { - if (value == null) { - return remove(key); - } - String previousValue = map.put(key, serialize(value)); - db.commit(); - return deserialize(previousValue); - } - - @Override - public @Nullable T remove(String key) { - String removedElement = map.remove(key); - db.commit(); - return deserialize(removedElement); - } - - @Override - public boolean containsKey(final String key) { - return map.containsKey(key); - } - - @Override - public @Nullable T get(String key) { - return deserialize(map.get(key)); - } - - @Override - public Collection getKeys() { - return new HashSet<>(map.keySet()); - } - - @Override - public Collection<@Nullable T> getValues() { - Collection<@Nullable T> values = new ArrayList<>(); - for (String key : getKeys()) { - values.add(get(key)); - } - return values; - } - - /** - * Transforms the given {@code value} into its JSON representation using {@code Gson}. - * - *

- * Since we do not know the type of {@code value} while deserializing it afterwards we prepend its qualified type - * name to the JSON String. - * - * @param value the {@code value} to store - * @return the JSON document prepended with the qualified type name of {@code value} - */ - private String serialize(T value) { - if (value == null) { - throw new IllegalArgumentException("Cannot serialize NULL"); - } - - String valueTypeName = value.getClass().getName(); - String valueAsString = mapper.toJson(value); - String concatValue = valueTypeName + TYPE_SEPARATOR + valueAsString; - - logger.trace("serialized value '{}' to MapDB", concatValue); - return concatValue; - } - - /** - * Deserializes and instantiates an object of type {@code T} out of the given JSON String. - * - *

- * A special classloader (other than the one of the MapDB bundle) is used in order to load the classes in the - * context of the calling bundle. - * - * @param json the JSON String - * @return the deserialized object - */ - @SuppressWarnings("unchecked") - public @Nullable T deserialize(@Nullable String json) { - if (json == null) { - // nothing to deserialize - return null; - } - - String[] concatValue = json.split(TYPE_SEPARATOR, 2); - String valueTypeName = concatValue[0]; - String valueAsString = concatValue[1]; - - @Nullable - T value = null; - try { - final ClassLoader classLoader = this.classLoader; - - // load required class within the given bundle context - final Class loadedValueType; - if (classLoader == null) { - loadedValueType = (Class) Class.forName(valueTypeName); - } else { - loadedValueType = (Class) classLoader.loadClass(valueTypeName); - } - - value = mapper.fromJson(valueAsString, loadedValueType); - logger.trace("deserialized value '{}' from MapDB", value); - } catch (final JsonSyntaxException | ClassNotFoundException ex) { - logger.warn("Couldn't deserialize value '{}'. Root cause is: {}", json, ex.getMessage()); - } - - return value; - } -} diff --git a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorageService.java b/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorageService.java deleted file mode 100644 index 82ba8f057..000000000 --- a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/MapDbStorageService.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2010-2020 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.core.storage.mapdb.internal; - -import java.io.File; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.mapdb.DB; -import org.mapdb.DBMaker; -import org.openhab.core.config.core.ConfigConstants; -import org.openhab.core.storage.DeletableStorage; -import org.openhab.core.storage.DeletableStorageService; -import org.openhab.core.storage.StorageService; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This implementation of {@link StorageService} provides abilities to store - * data in the lightweight key-value-store MapDB. - * - * @author Thomas Eichstaedt-Engelen - Initial contribution - * @author Alex Tugarev - Added getStorage for name only - * @author Markus Rathgeb - Use {@link DeletableStorageService} - */ -@Component(name = "org.openhab.core.storage.mapdb", configurationPid = "org.openhab.storage.mapdb", immediate = true, service = { - StorageService.class, DeletableStorageService.class }, property = "storage.format=mapdb") -@NonNullByDefault -public class MapDbStorageService implements DeletableStorageService { - - private final Logger logger = LoggerFactory.getLogger(MapDbStorageService.class); - - /* the name of the mapdb database ({@code storage.mapdb}) */ - private static final String DB_FILE_NAME = "storage.mapdb"; - - /* holds the local instance of the MapDB database */ - private final DB db; - - /* the folder name to store mapdb databases ({@code mapdb} by default) */ - private String dbFolderName = "mapdb"; - - @Activate - public MapDbStorageService() { - dbFolderName = ConfigConstants.getUserDataFolder() + File.separator + dbFolderName; - File folder = new File(dbFolderName); - if (!folder.exists()) { - folder.mkdirs(); - } - - File dbFile = new File(dbFolderName, DB_FILE_NAME); - db = DBMaker.newFileDB(dbFile).closeOnJvmShutdown().make(); - - logger.debug("Opened MapDB file at '{}'.", dbFile.getAbsolutePath()); - } - - @Deactivate - public void deactivate() { - db.close(); - logger.debug("Deactivated MapDB Storage Service."); - } - - @Override - public DeletableStorage getStorage(String name, @Nullable ClassLoader classLoader) { - return new MapDbStorage<>(db, name, classLoader); - } - - @Override - public DeletableStorage getStorage(String name) { - return getStorage(name, null); - } -} diff --git a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapter.java b/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapter.java deleted file mode 100644 index 5b8fbd68f..000000000 --- a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapter.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2010-2020 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.core.storage.mapdb.internal; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.util.Collections; -import java.util.Map; - -import org.eclipse.jdt.annotation.Nullable; - -import com.google.gson.Gson; -import com.google.gson.InstanceCreator; -import com.google.gson.JsonSyntaxException; -import com.google.gson.TypeAdapter; -import com.google.gson.internal.ConstructorConstructor; -import com.google.gson.internal.JsonReaderInternalAccess; -import com.google.gson.internal.bind.MapTypeAdapterFactory; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; - -/** - * Type adapter that makes sure that all Numeric values in Maps of type Map<String, Object> are deserialized as - * BigDecimal instances instead of doubles. - * - * @author Ivan Iliev - Initial contribution - */ -public class PropertiesTypeAdapter extends TypeAdapter> { - - /** Type token. */ - public static final TypeToken> TOKEN = new TypeToken>() { - }; - - private final TypeAdapter> delegate; - - private final ConstructorConstructor constructor; - - private final TypeAdapter keyAdapter; - - private final TypeAdapter valueAdapter; - - /** - * Constructor - * - * @param gson the Gson reference - */ - public PropertiesTypeAdapter(final Gson gson) { - // obtain the default type adapters for String and Object classes - keyAdapter = gson.getAdapter(String.class); - valueAdapter = gson.getAdapter(Object.class); - - // obtain default gson objects - constructor = new ConstructorConstructor(Collections.> emptyMap()); - delegate = new MapTypeAdapterFactory(constructor, false).create(new Gson(), TOKEN); - } - - @Override - public void write(JsonWriter out, @Nullable Map value) throws IOException { - // write remains unchanged - delegate.write(out, value); - } - - @Override - public @Nullable Map read(JsonReader in) throws IOException { - // gson implementation code is modified when deserializing numbers - JsonToken peek = in.peek(); - if (peek == JsonToken.NULL) { - in.nextNull(); - return null; - } - - Map map = constructor.get(TOKEN).construct(); - - if (peek == JsonToken.BEGIN_ARRAY) { - in.beginArray(); - while (in.hasNext()) { - in.beginArray(); // entry array - String key = keyAdapter.read(in); - - // modification - Object value = getValue(in); - - Object replaced = map.put(key, value); - if (replaced != null) { - throw new JsonSyntaxException("duplicate key: " + key); - } - in.endArray(); - } - in.endArray(); - } else { - in.beginObject(); - while (in.hasNext()) { - JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); - String key = keyAdapter.read(in); - - // modification - Object value = getValue(in); - - Object replaced = map.put(key, value); - if (replaced != null) { - throw new JsonSyntaxException("duplicate key: " + key); - } - } - in.endObject(); - } - return map; - } - - private Object getValue(JsonReader in) throws IOException { - Object value = null; - - // if the next json token is a number we read it as a BigDecimal, - // otherwise use the default adapter to read it - if (JsonToken.NUMBER.equals(in.peek())) { - value = new BigDecimal(in.nextString()); - } else { - value = valueAdapter.read(in); - } - - return value; - } -} diff --git a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapterFactory.java b/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapterFactory.java deleted file mode 100644 index 83770e41d..000000000 --- a/bundles/org.openhab.core.storage.mapdb/src/main/java/org/openhab/core/storage/mapdb/internal/PropertiesTypeAdapterFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2010-2020 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.core.storage.mapdb.internal; - -import java.lang.reflect.Type; - -import org.eclipse.jdt.annotation.Nullable; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -/** - * TypeAdapterFactory responsible for returning a new instance of {@link PropertiesTypeAdapter} if the given type - * matches Map<String, Object> or null otherwise. - * - * @author Ivan Iliev - Initial contribution - */ -public class PropertiesTypeAdapterFactory implements TypeAdapterFactory { - - @SuppressWarnings({ "unused", "unchecked" }) - @Override - public @Nullable TypeAdapter create(Gson gson, TypeToken typeToken) { - Type type = typeToken.getType(); - - Class rawType = typeToken.getRawType(); - if (!PropertiesTypeAdapter.TOKEN.equals(typeToken)) { - return null; - } - - return (TypeAdapter) new PropertiesTypeAdapter(gson); - } -} diff --git a/bundles/org.openhab.core.storage.mapdb/src/test/java/org/openhab/core/storage/mapdb/internal/MapDbStorageServiceTest.java b/bundles/org.openhab.core.storage.mapdb/src/test/java/org/openhab/core/storage/mapdb/internal/MapDbStorageServiceTest.java deleted file mode 100644 index 1a65e4189..000000000 --- a/bundles/org.openhab.core.storage.mapdb/src/test/java/org/openhab/core/storage/mapdb/internal/MapDbStorageServiceTest.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Copyright (c) 2010-2020 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.core.storage.mapdb.internal; - -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openhab.core.config.core.ConfigConstants; -import org.openhab.core.library.CoreItemFactory; -import org.openhab.core.storage.DeletableStorage; -import org.openhab.core.storage.Storage; - -/** - * @author Thomas Eichstaedt-Engelen - Initial contribution - * @author Alex Tugarev - Added test for getStorage without classloader - * @author Markus Rathgeb - Migrate Groovy tests to OSGi - * @author Markus Rathgeb - Migrate OSGi test to non-OSGi test - */ -@NonNullByDefault -public class MapDbStorageServiceTest { - - private static final String KEY_1 = "Key1"; - private static final String KEY_2 = "Key2"; - - private static class PersistedItem { - public final String itemType; - public final List groupNames; - public final @Nullable String baseItemType; - - public PersistedItem(String itemType, List groupNames) { - this(itemType, groupNames, null); - } - - public PersistedItem(String itemType, List groupNames, @Nullable String baseItemType) { - this.itemType = itemType; - this.groupNames = groupNames; - this.baseItemType = baseItemType; - } - - @Override - public String toString() { - return String.format("PersistedItem [itemType=%s, groupNames=%s, baseItemType=%s]", itemType, groupNames, - baseItemType); - } - } - - private static class MockConfiguration { - private final Map configuration = new HashMap<>(); - - public void put(String key, Object value) { - configuration.put(key, value); - } - - public @Nullable Object get(String key) { - return configuration.get(key); - } - } - - public static class EntryTypeSeparatorTest { - public int num; - public @Nullable String str; - public boolean bool; - - @Override - public String toString() { - return "Entry [num=" + num + ", str=" + str + ", bool=" + bool + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (bool ? 1231 : 1237); - result = prime * result + num; - final String str = this.str; - result = prime * result + ((str == null) ? 0 : str.hashCode()); - return result; - } - - @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - EntryTypeSeparatorTest other = (EntryTypeSeparatorTest) obj; - if (bool != other.bool) { - return false; - } - if (num != other.num) { - return false; - } - if (str == null) { - if (other.str != null) { - return false; - } - } else if (!Objects.equals(str, other.str)) { - return false; - } - return true; - } - } - - private @NonNullByDefault({}) Path tmpDir; - private @NonNullByDefault({}) MapDbStorageService storageService; - private @NonNullByDefault({}) MapDbStorage storage; - - @Before - public void setup() throws IOException { - tmpDir = Files.createTempDirectory(null); - final Path userdata = tmpDir.resolve("userdata"); - userdata.toFile().mkdir(); - System.setProperty(ConfigConstants.USERDATA_DIR_PROG_ARGUMENT, userdata.toString()); - - storageService = new MapDbStorageService(); - this.storage = (MapDbStorage) storageService.getStorage("TestStorage", getClass().getClassLoader()); - } - - @After - public void teardown() throws IOException { - if (storage != null) { - storage.delete(); - storage = null; - } - if (storageService != null) { - storageService.deactivate(); - storageService = null; - } - - // clean up database files ... - removeDirRecursive(tmpDir); - } - - private static void removeDirRecursive(final Path path) throws IOException { - if (Files.exists(path)) { - Files.walk(path).map(Path::toFile).sorted((o1, o2) -> -o1.compareTo(o2)).forEach(File::delete); - } - } - - /** - * Assert elements are serialized and deserialized by the storage. - */ - @Test - public void serializationDeserialization() { - Assert.assertThat(storage.getKeys().size(), Matchers.equalTo(0)); - storage.put(KEY_1, new PersistedItem(CoreItemFactory.STRING, Arrays.asList("LIGHT", "GROUND_FLOOR"))); - storage.put(KEY_2, new PersistedItem(CoreItemFactory.NUMBER, Arrays.asList("TEMPERATURE", "OUTSIDE"))); - Assert.assertThat(storage.getKeys().size(), Matchers.equalTo(2)); - final Object persistedObject = storage.get(KEY_1); - Assert.assertThat(persistedObject, Matchers.instanceOf(PersistedItem.class)); - storage.remove(KEY_1); - storage.remove(KEY_2); - Assert.assertThat(storage.getKeys().size(), Matchers.equalTo(0)); - } - - /** - * Assert old element gets overwritten when new value is stored under an existing key. - */ - @Test - public void override() { - Object persistedObject = null; - PersistedItem persistedItem = null; - - Assert.assertEquals(0, storage.getKeys().size()); - - persistedObject = storage.put(KEY_1, - new PersistedItem(CoreItemFactory.STRING, Arrays.asList("LIGHT", "GROUND_FLOOR"))); - Assert.assertEquals(1, storage.getKeys().size()); - Assert.assertNull(persistedObject); - - persistedObject = storage.get(KEY_1); - Assert.assertTrue(persistedObject instanceof PersistedItem); - persistedItem = (PersistedItem) persistedObject; - Assert.assertEquals(CoreItemFactory.STRING, persistedItem.itemType); - - persistedObject = storage.put(KEY_1, new PersistedItem(CoreItemFactory.NUMBER, Arrays.asList("TEMPERATURE"))); - Assert.assertTrue(persistedObject instanceof PersistedItem); - persistedItem = (PersistedItem) persistedObject; - Assert.assertEquals(1, storage.getKeys().size()); - Assert.assertEquals(CoreItemFactory.STRING, persistedItem.itemType); - - persistedObject = storage.get(KEY_1); - Assert.assertTrue(persistedObject instanceof PersistedItem); - persistedItem = (PersistedItem) persistedObject; - Assert.assertEquals(CoreItemFactory.NUMBER, persistedItem.itemType); - - storage.remove(KEY_1); - Assert.assertEquals(0, storage.getKeys().size()); - } - - /** - * Assert storage works without classloader. - */ - @Test - public void withoutClassloader() { - final Storage storageWithoutClassloader = storageService.getStorage("storageWithoutClassloader"); - final String value = "Value"; - storageWithoutClassloader.put(KEY_1, value); - Assert.assertEquals(value, storageWithoutClassloader.get(KEY_1)); - } - - /** - * Assert store configuration works. - */ - @Test - public void storeConfiguration() { - final Storage storageWithoutClassloader = storageService.getStorage("storage"); - final MockConfiguration configuration = new MockConfiguration(); - configuration.put(KEY_1, new BigDecimal(3)); - storageWithoutClassloader.put(KEY_2, configuration); - final Object persistedObject = storageWithoutClassloader.get(KEY_2); - Assert.assertTrue(persistedObject instanceof MockConfiguration); - final MockConfiguration persistedConfiguration = (MockConfiguration) persistedObject; - final Object cfgValue = persistedConfiguration.get(KEY_1); - Assert.assertTrue(cfgValue instanceof BigDecimal); - } - - /** - * Checks that the usage of the type separator does not break the storage. - */ - @Test - public void typeSeparator() { - final DeletableStorage storage = storageService.getStorage("type_separator"); - try { - final EntryTypeSeparatorTest entryOriginal = new EntryTypeSeparatorTest(); - entryOriginal.num = 2810; - entryOriginal.str = MapDbStorage.TYPE_SEPARATOR; - entryOriginal.bool = true; - storage.put(KEY_1, entryOriginal); - final EntryTypeSeparatorTest entryStorage = storage.get(KEY_1); - Assert.assertThat(entryStorage, Matchers.equalTo(entryOriginal)); - } finally { - storage.delete(); - } - } -} diff --git a/bundles/pom.xml b/bundles/pom.xml index 1d66029a1..74846df2f 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -100,7 +100,6 @@ org.openhab.core.model.thing.ide org.openhab.core.model.thing.runtime org.openhab.core.storage.json - org.openhab.core.storage.mapdb org.openhab.core.test org.openhab.core.test.magic org.openhab.core.ui diff --git a/features/karaf/openhab-core/src/main/feature/feature.xml b/features/karaf/openhab-core/src/main/feature/feature.xml index f2e133822..8693186a1 100644 --- a/features/karaf/openhab-core/src/main/feature/feature.xml +++ b/features/karaf/openhab-core/src/main/feature/feature.xml @@ -39,7 +39,7 @@ mvn:org.openhab.core.bundles/org.openhab.core.config.dispatch/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.config.xml/${project.version} mvn:org.openhab.core.bundles/org.openhab.core/${project.version} - openhab-core-storage-mapdb + openhab-core-storage-json mvn:org.openhab.core.bundles/org.openhab.core.binding.xml/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.id/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.persistence/${project.version} @@ -404,15 +404,6 @@ mvn:org.openhab.core.bundles/org.openhab.core.model.lsp/${project.version} - - openhab-core-base - - mvn:org.openhab.core.bundles/org.openhab.core.storage.mapdb/${project.version} - - openhab.tp;filter:="(feature=mapdb)" - openhab.tp-mapdb - - openhab-core-base diff --git a/itests/itest-common.bndrun b/itests/itest-common.bndrun index aa3a18af4..b37a3b5d5 100644 --- a/itests/itest-common.bndrun +++ b/itests/itest-common.bndrun @@ -2,5 +2,4 @@ # If we would like to use a storage at all, we will use the "volatile" storage. -runblacklist.itest-common: \ - bnd.identity;id='org.openhab.core.storage.json',\ - bnd.identity;id='org.openhab.core.storage.mapdb' + bnd.identity;id='org.openhab.core.storage.json'