Updated Branches: refs/heads/develop dc66186d0 -> 38620a9e4
implemented a test for updating Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/38620a9e Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/38620a9e Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/38620a9e Branch: refs/heads/develop Commit: 38620a9e4a9d2b213ef46939254d6cbde10dc5cb Parents: dc66186 Author: Sebastian Schaffert <[email protected]> Authored: Tue Jan 7 15:46:00 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Tue Jan 7 15:46:00 2014 +0100 ---------------------------------------------------------------------- .../commons/sesame/model/StatementCommons.java | 46 ++++++++++++ .../kiwi/sparql/test/KiWiSparqlJoinTest.java | 76 ++++++++++++++++---- .../marmotta/kiwi/sparql/test/update01.sparql | 24 +++++++ .../kiwi/persistence/KiWiConnection.java | 2 +- 4 files changed, 135 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/38620a9e/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java index 194732c..47cd7b5 100644 --- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java +++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java @@ -18,11 +18,15 @@ package org.apache.marmotta.commons.sesame.model; import com.google.common.base.Equivalence; +import com.google.common.base.Function; import com.google.common.base.Objects; import javolution.util.FastMap; import javolution.util.FastSet; import javolution.util.function.Equality; +import org.openrdf.model.Resource; import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; import java.util.Map; import java.util.Set; @@ -188,4 +192,46 @@ public class StatementCommons { }; } + public static class TripleEquality implements Function<Statement,Statement> { + + @Override + public Statement apply(final Statement input) { + return new Statement() { + @Override + public Resource getSubject() { + return input.getSubject(); + } + + @Override + public URI getPredicate() { + return input.getPredicate(); + } + + @Override + public Value getObject() { + return input.getObject(); + } + + @Override + public Resource getContext() { + return input.getContext(); + } + + @Override + public int hashCode() { + return TRIPLE_EQUIVALENCE.hash(input); + } + + @Override + public boolean equals(Object obj) { + return TRIPLE_EQUIVALENCE.equivalent(input, (Statement) obj); + } + + @Override + public String toString() { + return input.toString(); + } + }; + } + } } http://git-wip-us.apache.org/repos/asf/marmotta/blob/38620a9e/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java index 7ffcad1..63f452e 100644 --- a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java +++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java @@ -18,31 +18,26 @@ package org.apache.marmotta.kiwi.sparql.test; import com.google.common.base.Function; +import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import info.aduna.iteration.Iterations; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; +import org.apache.marmotta.commons.sesame.model.StatementCommons; +import org.apache.marmotta.commons.vocabulary.FOAF; import org.apache.marmotta.kiwi.config.KiWiConfiguration; import org.apache.marmotta.kiwi.sail.KiWiStore; import org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSail; import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner; import org.apache.marmotta.kiwi.vocabulary.FN_MARMOTTA; import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runner.RunWith; -import org.openrdf.query.Binding; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQuery; -import org.openrdf.query.TupleQueryResult; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.query.*; import org.openrdf.repository.Repository; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; @@ -267,6 +262,13 @@ public class KiWiSparqlJoinTest { testQuery("query21.sparql"); } + // INSERT/UPDATE + @Test + public void testUpdate01() throws Exception { + testUpdate("update01.sparql", FOAF.name); + } + + // fulltext search filter @Test public void testQuery22() throws Exception { @@ -363,6 +365,56 @@ public class KiWiSparqlJoinTest { } } + private void testUpdate(String filename, URI... properties) throws Exception { + String queryString = IOUtils.toString(this.getClass().getResourceAsStream(filename), "UTF-8"); + + RepositoryConnection con1 = repository.getConnection(); + RepositoryConnection con2 = reference.getConnection(); + try { + con2.begin(); + + Update query2 = con2.prepareUpdate(QueryLanguage.SPARQL, queryString); + query2.execute(); + + con2.commit(); + + con1.begin(); + + Update query1 = con1.prepareUpdate(QueryLanguage.SPARQL, queryString); + query1.execute(); + + con1.commit(); + + + con1.begin(); + Set<Statement> set1 = new HashSet<>(); + for(URI u : properties) { + set1.addAll(Collections2.transform(Iterations.asSet(con1.getStatements(null, u, null, true)), new StatementCommons.TripleEquality())); + } + con1.commit(); + + con2.begin(); + Set<Statement> set2 = new HashSet<>(); + for(URI u : properties) { + set2.addAll(Collections2.transform(Iterations.asSet(con2.getStatements(null,u,null,true)), new StatementCommons.TripleEquality())); + } + con2.commit(); + + for(Statement stmt : set1) { + Assert.assertTrue(stmt + " not contained in set 2", set2.contains(stmt)); + } + for(Statement stmt : set2) { + Assert.assertTrue(stmt + " not contained in set 1", set1.contains(stmt)); + } + + } catch(RepositoryException ex) { + con1.rollback(); + } finally { + con1.close(); + con2.close(); + } + } + private void compareResults(TupleQueryResult result1, TupleQueryResult result2) throws QueryEvaluationException { List<BindingSet> bindingSets1 = Iterations.asList(result1); http://git-wip-us.apache.org/repos/asf/marmotta/blob/38620a9e/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/update01.sparql ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/update01.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/update01.sparql new file mode 100644 index 0000000..836676e --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/update01.sparql @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +PREFIX foaf: <http://xmlns.com/foaf/0.1/> +PREFIX dc: <http://purl.org/dc/elements/1.1/> +PREFIX mm: <http://marmotta.apache.org/vocabulary/sparql-functions#> + +DELETE { ?s foaf:name ?o . } +INSERT { ?s foaf:name "Johannes Meier" } +WHERE { ?s ?p ?o . FILTER(?s = <http://localhost:8080/LMF/resource/hans_meier>) } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/marmotta/blob/38620a9e/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java index f895251..9773003 100644 --- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java +++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java @@ -762,7 +762,7 @@ public class KiWiConnection implements AutoCloseable { * @return a KiWiDoubleLiteral with the correct value, or null if it does not exist * @throws SQLException */ - public synchronized KiWiDoubleLiteral loadLiteral(double value) throws SQLException { + public KiWiDoubleLiteral loadLiteral(double value) throws SQLException { // look in cache KiWiLiteral element = literalCache.get(LiteralCommons.createCacheKey(Double.toString(value),null,Namespaces.NS_XSD + "double")); if(element != null) {
