You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/11/05 11:52:24 UTC

[19/52] [partial] Reverting the erroneous merge by Sebastian according to the instructions in INFRA-6876

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sqlmapper/UnionOptimizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sqlmapper/UnionOptimizer.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sqlmapper/UnionOptimizer.java
deleted file mode 100644
index e3ab76c..0000000
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/sqlmapper/UnionOptimizer.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * 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.
- */
-package org.apache.marmotta.platform.sparql.services.evaluation.sql;
-
-import org.openrdf.query.algebra.*;
-import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Move unions that are contained in Joins or LeftJoins out (switch positions of union and join)
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class UnionOptimizer  extends QueryModelVisitorBase<RuntimeException> {
-
-    public UnionOptimizer() {
-    }
-
-    public void optimize(TupleExpr expr) {
-        expr.visit(this);
-    }
-
-
-    // rewrite multiprojection so that each projection gets a unique name and turn it into a projection
-
-
-    @Override
-    public void meet(MultiProjection node) throws RuntimeException {
-        int projectionCounter = 0;
-
-        List<ProjectionElem> projectionElemList = new ArrayList<ProjectionElem>();
-        for(ProjectionElemList elems : node.getProjections()) {
-            projectionCounter++;
-
-            for(ProjectionElem elem : elems.getElements()) {
-                ProjectionElem celem = elem.clone();
-                celem.setTargetName("_multi_"+elem.getTargetName()+"_"+projectionCounter);
-                projectionElemList.add(celem);
-            }
-        }
-        ProjectionElemList projections = new ProjectionElemList(projectionElemList);
-
-        Projection projection = new Projection(node.getArg().clone(),projections);
-        node.replaceWith(projection);
-        projection.visit(this);
-    }
-
-    @Override
-    public void meet(Union node) throws RuntimeException {
-        if(node.getParentNode() instanceof Join || node.getParentNode() instanceof LeftJoin) {
-            // move the other arg of the join inside the union
-            BinaryTupleOperator parent = (BinaryTupleOperator)node.getParentNode();
-            if(node == parent.getLeftArg()) {
-                // transform Join(Union(X,Y),Z) into Union(Join(X,Z),Join(Y,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the left argument of the union and the right argument of the join, and put them into join1
-                join1.setLeftArg(node.getLeftArg());
-                join1.setRightArg(parent.getRightArg());
-
-                // take the right argument of the union and the right argument of the join, and put them into join2
-                join2.setLeftArg(node.getRightArg());
-                join2.setRightArg(parent.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Union union = node.clone();
-                union.setLeftArg(join1);
-                union.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(union);
-
-                union.visit(this);
-            } else if(node == parent.getRightArg()) {
-                // transform Join(X,Union(Y,Z)) into Union(Join(X,Y),Join(X,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the the left argument of the join and the left argument of the union , and put them into join1
-                join1.setLeftArg(parent.getLeftArg());
-                join1.setRightArg(node.getLeftArg());
-
-                // take the the left argument of the join and the right argument of the union , and put them into join1
-                join2.setLeftArg(parent.getLeftArg());
-                join2.setRightArg(node.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Union union = node.clone();
-                union.setLeftArg(join1);
-                union.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(union);
-
-                union.visit(this);
-            }
-
-        }
-    }
-
-    @Override
-    public void meet(Intersection node) throws RuntimeException {
-        if(node.getParentNode() instanceof Join || node.getParentNode() instanceof LeftJoin) {
-            // move the other arg of the join inside the union
-            BinaryTupleOperator parent = (BinaryTupleOperator)node.getParentNode();
-            if(node == parent.getLeftArg()) {
-                // transform Join(Union(X,Y),Z) into Union(Join(X,Z),Join(Y,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the left argument of the union and the right argument of the join, and put them into join1
-                join1.setLeftArg(node.getLeftArg());
-                join1.setRightArg(parent.getRightArg());
-
-                // take the right argument of the union and the right argument of the join, and put them into join2
-                join2.setLeftArg(node.getRightArg());
-                join2.setRightArg(parent.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Intersection intersection = node.clone();
-                intersection.setLeftArg(join1);
-                intersection.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(intersection);
-
-                intersection.visit(this);
-            } else if(node == parent.getRightArg()) {
-                // transform Join(X,Union(Y,Z)) into Union(Join(X,Y),Join(X,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the the left argument of the join and the left argument of the union , and put them into join1
-                join1.setLeftArg(parent.getLeftArg());
-                join1.setRightArg(node.getLeftArg());
-
-                // take the the left argument of the join and the right argument of the union , and put them into join1
-                join2.setLeftArg(parent.getLeftArg());
-                join2.setRightArg(node.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Intersection intersection = node.clone();
-                intersection.setLeftArg(join1);
-                intersection.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(intersection);
-
-                intersection.visit(this);
-            }
-
-        }
-    }
-
-    @Override
-    public void meet(Difference node) throws RuntimeException {
-        if(node.getParentNode() instanceof Join || node.getParentNode() instanceof LeftJoin) {
-            // move the other arg of the join inside the union
-            BinaryTupleOperator parent = (BinaryTupleOperator)node.getParentNode();
-            if(node == parent.getLeftArg()) {
-                // transform Join(Union(X,Y),Z) into Union(Join(X,Z),Join(Y,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the left argument of the union and the right argument of the join, and put them into join1
-                join1.setLeftArg(node.getLeftArg());
-                join1.setRightArg(parent.getRightArg());
-
-                // take the right argument of the union and the right argument of the join, and put them into join2
-                join2.setLeftArg(node.getRightArg());
-                join2.setRightArg(parent.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Difference difference = node.clone();
-                difference.setLeftArg(join1);
-                difference.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(difference);
-
-                difference.visit(this);
-            } else if(node == parent.getRightArg()) {
-                // transform Join(X,Union(Y,Z)) into Union(Join(X,Y),Join(X,Z))
-
-                // parent is the join, so we create two copies of it
-                BinaryTupleOperator join1 = parent.clone();
-                BinaryTupleOperator join2 = parent.clone();
-
-                // take the the left argument of the join and the left argument of the union , and put them into join1
-                join1.setLeftArg(parent.getLeftArg());
-                join1.setRightArg(node.getLeftArg());
-
-                // take the the left argument of the join and the right argument of the union , and put them into join1
-                join2.setLeftArg(parent.getLeftArg());
-                join2.setRightArg(node.getRightArg());
-
-                // copy the union node to a new union node, and set the two new joins as arguments
-                Difference difference = node.clone();
-                difference.setLeftArg(join1);
-                difference.setRightArg(join2);
-
-                // replace parent by the new union
-                parent.replaceWith(difference);
-
-                difference.visit(this);
-            }
-
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/ComplexKiWiSparqlQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/ComplexKiWiSparqlQueryTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/ComplexKiWiSparqlQueryTest.java
new file mode 100644
index 0000000..0fba8b2
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/ComplexKiWiSparqlQueryTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+package org.apache.marmotta.kiwi.sparql.test;
+
+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.junit.runner.RunWith;
+import org.openrdf.query.parser.sparql.ComplexSPARQLQueryTest;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.sail.SailRepository;
+
+
+/**
+ * Run the Sesame Complex SPARQL Query Test Suite.
+
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class ComplexKiWiSparqlQueryTest extends ComplexSPARQLQueryTest {
+    
+ 
+    private final KiWiConfiguration config;
+
+    public ComplexKiWiSparqlQueryTest(KiWiConfiguration config) {
+        this.config = config;
+    }
+    
+    @Override
+    protected Repository newRepository() throws Exception {
+        KiWiStore store = new KiWiStore(config);
+        KiWiSparqlSail ssail = new KiWiSparqlSail(store);
+        return new SailRepository(ssail);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/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
new file mode 100644
index 0000000..ad7d701
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlJoinTest.java
@@ -0,0 +1,322 @@
+/*
+ * 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.
+ */
+
+package org.apache.marmotta.kiwi.sparql.test;
+
+import info.aduna.iteration.Iterations;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
+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.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+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.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.sail.memory.MemoryStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+
+/**
+ * Test the KiWi SPARQL Join optimization.
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class KiWiSparqlJoinTest {
+
+
+    private KiWiStore store;
+
+    private KiWiSparqlSail ssail;
+
+    private Repository repository;
+
+    // reference repository for checking if the results are the same
+    private Repository reference;
+
+    private final KiWiConfiguration dbConfig;
+
+    public KiWiSparqlJoinTest(KiWiConfiguration dbConfig) {
+        this.dbConfig = dbConfig;
+    }
+
+
+    @Before
+    public void initDatabase() throws RepositoryException, IOException, RDFParseException {
+        store = new KiWiStore(dbConfig);
+        ssail = new KiWiSparqlSail(store);
+        repository = new SailRepository(ssail);
+        repository.initialize();
+
+        // load demo data
+        RepositoryConnection con = repository.getConnection();
+        try {
+            con.begin();
+
+            con.add(this.getClass().getResourceAsStream("demo-data.foaf"), "http://localhost/test/", RDFFormat.RDFXML);
+
+            con.commit();
+        } finally {
+            con.close();
+        }
+
+        reference = new SailRepository(new MemoryStore());
+        reference.initialize();
+
+        // load demo data
+        RepositoryConnection con2 = reference.getConnection();
+        try {
+            con2.begin();
+
+            con2.add(this.getClass().getResourceAsStream("demo-data.foaf"), "http://localhost/test/", RDFFormat.RDFXML);
+
+            con2.commit();
+        } finally {
+            con2.close();
+        }
+    }
+
+    @After
+    public void dropDatabase() throws RepositoryException, SQLException {
+        store.getPersistence().dropDatabase();
+        repository.shutDown();
+    }
+
+    final Logger logger =
+            LoggerFactory.getLogger(this.getClass());
+
+    @Rule
+    public TestWatcher watchman = new TestWatcher() {
+        /**
+         * Invoked when a test is about to start
+         */
+        @Override
+        protected void starting(Description description) {
+            logger.info("{} being run...", description.getMethodName());
+        }
+    };
+
+
+    /**
+     * This method tests a simple triple join with two triple patterns.
+     * @throws Exception
+     */
+    @Test
+    public void testQuery1() throws Exception {
+        testQuery("query1.sparql");
+    }
+
+    @Test
+    public void testQuery2() throws Exception {
+        testQuery("query2.sparql");
+    }
+
+    @Test
+    public void testQuery3() throws Exception {
+        testQuery("query3.sparql");
+    }
+
+    @Test
+    public void testQuery4() throws Exception {
+        testQuery("query4.sparql");
+    }
+
+    // numeric comparison
+    @Test
+    public void testQuery5() throws Exception {
+        testQuery("query5.sparql");
+    }
+
+    // language match
+    @Test
+    public void testQuery6() throws Exception {
+        testQuery("query6.sparql");
+    }
+
+    // math expression
+    @Test
+    public void testQuery7() throws Exception {
+        testQuery("query7.sparql");
+    }
+
+    // isLiteral
+    @Test
+    public void testQuery8() throws Exception {
+        testQuery("query8.sparql");
+    }
+
+    // isURI
+    @Test
+    public void testQuery9() throws Exception {
+        testQuery("query9.sparql");
+    }
+
+    // term comparison
+    @Test
+    public void testQuery10() throws Exception {
+        testQuery("query10.sparql");
+    }
+
+    // optional
+    @Test
+    public void testQuery11() throws Exception {
+        testQuery("query11.sparql");
+    }
+
+    // optional with join
+    @Test
+    public void testQuery12() throws Exception {
+        testQuery("query12.sparql");
+    }
+
+    // nested query
+    @Test
+    public void testQuery13() throws Exception {
+        testQuery("query13.sparql");
+    }
+
+    // boolean filter
+    @Test
+    public void testQuery14() throws Exception {
+        testQuery("query14.sparql");
+    }
+
+    private void testQuery(String filename) throws Exception {
+        String queryString = IOUtils.toString(this.getClass().getResourceAsStream(filename), "UTF-8");
+
+        RepositoryConnection con1 = repository.getConnection();
+        RepositoryConnection con2 = reference.getConnection();
+        try {
+            con1.begin();
+
+            TupleQuery query1 = con1.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+            TupleQueryResult result1 = query1.evaluate();
+
+            con1.commit();
+
+            Assert.assertTrue(result1.hasNext());
+
+
+            con2.begin();
+
+            TupleQuery query2 = con2.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
+            TupleQueryResult result2 = query2.evaluate();
+
+            con2.commit();
+
+            compareResults(result1,result2);
+
+        } 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);
+        List<BindingSet> bindingSets2 = Iterations.asList(result2);
+
+        Set<Set<Pair>> set1 = new HashSet<Set<Pair>>(Lists.transform(bindingSets1,new BindingSetPairFunction()));
+        Set<Set<Pair>> set2 = new HashSet<Set<Pair>>(Lists.transform(bindingSets2,new BindingSetPairFunction()));
+
+        Assert.assertTrue(CollectionUtils.isEqualCollection(set1, set2));
+    }
+
+
+    private static class BindingSetPairFunction implements Function<BindingSet, Set<Pair>> {
+        @Override
+        public Set<Pair> apply(BindingSet input) {
+            Set<Pair> result = new HashSet<Pair>();
+
+            for(Binding b : input) {
+                Pair p = new Pair(b.getName(), b.getValue() != null ? b.getValue().stringValue() : null);
+                result.add(p);
+            }
+
+            return result;
+        }
+    }
+
+    private static class Pair {
+        String key, value;
+
+        private Pair(String key, String value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        private String getKey() {
+            return key;
+        }
+
+        private String getValue() {
+            return value;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            Pair pair = (Pair) o;
+
+            if (!key.equals(pair.getKey())) return false;
+            if (value != null ? !value.equals(pair.getValue()) : pair.getValue() != null) return false;
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            int result = key.hashCode();
+            result = 31 * result + (value != null ? value.hashCode() : 0);
+            return result;
+        }
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlUpdateTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlUpdateTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlUpdateTest.java
new file mode 100644
index 0000000..4e3f20e
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlUpdateTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package org.apache.marmotta.kiwi.sparql.test;
+
+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.junit.runner.RunWith;
+import org.openrdf.query.parser.sparql.SPARQLUpdateTest;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.sail.SailRepository;
+
+
+/**
+ * Run the Sesame SPARQL Update Test Suite.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class KiWiSparqlUpdateTest extends SPARQLUpdateTest {
+
+    private final KiWiConfiguration config;
+
+    public KiWiSparqlUpdateTest(KiWiConfiguration config) {
+        this.config = config;
+    }
+
+    @Override
+    protected Repository newRepository() throws Exception {
+        KiWiStore store = new KiWiStore(config);
+        KiWiSparqlSail ssail = new KiWiSparqlSail(store);
+        return new SailRepository(ssail);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf
new file mode 100644
index 0000000..219c341
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/demo-data.foaf
@@ -0,0 +1,78 @@
+<!--
+  ~ 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.
+  -->
+
+<rdf:RDF
+        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+        xmlns:foaf="http://xmlns.com/foaf/0.1/"
+        xmlns:dc="http://purl.org/dc/elements/1.1/">
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/hans_meier" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Hans Meier</foaf:name>
+        <dc:description xml:lang="en">Hans Meier is a software engineer living in Salzburg</dc:description>
+        <dc:description xml:lang="de">Hans Meier ist ein Softwareentwickler aus Salzburg</dc:description>
+        <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.software_engineering"/>
+        <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.linux"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Java" />
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+        <foaf:based_near rdf:resource="http://sws.geonames.org/2766824/"/>
+        <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/hans_meier.jpg"/>
+
+        <foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">29</foaf:age>
+
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt"/>
+
+        <foaf:account>
+            <foaf:OnlineAccount>
+                <foaf:accountName>Example</foaf:accountName>
+                <foaf:accountServiceHomepage>http://www.example.com</foaf:accountServiceHomepage>
+            </foaf:OnlineAccount>
+        </foaf:account>
+    </foaf:Person>
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/sepp_huber" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Sepp Huber</foaf:name>
+        <dc:description xml:lang="en">Sepp Huber is an alpinist living in Traunstein. He is a good climber, but not as famous as his cousin Alexander Huber.</dc:description>
+        <dc:description xml:lang="de-DE">Sepp Huber ist ein Bergsteiger aus Traunstein. Er ist ein guter Kletterer.</dc:description>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+        <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+        <foaf:based_near rdf:resource="http://dbpedia.org/resource/Traunstein"/>
+
+        <foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">31</foaf:age>
+
+
+        <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/hans_meier" />
+    </foaf:Person>
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/anna_schmidt" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Anna Schmidt</foaf:name>
+        <dc:description xml:lang="en">Anna Schmidt is working as PR manager for mountaineers coming from Garmisch-Partenkirchen. She likes mountaineering and is also a Linux enthusiast.</dc:description>
+        <foaf:interest>Literal Interest</foaf:interest>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Linux"/>
+        <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+        <foaf:based_near rdf:resource="http://dbpedia.org/resource/Garmisch-Partenkirchen"/>
+        <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt.jpg"/>
+
+        <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+    </foaf:Person>
+
+
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query1.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query1.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query1.sparql
new file mode 100644
index 0000000..3916c58
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query1.sparql
@@ -0,0 +1,23 @@
+#
+# 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/>
+
+SELECT ?p1 ?p3 WHERE {
+    ?p1 foaf:knows ?p2 .
+    ?p2 foaf:knows ?p3
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query10.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query10.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query10.sparql
new file mode 100644
index 0000000..16fa6fc
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query10.sparql
@@ -0,0 +1,27 @@
+#
+# 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/>
+
+SELECT ?fn1 ?fn2 WHERE {
+    ?p1 foaf:name ?fn1 .
+    ?p1 foaf:interest ?interest1 .
+    ?p2 foaf:name ?fn2 .
+    ?p2 foaf:interest ?interest2 .
+    FILTER( ?interest1 = ?interest2 )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query11.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query11.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query11.sparql
new file mode 100644
index 0000000..2b6f701
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query11.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?age ?i WHERE {
+    ?p1 foaf:name ?fn .
+    OPTIONAL { ?p1 foaf:age ?age } .
+    ?p1 foaf:interest ?i
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query12.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query12.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query12.sparql
new file mode 100644
index 0000000..9b075c2
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query12.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/>
+
+SELECT ?p1 ?fn ?p2 ?age WHERE {
+    ?p1 foaf:name ?fn .
+    OPTIONAL { ?p1 foaf:knows ?p2 . ?p2 foaf:age ?age }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query13.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query13.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query13.sparql
new file mode 100644
index 0000000..1d4b892
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query13.sparql
@@ -0,0 +1,28 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?friends WHERE {
+    ?p1 foaf:name ?fn .
+    {
+        SELECT (COUNT(?friend) as ?friends) WHERE {
+            ?p1 foaf:knows ?friend
+        } GROUP BY ?p1
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query14.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query14.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query14.sparql
new file mode 100644
index 0000000..978115e
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query14.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?age WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 foaf:age ?age .
+    FILTER( ?age > 30 && regex(str(?p1), "^http://localhost:8080/LMF/resource/sepp.*") )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query2.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query2.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query2.sparql
new file mode 100644
index 0000000..612202b
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query2.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?desc ?friend WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 dc:description ?desc .
+    ?p1 foaf:knows ?friend
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query3.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query3.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query3.sparql
new file mode 100644
index 0000000..26b7041
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query3.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/>
+
+SELECT ?p1 ?fn ?desc ?friend WHERE {
+    ?p1 foaf:name ?fn .
+    FILTER( regex(?fn, "Anna.*") )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query4.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query4.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query4.sparql
new file mode 100644
index 0000000..6742145
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query4.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/>
+
+SELECT ?p1 ?fn ?desc ?friend WHERE {
+    ?p1 foaf:name ?fn .
+    FILTER( regex(str(?p1), "^http://localhost:8080/LMF/resource/sepp.*") )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query5.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query5.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query5.sparql
new file mode 100644
index 0000000..8d0000d
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query5.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?age WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 foaf:age ?age .
+    FILTER( ?age > 30 )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query6.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query6.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query6.sparql
new file mode 100644
index 0000000..5bdfbb1
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query6.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?d WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 dc:description ?d .
+    FILTER( langMatches(lang(?d), "de") )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query7.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query7.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query7.sparql
new file mode 100644
index 0000000..151caa2
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query7.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?age WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 foaf:age ?age .
+    FILTER( 2013 - ?age > 1983 )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query8.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query8.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query8.sparql
new file mode 100644
index 0000000..139e1cd
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query8.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?interest WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 foaf:interest ?interest .
+    FILTER( isLiteral(?interest) )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query9.sparql
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query9.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query9.sparql
new file mode 100644
index 0000000..b07ad16
--- /dev/null
+++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/query9.sparql
@@ -0,0 +1,25 @@
+#
+# 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/>
+
+SELECT ?p1 ?fn ?interest WHERE {
+    ?p1 foaf:name ?fn .
+    ?p1 foaf:interest ?interest .
+    FILTER( isURI(?interest) )
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-transactions/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-transactions/pom.xml b/libraries/kiwi/kiwi-transactions/pom.xml
index 4be1e0a..07d3b2d 100644
--- a/libraries/kiwi/kiwi-transactions/pom.xml
+++ b/libraries/kiwi/kiwi-transactions/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.marmotta</groupId>
         <artifactId>kiwi-parent</artifactId>
-        <version>3.1.0-incubating-SNAPSHOT</version>
+        <version>3.1.0-incubating</version>
         <relativePath>../</relativePath>
     </parent>
 
@@ -63,8 +63,8 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.marmotta</groupId>
@@ -124,7 +124,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.jumpmind.symmetric.jdbc</groupId>
+            <groupId>org.postgresql</groupId>
             <artifactId>postgresql</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java b/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
index 52b92b1..6882ddf 100644
--- a/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
+++ b/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
@@ -17,16 +17,19 @@
  */
 package org.apache.marmotta.kiwi.test;
 
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assume.assumeThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.util.List;
+
 import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import org.apache.marmotta.kiwi.persistence.KiWiDialect;
-import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
-import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
-import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
 import org.apache.marmotta.kiwi.transactions.api.TransactionListener;
 import org.apache.marmotta.kiwi.transactions.model.TransactionData;
 import org.apache.marmotta.kiwi.transactions.sail.KiWiTransactionalSail;
@@ -38,7 +41,6 @@ import org.junit.Test;
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
 import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
 import org.openrdf.model.Resource;
 import org.openrdf.repository.Repository;
 import org.openrdf.repository.RepositoryConnection;
@@ -49,82 +51,19 @@ import org.openrdf.rio.RDFParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assume.assumeThat;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 /**
- * Test the Sesame repository functionality backed by the KiWi triple store. It will try running over all
- * available databases. Except for in-memory databases like H2 or Derby, database URLs must be passed as
- * system property, or otherwise the test is skipped for this database. Available system properties:
- * <ul>
- *     <li>PostgreSQL:
- *     <ul>
- *         <li>postgresql.url, e.g. jdbc:postgresql://localhost:5433/kiwitest?prepareThreshold=3</li>
- *         <li>postgresql.user (default: lmf)</li>
- *         <li>postgresql.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- *     <li>MySQL:
- *     <ul>
- *         <li>mysql.url, e.g. jdbc:mysql://localhost:3306/kiwitest?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull</li>
- *         <li>mysql.user (default: lmf)</li>
- *         <li>mysql.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- *     <li>H2:
- *     <ul>
- *         <li>h2.url, e.g. jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10</li>
- *         <li>h2.user (default: lmf)</li>
- *         <li>h2.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- * </ul>
- * <p/>
- * Author: Sebastian Schaffert
+ * Test the Sesame repository functionality backed by the KiWi triple store. 
+ * 
+ * @author Sebastian Schaffert (sschaffert@apache.org)
  */
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
 public class TransactionTest {
     private static Logger log = LoggerFactory.getLogger(TransactionTest.class);
 
-    /**
-     * Return database configurations if the appropriate parameters have been set.
-     *
-     * @return an array (database name, url, user, password)
-     */
-    @Parameterized.Parameters(name="Database Test {index}: {0} at {1}")
-    public static Iterable<Object[]> databases() {
-        String[] databases = {"H2", "PostgreSQL", "MySQL"};
-
-        List<Object[]> result = new ArrayList<Object[]>(databases.length);
-        for(String database : databases) {
-            if(System.getProperty(database.toLowerCase()+".url") != null) {
-                result.add(new Object[] {
-                        database,
-                        System.getProperty(database.toLowerCase()+".url"),
-                        System.getProperty(database.toLowerCase()+".user","lmf"),
-                        System.getProperty(database.toLowerCase()+".pass","lmf")
-                });
-            }
-        }
-        return result;
-    }
-
-
-    private KiWiDialect dialect;
-
-    private String jdbcUrl;
-
-    private String jdbcUser;
-
-    private String jdbcPass;
-
     private Repository repository;
 
     private KiWiStore store;
@@ -133,25 +72,15 @@ public class TransactionTest {
 
     private MockListener listener;
 
-    public TransactionTest(String database, String jdbcUrl, String jdbcUser, String jdbcPass) {
-        this.jdbcPass = jdbcPass;
-        this.jdbcUrl = jdbcUrl;
-        this.jdbcUser = jdbcUser;
-
-        if("H2".equals(database)) {
-            this.dialect = new H2Dialect();
-        } else if("MySQL".equals(database)) {
-            this.dialect = new MySQLDialect();
-        } else if("PostgreSQL".equals(database)) {
-            this.dialect = new PostgreSQLDialect();
-        }
-        
-        DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
+    private final KiWiConfiguration kiwiConfiguration;
+
+    public TransactionTest(KiWiConfiguration configuration) {
+        this.kiwiConfiguration = configuration;
     }
 
     @Before
     public void initDatabase() throws RepositoryException {
-        store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred");
+        store = new KiWiStore(kiwiConfiguration);
         tstore = new KiWiTransactionalSail(store);
         listener = new MockListener();
         tstore.addTransactionListener(listener);
@@ -165,17 +94,6 @@ public class TransactionTest {
         repository.shutDown();
     }
 
-    @Rule
-    public TestWatcher watchman = new TestWatcher() {
-        /**
-         * Invoked when a test is about to start
-         */
-        @Override
-        protected void starting(Description description) {
-            log.info("{} being run...", description.getMethodName());
-        }
-    };
-
 
     /**
      * Test importing data; the test will load a small sample RDF file and check whether the expected resources are
@@ -234,7 +152,7 @@ public class TransactionTest {
             connection.begin();
             List<String> resources = ImmutableList.copyOf(
                     Iterables.transform(
-                            ResourceUtils.listResources(connection),
+                            ResourceUtils.listSubjects(connection),
                             new Function<Resource, String>() {
                                 @Override
                                 public String apply(Resource input) {

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/pom.xml b/libraries/kiwi/kiwi-triplestore/pom.xml
index 6249f8d..ac82859 100644
--- a/libraries/kiwi/kiwi-triplestore/pom.xml
+++ b/libraries/kiwi/kiwi-triplestore/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.marmotta</groupId>
         <artifactId>kiwi-parent</artifactId>
-        <version>3.1.0-incubating-SNAPSHOT</version>
+        <version>3.1.0-incubating</version>
         <relativePath>../</relativePath>
     </parent>
 
@@ -36,7 +36,6 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
-                <version>2.4</version>
                 <executions>
                     <execution>
                         <goals>
@@ -106,8 +105,8 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.marmotta</groupId>
@@ -151,7 +150,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.jumpmind.symmetric.jdbc</groupId>
+            <groupId>org.postgresql</groupId>
             <artifactId>postgresql</artifactId>
             <scope>test</scope>
         </dependency>
@@ -176,6 +175,18 @@
             <artifactId>sesame-repository-sail</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.openrdf.sesame</groupId>
+            <artifactId>sesame-store-testsuite</artifactId>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>com.google.code.tempus-fugit</groupId>
+            <artifactId>tempus-fugit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
 
     </dependencies>
     

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index ca3a05c..6767100 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -33,20 +33,82 @@ import org.apache.marmotta.kiwi.persistence.KiWiDialect;
  */
 public class KiWiConfiguration {
 
+    /**
+     * A unique name for identifying this instance of KiWiPersistence. Can be used in case there are several
+     * instances running in the same environment.
+     */
     private String name;
     private String jdbcUrl;
     private String dbUser;
     private String dbPassword;
+
+    /**
+     * The default context to use when no explicit context is given in createStatement. The KiWi triple store
+     * does not support null values for the context of a triple, so this URL must be set to an appropriate value
+     */
+    private String defaultContext;
+
+    /**
+     * The context to use for storing all inferred triples. The value set here will override all contexts
+     * given to addInferredTriple, because KiWi always stores all inferred triples in the same context.
+     */
+    private String inferredContext;
+
+
+    /**
+     * The SQL dialect to use
+     */
     private KiWiDialect dialect;
 
+    /**
+     * A flag indicating if the query logging (Tomcat JDBC SlowQueryReport) is enabled or not.
+     */
+    private boolean queryLoggingEnabled = false;
+
+    /**
+     * Enable batched commit (if supported by the database dialect). If this is enabled, the KiWiConnection will
+     * use an in-memory buffer for stored triples and nodes that are committed in a batch once the limit is reached
+     * or the connection committed. Enabling this can significantly improve the performance (EXPERIMENTAL).
+     */
+    private boolean batchCommit;
+
+    private int batchSize = 10000;
+
+    /**
+     * Size of the database cursor for pre-fetching rows on database supporting this feature. If the size is set to 0,
+     * no cursor is used and all rows are retrieved in one batch.
+     *
+     * @see java.sql.PreparedStatement#setFetchSize(int)
+     */
+    private int cursorSize = 1000;
+
+    /**
+     * If enabled, and batchCommit is also true, load sequence values into static memory fields once and increment
+     * values purely in-memory. The last value is then written back on batch commits.
+     */
+    private boolean memorySequences = true;
+
+
+    private boolean commitSequencesOnCommit = true;
+
+
     public KiWiConfiguration(String name, String jdbcUrl, String dbUser, String dbPassword, KiWiDialect dialect) {
+        this(name, jdbcUrl, dbUser, dbPassword, dialect, null, null);
+    }
+
+    public KiWiConfiguration(String name, String jdbcUrl, String dbUser, String dbPassword, KiWiDialect dialect, String defaultContext, String inferredContext) {
         this.dbPassword = dbPassword;
         this.dbUser = dbUser;
         this.dialect = dialect;
         this.jdbcUrl = jdbcUrl;
         this.name = name;
+        this.defaultContext = defaultContext;
+        this.inferredContext = inferredContext;
+
+        batchCommit = dialect.isBatchSupported();
     }
 
+
     public String getDbPassword() {
         return dbPassword;
     }
@@ -66,4 +128,105 @@ public class KiWiConfiguration {
     public String getName() {
         return name;
     }
+
+    public boolean isQueryLoggingEnabled() {
+        return queryLoggingEnabled;
+    }
+
+    public void setQueryLoggingEnabled(boolean queryLoggingEnabled) {
+        this.queryLoggingEnabled = queryLoggingEnabled;
+    }
+
+    public String getDefaultContext() {
+        return defaultContext;
+    }
+
+    public void setDefaultContext(String defaultContext) {
+        this.defaultContext = defaultContext;
+    }
+
+    public String getInferredContext() {
+        return inferredContext;
+    }
+
+    public void setInferredContext(String inferredContext) {
+        this.inferredContext = inferredContext;
+    }
+
+    /**
+     * Return true if batched commit is enabled. If this is enabled, the KiWiConnection will
+     * use an in-memory buffer for stored triples and nodes that are committed in a batch once the limit is reached
+     * or the connection committed. Enabling this can significantly improve the performance (EXPERIMENTAL).
+     */
+    public boolean isBatchCommit() {
+        return batchCommit;
+    }
+
+    /**
+     * Enable batched commit (if supported by the database dialect). If this is enabled, the KiWiConnection will
+     * use an in-memory buffer for stored triples and nodes that are committed in a batch once the limit is reached
+     * or the connection committed. Enabling this can significantly improve the performance (EXPERIMENTAL).
+     */
+    public void setBatchCommit(boolean batchCommit) {
+        if(dialect.isBatchSupported()) {
+            this.batchCommit = batchCommit;
+        }
+    }
+
+    public int getBatchSize() {
+        return batchSize;
+    }
+
+    public void setBatchSize(int batchSize) {
+        this.batchSize = batchSize;
+    }
+
+    /**
+     * Size of the database cursor for pre-fetching rows on database supporting this feature. If the size is set to 0,
+     * no cursor is used and all rows are retrieved in one batch.
+     *
+     * @see java.sql.PreparedStatement#setFetchSize(int)
+     */
+    public int getCursorSize() {
+        return cursorSize;
+    }
+
+    /**
+     * Size of the database cursor for pre-fetching rows on database supporting this feature. If the size is set to 0,
+     * no cursor is used and all rows are retrieved in one batch.
+     *
+     * @see java.sql.PreparedStatement#setFetchSize(int)
+     */
+    public void setCursorSize(int cursorSize) {
+        this.cursorSize = cursorSize;
+    }
+
+    public boolean isMemorySequences() {
+        return memorySequences;
+    }
+
+    /**
+     * Enable in-memory sequences. If enabled, and batchCommit is also true, load sequence values into static memory
+     * fields once and increment values purely in-memory. The last value is then written back on batch commits. This
+     * feature can avoid many database accesses and connections and therefore give significant performance improvements.
+     * (EXPERIMENTAL).
+     */
+    public void setMemorySequences(boolean memorySequences) {
+        this.memorySequences = memorySequences;
+    }
+
+
+    public boolean isCommitSequencesOnCommit() {
+        return commitSequencesOnCommit;
+    }
+
+    /**
+     * This flag determines whether memory sequences should be stored back into the database on every commit or only
+     * when the repository shuts down. Saving back on every commit is safer, but has less performance.
+     *
+     * @param commitSequencesOnCommit
+     */
+    public void setCommitSequencesOnCommit(boolean commitSequencesOnCommit) {
+        this.commitSequencesOnCommit = commitSequencesOnCommit;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiAnonResource.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiAnonResource.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiAnonResource.java
index 1f3d37a..64801be 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiAnonResource.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiAnonResource.java
@@ -29,14 +29,8 @@ import org.openrdf.model.BNode;
  */
 public class KiWiAnonResource extends KiWiResource implements BNode {
 
-    private static HashFunction hasher = Hashing.goodFastHash(16);
-
     private static final long serialVersionUID = -873594698794527452L;
 
-    // @Transient
-    private transient HashCode goodHashCode;
-
-
     private String anonId;
 
     public KiWiAnonResource() {
@@ -110,9 +104,6 @@ public class KiWiAnonResource extends KiWiResource implements BNode {
 
     @Override
     public int hashCode() {
-        if(goodHashCode == null) {
-            goodHashCode = hasher.newHasher().putChar('A').putString(anonId).hash();
-        }
-        return goodHashCode.hashCode();
+        return anonId.hashCode();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiLiteral.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiLiteral.java
index d373254..e96220e 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiLiteral.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiLiteral.java
@@ -17,20 +17,17 @@
  */
 package org.apache.marmotta.kiwi.model.rdf;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Locale;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
 import org.apache.marmotta.commons.sesame.model.Namespaces;
-import com.google.common.hash.HashCode;
-import com.google.common.hash.HashFunction;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
 import org.openrdf.model.Literal;
 import org.openrdf.model.URI;
 import org.openrdf.model.datatypes.XMLDatatypeUtil;
 
-import javax.xml.datatype.XMLGregorianCalendar;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Locale;
-
 /**
  * KiWiLiterals store literal information from the knowledge base. They directly
  * correspond to an RDF literal stored in Sesame. KiWiLiterals are
@@ -44,23 +41,12 @@ import java.util.Locale;
  */
 public abstract class KiWiLiteral extends KiWiNode implements Literal {
 
-    private static HashFunction hasher = Hashing.goodFastHash(32);
-
-    //@Transient
-    private HashCode goodHashCode;
-
     /**
      * 
      */
     private static final long serialVersionUID = 1772323725671607249L;
 
 
-    /**
-     * An internal checksum of the content of the literal, used to efficiently check equality.
-     */
-    private String contentMd5;
-
-
     private Locale locale;
 
     private KiWiUriResource type;
@@ -180,17 +166,7 @@ public abstract class KiWiLiteral extends KiWiNode implements Literal {
 
     @Override
     public int hashCode() {
-        if(goodHashCode == null) {
-            Hasher hash = hasher.newHasher().putChar('L').putString(getContent());
-            if(getLocale() != null) {
-                hash.putString(getLocale().toString());
-            }
-            if(getType() != null) {
-                hash.putString(getType().stringValue());
-            }
-            goodHashCode = hash.hash();
-        }
-        return goodHashCode.hashCode();
+        return this.getLabel().hashCode();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
index 83ec60c..42957f3 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
@@ -57,7 +57,6 @@ public class KiWiNamespace implements Namespace, Serializable {
 
     public String getPrefix() {
         return prefix;
-        
     }
 
     public void setPrefix(String prefix) {
@@ -159,4 +158,10 @@ public class KiWiNamespace implements Namespace, Serializable {
         result = 31 * result + (deleted != null ? deleted.hashCode() : 0);
         return result;
     }
+
+	@Override
+	public int compareTo(Namespace other) {
+		return uri.compareTo(other.getName());
+	}
+	
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
index 58ff9f4..4f1b21c 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
@@ -98,7 +98,6 @@ public class KiWiTriple  implements Statement, Serializable {
         assert(subject  != null);
         assert(predicate != null);
         assert(object   != null);
-        assert(context  != null);
 	}
 
    /**
@@ -221,7 +220,7 @@ public class KiWiTriple  implements Statement, Serializable {
      * @param deletedAt
      */
     public void setDeletedAt(Date deletedAt) {
-        this.deletedAt = new Date(deletedAt.getTime());
+        this.deletedAt = deletedAt != null ? new Date(deletedAt.getTime()) : null;
     }
 
     /**
@@ -259,12 +258,10 @@ public class KiWiTriple  implements Statement, Serializable {
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
-//        if (!(o instanceof KiWiTriple)) return false;
 
-
-        KiWiTriple triple = (KiWiTriple) o;
-
-        if (!getContext().equals(triple.getContext())) return false;
+        Statement triple = (Statement) o;
+//        changed according to https://openrdf.atlassian.net/browse/SES-1924
+//        if (!getContext().equals(triple.getContext())) return false;
         if (!getObject().equals(triple.getObject())) return false;
         if (!getPredicate().equals(triple.getPredicate())) return false;
         return getSubject().equals(triple.getSubject());
@@ -273,11 +270,7 @@ public class KiWiTriple  implements Statement, Serializable {
 
     @Override
     public int hashCode() {
-        int result = getSubject().hashCode();
-        result = 31 * result + getPredicate().hashCode();
-        result = 31 * result + getObject().hashCode();
-        result = 31 * result + getContext().hashCode();
-        return result;
+        return 961 * getSubject().hashCode() + 31 * getPredicate().hashCode() + getObject().hashCode();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/582abb5b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiUriResource.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiUriResource.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiUriResource.java
index e9f64c0..4709463 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiUriResource.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiUriResource.java
@@ -33,10 +33,11 @@ public class KiWiUriResource extends KiWiResource implements URI {
 
 	private static final long serialVersionUID = -6399293877969640084L;
 
-	private static HashFunction hasher = Hashing.goodFastHash(16);
+    /**
+     * The MemURI's hash code, 0 if not yet initialized.
+     */
+    private int hashCode = 0;
 
-    //@Transient
-    private HashCode goodHashCode;
 
     private String uri;
 
@@ -134,11 +135,11 @@ public class KiWiUriResource extends KiWiResource implements URI {
 
     @Override
     public int hashCode() {
-        if(goodHashCode == null) {
-            goodHashCode = hasher.newHasher().putChar('U').putString(getUri()).hash();
+        if (hashCode == 0) {
+            hashCode = toString().hashCode();
         }
 
-        return goodHashCode.hashCode();
+        return hashCode;
     }