diff --git a/.travis.yml b/.travis.yml index 27fd9b6d57..0c4f4ffd80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ notifications: rooms: secure: I+soWCTe4u34GgD8069hEcSswPYPuKDjxjbM0/W5UsjBcog+G+9WfMM/NdXpi6MFKg7FnSdudTH34yLLoqYDVkDOqIZ+o/UG/jaTjHtqZeoJg5aQAXWVl0EVBfrPTltCwdDsrIwIuPJRk2RV5/0x4/Hp7KPtWfiRsweiu/0DQ4Zh0QbLMOgoXWKymU8g4x17ruJnJ8+1M//OCAfSZouJVga5U/RX1nPhB5lJtya6p27Nf1kRLTIh9Jksyv1fRhJE5qDrZCL1Qah5WvWJLraTy4Fs1hnY8ACMQURq/0nx4C37MsAYR2jFoixm+oCIxJlYrMWh7/wKS7UrAzniieXAYitMX7SnUWaihgE+3FRnD8QliPb8UeBAh0CUDHUxzrD7Jslbt+DVk4MjXfYPRzWfWHEIBzzIIPGwN540bKlHcTl5TD0eoKIzBc1DOxCCrAHmL5CfIIr5hj2/b7ZwTUIpYrtupBSV8sFD3X449VdRz+pVkDKj7FEVpAZ1Ywylg52wa0/2hObvfG9SbrhqSQZvKkTyEs4kdNuCjqUYlILOiqdz0fNbW4M7qvskONt9h5BunV7KyQkrnwfUVW0yA0D9eEG339aYbLwmLeSrrxMUFngK/9U63JsGmPmUQGafiomvLog6KJ04lXDTEURM1N1lZCGuJ5uYbqIpnSm9QwpmnWA= template: - - Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository} %{result} in %{duration} + - Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository} [%{branch}] %{result} in %{duration} on_success: always on_failure: always on_pull_requests: true diff --git a/benchmarks/core/pom.xml b/benchmarks/core/pom.xml index 070ba3e47b..0d2bfb0479 100644 --- a/benchmarks/core/pom.xml +++ b/benchmarks/core/pom.xml @@ -74,8 +74,18 @@ neoemf-data-mapdb + + fr.inria.atlanmod.neoemf + neoemf-data-berkeleydb + + + + cglib + cglib-nodep + + com.google.guava guava diff --git a/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/datastore/NeoBerkeleydbBackend.java b/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/datastore/NeoBerkeleydbBackend.java new file mode 100644 index 0000000000..d6c0424a2e --- /dev/null +++ b/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/datastore/NeoBerkeleydbBackend.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2017 Atlanmod INRIA LINA Mines Nantes. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Atlanmod INRIA LINA Mines Nantes - initial API and implementation + */ +package fr.inria.atlanmod.neoemf.benchmarks.datastore; + +import fr.inria.atlanmod.neoemf.data.PersistenceBackendFactoryRegistry; +import fr.inria.atlanmod.neoemf.data.berkeleydb.BerkeleyDbPersistenceBackendFactory; +import fr.inria.atlanmod.neoemf.data.berkeleydb.option.BerkeleyDbOptionsBuilder; +import fr.inria.atlanmod.neoemf.data.berkeleydb.util.BerkeleyDbURI; +import fr.inria.atlanmod.neoemf.resource.PersistentResourceFactory; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; + +import java.io.File; +import java.util.Map; + +public class NeoBerkeleydbBackend extends AbstractNeoBackend { + + public static final String NAME = "neo-berkeleydb"; + + private static final String STORE_EXTENSION = "berkeleydb.resource"; // -> neoemf.mapdb.resource + + public NeoBerkeleydbBackend() { + super(NAME, STORE_EXTENSION); + } + + @Override + public Resource createResource(File file, ResourceSet resourceSet) throws Exception { + PersistenceBackendFactoryRegistry.register(BerkeleyDbURI.SCHEME, BerkeleyDbPersistenceBackendFactory.getInstance()); + resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(BerkeleyDbURI.SCHEME, PersistentResourceFactory.getInstance()); + + URI uri = BerkeleyDbURI.createFileURI(file); + + return resourceSet.createResource(uri); + } + + @Override + public Map getOptions() { + return BerkeleyDbOptionsBuilder.newBuilder() + .directWrite() + .autocommit() + .asMap(); + } +} diff --git a/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/query/ase2015/QueryFactoryASE2015.java b/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/query/ase2015/QueryFactoryASE2015.java index 8c50eabe97..1ad732dd50 100644 --- a/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/query/ase2015/QueryFactoryASE2015.java +++ b/benchmarks/core/src/main/java/fr/inria/atlanmod/neoemf/benchmarks/query/ase2015/QueryFactoryASE2015.java @@ -117,7 +117,7 @@ public static Query queryCommentsTagContent(Resource resource) { } } catch (NullPointerException e) { - log.error(e); + log.error("Null pointer", e); } return result.size(); diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index f671531ef9..4d932df1c3 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -25,9 +25,7 @@ 4.3.0 1.9.6 - 2.7 - 1.17.1 3.2.4 @@ -40,6 +38,11 @@ ${cglib-nodep.version} + + cglib + cglib-nodep + ${cglib-nodep.version} + @@ -82,6 +85,12 @@ ${project.version} + + fr.inria.atlanmod.neoemf + neoemf-data-berkeleydb + ${project.version} + + diff --git a/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/BerkeleyDbPersistenceBackend.java b/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/BerkeleyDbPersistenceBackend.java index 48deda749d..51d56c1d7e 100644 --- a/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/BerkeleyDbPersistenceBackend.java +++ b/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/BerkeleyDbPersistenceBackend.java @@ -377,16 +377,17 @@ public Object valueOf(FeatureKey featureKey) { * * @param featureKey ??? * - * @return ??? + * @return the previous (eventually null) value of the feature. */ public Object removeFeature(FeatureKey featureKey) { DatabaseEntry key = new DatabaseEntry(fkSerializer.serialize(featureKey)); DatabaseEntry value = new DatabaseEntry(); Object old = null; try { - features.get(null, key, value, LockMode.DEFAULT); - features.delete(null, key); - old = objSerializer.deserialize(value.getData()); + if (features.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS){ + features.delete(null, key); + old = objSerializer.deserialize(value.getData()); + } } catch (DatabaseException e) { NeoLogger.error(e); @@ -417,8 +418,8 @@ public boolean isFeatureSet(FeatureKey featureKey) { /** * Stores the single value of a given multi-valued feature at the given index. * - * @param featureKey ??? - * @param obj ??? + * @param featureKey the key + * @param obj the value * * @return ??? */ diff --git a/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/ObjectSerializer.java b/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/ObjectSerializer.java index 04d7d1ecd6..7ec6eb793c 100644 --- a/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/ObjectSerializer.java +++ b/neoemf-data/map/berkeleydb/src/main/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/ObjectSerializer.java @@ -22,6 +22,7 @@ import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import static com.google.common.base.Preconditions.checkNotNull; /** * ??? */ @@ -30,6 +31,8 @@ public class ObjectSerializer implements Serializer { @Override public byte[] serialize(Object value) { + checkNotNull(value); + byte[] data; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { @@ -46,6 +49,8 @@ public byte[] serialize(Object value) { @Override public Object deserialize(byte[] data) { + checkNotNull(data); + ByteArrayInputStream bis = new ByteArrayInputStream(data); Object value = null; try { diff --git a/neoemf-data/map/berkeleydb/src/test/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/FeatureKeySerializerTest.java b/neoemf-data/map/berkeleydb/src/test/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/FeatureKeySerializerTest.java new file mode 100644 index 0000000000..8ad8a34c70 --- /dev/null +++ b/neoemf-data/map/berkeleydb/src/test/java/fr/inria/atlanmod/neoemf/data/berkeleydb/serializer/FeatureKeySerializerTest.java @@ -0,0 +1,50 @@ +package fr.inria.atlanmod.neoemf.data.berkeleydb.serializer; + + +import fr.inria.atlanmod.neoemf.core.StringId; +import fr.inria.atlanmod.neoemf.data.structure.FeatureKey; +import fr.inria.atlanmod.neoemf.data.structure.MultivaluedFeatureKey; +import org.junit.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FeatureKeySerializerTest { + + @Test + public void testSerialize() { + FeatureKeySerializer serializer = new FeatureKeySerializer(); + FeatureKey fkIn = FeatureKey.of(new StringId("obj1"), "feature"); + FeatureKey fkOut = serializer.deserialize(serializer.serialize(fkIn)); + + assertThat(fkIn).isEqualTo(fkOut); + } + + @Test + public void testSerializeMFK() { + FeatureKeySerializer serializer = new FeatureKeySerializer(); + MultivaluedFeatureKey fkIn = FeatureKey.of(new StringId("obj1"), "feature").withPosition(0); + MultivaluedFeatureKey fkOut = (MultivaluedFeatureKey) serializer.deserialize(serializer.serialize(fkIn)); + + assertThat(fkIn).isEqualTo(fkOut); + } + + + @Test + public void testSerializeMFKBis() { + FeatureKeySerializer serializer = new FeatureKeySerializer(); + FeatureKey fk = FeatureKey.of(new StringId("obj1"), "feature"); + MultivaluedFeatureKey fk1 = fk.withPosition(0); + MultivaluedFeatureKey fk2 = fk.withPosition(1); + + byte[] ser1 = serializer.serialize(fk1); + byte[] ser2 = serializer.serialize(fk2); + byte[] ser3 = serializer.serialize(fk); + + + assertThat(Arrays.equals(ser1, ser2)).isFalse(); + assertThat(Arrays.equals(ser1, ser3)).isFalse(); + assertThat(Arrays.equals(ser2, ser3)).isFalse(); + } +}