You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/02/19 13:52:00 UTC
[39/52] [partial] code contribution,
initial import of relevant modules of LMF-3.0.0-SNAPSHOT based on
revision 4bf944319368 of the default branch at https://code.google.com/p/lmf/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
new file mode 100644
index 0000000..11f6fc5
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -0,0 +1,1111 @@
+/*
+ * Copyright (c) 2013 The Apache Software Foundation
+ *
+ * Licensed 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.test;
+
+import at.newmedialab.sesame.commons.model.Namespaces;
+import at.newmedialab.sesame.commons.util.DateUtils;
+import info.aduna.iteration.Iterations;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.persistence.KiWiConnection;
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
+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.test.helper.DBConnectionChecker;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.openrdf.model.Statement;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+
+import static at.newmedialab.sesame.commons.model.LiteralCommons.getRDFLangStringType;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
+
+/**
+ * This test verifies the persistence functionality of 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>
+ *
+ * @see org.apache.marmotta.kiwi.persistence.KiWiConnection
+ * @see org.apache.marmotta.kiwi.persistence.KiWiPersistence
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+@RunWith(Parameterized.class)
+public class PersistenceTest {
+
+ /**
+ * 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 KiWiPersistence persistence;
+
+ public PersistenceTest(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);
+ }
+
+
+ @Before
+ public void initDatabase() throws SQLException {
+ persistence = new KiWiPersistence("test",jdbcUrl,jdbcUser,jdbcPass,dialect);
+ persistence.initDatabase();
+ }
+
+ @After
+ public void dropDatabase() throws SQLException {
+ persistence.dropDatabase();
+ persistence.shutdown();
+ }
+
+
+ @Test
+ public void testCreateDropDatabase() throws SQLException {
+ // test if database exists and has a version
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ Assert.assertThat(connection.getDatabaseTables(),hasItems("nodes","triples","namespaces"));
+ Assert.assertEquals(1, connection.getDatabaseVersion());
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+ /**
+ * Test storing and loading URI nodes.
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreUriNode() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiUriResource uri = new KiWiUriResource("http://localhost/"+ RandomStringUtils.randomAlphanumeric(8));
+ connection.storeNode(uri);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(uri.getId());
+
+ KiWiNode testUri1 = connection.loadNodeById(uri.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(uri,testUri1);
+ Assert.assertTrue(uri == testUri1);
+
+ connection.commit();
+
+ KiWiNode testUri2 = connection.loadNodeById(uri.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(uri,testUri2);
+ Assert.assertTrue(uri == testUri2);
+
+
+ KiWiNode testUri3 = connection.loadUriResource(uri.stringValue());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(uri,testUri3);
+ Assert.assertTrue(uri == testUri3);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testUri4 = connection.loadNodeById(uri.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(uri,testUri4);
+ Assert.assertTrue(uri != testUri4);
+
+ KiWiNode testUri5 = connection.loadUriResource(uri.stringValue());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(uri,testUri5);
+ Assert.assertTrue(uri != testUri5);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) uri.getId(), result.getLong("id"));
+ Assert.assertEquals(uri.stringValue(),result.getString("svalue"));
+ Assert.assertEquals("uri",result.getString("ntype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing and loading blank nodes.
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreBNode() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiAnonResource bnode = new KiWiAnonResource(RandomStringUtils.randomAlphanumeric(8));
+ connection.storeNode(bnode);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(bnode.getId());
+
+ KiWiNode testBNode1 = connection.loadNodeById(bnode.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(bnode,testBNode1);
+ Assert.assertTrue(bnode == testBNode1);
+
+ connection.commit();
+
+ KiWiNode testBNode2 = connection.loadNodeById(bnode.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(bnode,testBNode2);
+ Assert.assertTrue(bnode == testBNode2);
+
+
+ KiWiNode testBNode3 = connection.loadAnonResource(bnode.stringValue());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(bnode,testBNode3);
+ Assert.assertTrue(bnode == testBNode3);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testBNode4 = connection.loadNodeById(bnode.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(bnode,testBNode4);
+ Assert.assertTrue(bnode != testBNode4);
+
+ KiWiNode testBNode5 = connection.loadAnonResource(bnode.stringValue());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(bnode,testBNode5);
+ Assert.assertTrue(bnode != testBNode5);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long)bnode.getId(),result.getLong("id"));
+ Assert.assertEquals(bnode.stringValue(),result.getString("svalue"));
+ Assert.assertEquals("bnode",result.getString("ntype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing and loading string literals (without type and language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreStringLiteralNoType() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource stype = new KiWiUriResource(Namespaces.NS_XSD+"string");
+ connection.storeNode(stype);
+
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiStringLiteral literal = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(8),null,stype);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(), null, stype);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertTrue(literal == testLiteral3);
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,stype);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertTrue(literal != testLiteral5);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(), result.getString("svalue"));
+ Assert.assertEquals("string",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertNotNull(result.getObject("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing and loading string literals (without type but with language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreStringLiteralLanguage() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource stype = new KiWiUriResource(getRDFLangStringType());
+ connection.storeNode(stype);
+
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiStringLiteral literal = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(8), Locale.ENGLISH, stype);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertTrue(literal == testLiteral3);
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertTrue(literal != testLiteral5);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(), result.getString("svalue"));
+ Assert.assertEquals("string",result.getString("ntype"));
+ Assert.assertEquals(Locale.ENGLISH.getLanguage(),result.getString("lang"));
+ Assert.assertNotNull(result.getObject("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing and loading string literals (with type and without language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreStringLiteralType() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource uri = new KiWiUriResource("http://localhost/"+ RandomStringUtils.randomAlphanumeric(8));
+
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiStringLiteral literal = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(8), null, uri);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
+ Assert.assertTrue(literal == testLiteral3);
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
+ Assert.assertTrue(literal != testLiteral5);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='string'");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long)literal.getId(),result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
+ Assert.assertEquals("string",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing and loading string literals (with type and without language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreIntLiteral() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "integer");
+
+
+ Random rnd = new Random();
+ long value = rnd.nextLong();
+
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiIntLiteral literal = new KiWiIntLiteral(value, uri);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
+ Assert.assertTrue(literal == testLiteral3);
+
+
+ // load by integer value
+ KiWiNode testLiteral6 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral6);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
+ Assert.assertTrue(literal == testLiteral6);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
+ Assert.assertTrue(literal != testLiteral5);
+
+
+ // load by integer value
+ KiWiNode testLiteral7 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral7);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
+ Assert.assertTrue(literal != testLiteral7);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='int'");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
+ Assert.assertEquals(value,result.getLong("ivalue"));
+ Assert.assertEquals("int",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+ /**
+ * Test storing and loading string literals (with type and without language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreDoubleLiteral() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "double");
+
+
+ Random rnd = new Random();
+ double value = rnd.nextDouble();
+
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiDoubleLiteral literal = new KiWiDoubleLiteral(value, uri);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
+ Assert.assertTrue(literal == testLiteral3);
+
+
+ // load by integer value
+ KiWiNode testLiteral6 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral6);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
+ Assert.assertTrue(literal == testLiteral6);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
+ Assert.assertTrue(literal != testLiteral5);
+
+
+ // load by integer value
+ KiWiNode testLiteral7 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral7);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
+ Assert.assertTrue(literal != testLiteral7);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='double'");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
+ Assert.assertEquals(value,result.getDouble("dvalue"),0.01);
+ Assert.assertEquals("double",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+ /**
+ * Test storing and loading string literals (with type and without language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreBooleanLiteral() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "boolean");
+
+
+ Random rnd = new Random();
+ boolean value = rnd.nextBoolean();
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiBooleanLiteral literal = new KiWiBooleanLiteral(value, uri);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
+ Assert.assertTrue(literal == testLiteral3);
+
+
+ // load by integer value
+ KiWiNode testLiteral6 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral6);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
+ Assert.assertTrue(literal == testLiteral6);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
+ Assert.assertTrue(literal != testLiteral5);
+
+
+ // load by integer value
+ KiWiNode testLiteral7 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral7);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
+ Assert.assertTrue(literal != testLiteral7);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='boolean'");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
+ Assert.assertEquals(value,result.getBoolean("bvalue"));
+ Assert.assertEquals("boolean",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+ /**
+ * Test storing and loading string literals (with type and without language).
+ *
+ * @throws SQLException
+ */
+ @Test
+ public void testStoreDateLiteral() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "dateTime");
+
+
+ Date value = new Date();
+ // add a new URI to the triple store and check if it exists afterwards, before and after commit
+ KiWiDateLiteral literal = new KiWiDateLiteral(value, uri);
+ connection.storeNode(literal);
+
+ // check if it then has a database ID
+ Assert.assertNotNull(literal.getId());
+
+ KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral1);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
+ Assert.assertTrue(literal == testLiteral1);
+
+ connection.commit();
+
+ KiWiNode testLiteral2 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral2);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
+ Assert.assertTrue(literal == testLiteral2);
+
+ KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral3);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
+ Assert.assertTrue(literal == testLiteral3);
+
+
+ // load by integer value
+ KiWiNode testLiteral6 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral6);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral6).getType());
+ Assert.assertTrue(literal == testLiteral6);
+
+
+ connection.commit();
+
+
+ // clear cache and test again
+ persistence.clearCache();
+ KiWiNode testLiteral4 = connection.loadNodeById(literal.getId());
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral4);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
+ Assert.assertTrue(literal != testLiteral4);
+
+ KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
+
+ // needs to be equal, but now it should not be the same object!
+ Assert.assertEquals(literal,testLiteral5);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
+ Assert.assertTrue(literal != testLiteral5);
+
+
+ // load by integer value
+ KiWiNode testLiteral7 = connection.loadLiteral(value);
+
+ // needs to be equal, and should also be the identical object!
+ Assert.assertEquals(literal,testLiteral7);
+ Assert.assertEquals(uri,((KiWiLiteral)testLiteral7).getType());
+ Assert.assertTrue(literal != testLiteral7);
+
+ connection.commit();
+
+ // finally do a test on the nodes table, it should contain exactly one entry
+ PreparedStatement checkNodeStmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM nodes WHERE ntype='date'");
+ ResultSet result = checkNodeStmt.executeQuery();
+
+ Assert.assertTrue(result.next());
+ Assert.assertEquals((long) literal.getId(), result.getLong("id"));
+ Assert.assertEquals(literal.stringValue(),result.getString("svalue"));
+ Assert.assertEquals(DateUtils.getDateWithoutFraction(value).getTime(),result.getTimestamp("tvalue").getTime());
+ Assert.assertEquals("date",result.getString("ntype"));
+ Assert.assertNull(result.getString("lang"));
+ Assert.assertEquals((long) uri.getId(), result.getLong("ltype"));
+
+ result.close();
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+
+ /**
+ * Test storing, querying and deleting triples
+ */
+ @Test
+ public void testStoreTriples() throws Exception {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiUriResource stype = new KiWiUriResource(Namespaces.NS_XSD+"string");
+ KiWiUriResource subject = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource pred_1 = new KiWiUriResource("http://localhost/predicate/P1");
+ KiWiUriResource pred_2 = new KiWiUriResource("http://localhost/predicate/P2");
+ KiWiUriResource object_1 = new KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
+ KiWiStringLiteral object_2 = new KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32),null,stype);
+ KiWiUriResource context = new KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));
+
+ connection.storeNode(stype);
+ connection.storeNode(subject);
+ connection.storeNode(pred_1);
+ connection.storeNode(pred_2);
+ connection.storeNode(object_1);
+ connection.storeNode(object_2);
+ connection.storeNode(context);
+
+ KiWiTriple triple1 = new KiWiTriple(subject,pred_1,object_1,context);
+ KiWiTriple triple2 = new KiWiTriple(subject,pred_2,object_2,context);
+
+ connection.storeTriple(triple1);
+ connection.storeTriple(triple2);
+
+ // check querying within transaction
+ List<Statement> result1 = connection.listTriples(subject,null,null,null,false).asList();
+ Assert.assertThat(result1,hasItems((Statement)triple1,(Statement)triple2));
+
+ Assert.assertEquals(2, connection.getSize());
+ Assert.assertEquals(2, connection.getSize(context));
+ Assert.assertEquals(0, connection.getSize(subject));
+
+ connection.commit();
+
+ List<Statement> result2 = connection.listTriples(subject,null,null,null,false).asList();
+ Assert.assertThat(result2,hasItems((Statement)triple1,(Statement)triple2));
+
+ Assert.assertEquals(2, connection.getSize());
+ Assert.assertEquals(2, connection.getSize(context));
+ Assert.assertEquals(0, connection.getSize(subject));
+
+ Assert.assertThat(Iterations.asList(connection.listContexts()), hasItem((KiWiResource)context));
+
+ // clear cache and test again
+ persistence.clearCache();
+
+ List<Statement> result3 = connection.listTriples(subject,null,null,null,false).asList();
+ Assert.assertThat(result3,hasItems((Statement)triple1,(Statement)triple2));
+
+
+ Assert.assertEquals(2, connection.getSize());
+ Assert.assertEquals(2, connection.getSize(context));
+ Assert.assertEquals(0, connection.getSize(subject));
+
+ // test database contents
+ PreparedStatement stmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM triples WHERE deleted = false");
+ ResultSet dbResult1 = stmt.executeQuery();
+
+ Assert.assertTrue(dbResult1.next());
+ Assert.assertEquals((long) triple1.getId(), dbResult1.getLong("id"));
+ Assert.assertEquals((long) triple1.getSubject().getId(), dbResult1.getLong("subject"));
+ Assert.assertEquals((long) triple1.getPredicate().getId(), dbResult1.getLong("predicate"));
+ Assert.assertEquals((long)triple1.getObject().getId(),dbResult1.getLong("object"));
+
+ Assert.assertTrue(dbResult1.next());
+ Assert.assertEquals((long)triple2.getId(),dbResult1.getLong("id"));
+ Assert.assertEquals((long)triple2.getSubject().getId(),dbResult1.getLong("subject"));
+ Assert.assertEquals((long)triple2.getPredicate().getId(),dbResult1.getLong("predicate"));
+ Assert.assertEquals((long)triple2.getObject().getId(),dbResult1.getLong("object"));
+
+ dbResult1.close();
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+
+ }
+
+ // TODO: test namespaces
+ @Test
+ public void testStoreNamespaces() throws SQLException {
+ KiWiConnection connection = persistence.getConnection();
+ try {
+ KiWiNamespace ns1 = new KiWiNamespace("ns1", "http://localhost/ns1/");
+ KiWiNamespace ns2 = new KiWiNamespace("ns2", "http://localhost/ns2/");
+
+ connection.storeNamespace(ns1);
+ connection.storeNamespace(ns2);
+
+ // check before transaction commit
+ Assert.assertEquals(ns1, connection.loadNamespaceByPrefix("ns1"));
+ Assert.assertEquals(ns1, connection.loadNamespaceByUri("http://localhost/ns1/"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByPrefix("ns2"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByUri("http://localhost/ns2/"));
+ Assert.assertThat(Iterations.asList(connection.listNamespaces()),hasItems(ns1,ns2));
+
+ connection.commit();
+
+ // check after transaction commit
+ Assert.assertEquals(ns1, connection.loadNamespaceByPrefix("ns1"));
+ Assert.assertEquals(ns1, connection.loadNamespaceByUri("http://localhost/ns1/"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByPrefix("ns2"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByUri("http://localhost/ns2/"));
+ Assert.assertThat(Iterations.asList(connection.listNamespaces()),hasItems(ns1,ns2));
+
+ // clear cache and check again
+ persistence.clearCache();
+
+ Assert.assertEquals(ns1, connection.loadNamespaceByPrefix("ns1"));
+ Assert.assertEquals(ns1, connection.loadNamespaceByUri("http://localhost/ns1/"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByPrefix("ns2"));
+ Assert.assertEquals(ns2, connection.loadNamespaceByUri("http://localhost/ns2/"));
+ Assert.assertThat(Iterations.asList(connection.listNamespaces()),hasItems(ns1,ns2));
+
+
+ PreparedStatement stmt = connection.getJDBCConnection().prepareStatement("SELECT * FROM namespaces");
+ ResultSet dbResult1 = stmt.executeQuery();
+
+ Assert.assertTrue(dbResult1.next());
+ Assert.assertEquals("ns1",dbResult1.getString("prefix"));
+ Assert.assertEquals("http://localhost/ns1/",dbResult1.getString("uri"));
+
+ Assert.assertTrue(dbResult1.next());
+ Assert.assertEquals("ns2",dbResult1.getString("prefix"));
+ Assert.assertEquals("http://localhost/ns2/",dbResult1.getString("uri"));
+
+ } finally {
+ connection.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
new file mode 100644
index 0000000..c948f43
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2013 The Apache Software Foundation
+ *
+ * Licensed 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.test;
+
+import at.newmedialab.sesame.commons.repository.ResourceUtils;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import org.apache.commons.lang.RandomStringUtils;
+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.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
+import org.hamcrest.CoreMatchers;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Namespace;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+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.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.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assume.assumeThat;
+
+/**
+ * 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
+ */
+@RunWith(Parameterized.class)
+public class RepositoryTest {
+
+ private static Logger log = LoggerFactory.getLogger(RepositoryTest.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;
+
+ public RepositoryTest(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, this.dialect);
+ }
+
+ @Before
+ public void initDatabase() throws RepositoryException {
+ store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" );
+ repository = new SailRepository(store);
+ repository.initialize();
+ }
+
+ @After
+ public void dropDatabase() throws RepositoryException, SQLException {
+ store.getPersistence().dropDatabase();
+ repository.shutDown();
+ }
+
+ /**
+ * Test importing data; the test will load a small sample RDF file and check whether the expected resources are
+ * present.
+ *
+ * @throws RepositoryException
+ * @throws RDFParseException
+ * @throws IOException
+ */
+ @Test
+ public void testImport() throws RepositoryException, RDFParseException, IOException {
+ long start, end;
+
+ start = System.currentTimeMillis();
+ // load demo data
+ InputStream rdfXML = this.getClass().getResourceAsStream("demo-data.foaf");
+ assumeThat("Could not load test-data: demo-data.foaf", rdfXML, notNullValue(InputStream.class));
+
+ RepositoryConnection connectionRDF = repository.getConnection();
+ try {
+ connectionRDF.add(rdfXML, "http://localhost/foaf/", RDFFormat.RDFXML);
+ connectionRDF.commit();
+ } finally {
+ connectionRDF.close();
+ }
+ end = System.currentTimeMillis();
+
+ log.info("IMPORT: {} ms", end-start);
+
+ start = System.currentTimeMillis();
+ // get another connection and check if demo data is available
+ RepositoryConnection connection = repository.getConnection();
+
+ List<String> resources = ImmutableList.copyOf(
+ Iterables.transform(
+ ResourceUtils.listResources(connection),
+ new Function<Resource, String>() {
+ @Override
+ public String apply(Resource input) {
+ return input.stringValue();
+ }
+ }
+ )
+ );
+
+ // test if the result has the expected size
+ Assert.assertEquals(4, resources.size());
+
+ // test if the result contains all resources that have been used as subject
+ Assert.assertThat(resources, hasItems(
+ "http://localhost:8080/LMF/resource/hans_meier",
+ "http://localhost:8080/LMF/resource/sepp_huber",
+ "http://localhost:8080/LMF/resource/anna_schmidt"
+ ));
+ connection.commit();
+ connection.close();
+
+ end = System.currentTimeMillis();
+
+ log.info("QUERY EVALUATION: {} ms", end-start);
+ }
+
+ // TODO: test delete, test query,
+
+ /**
+ * Test setting, retrieving and updating namespaces through the repository API
+ * @throws RepositoryException
+ */
+ @Test
+ public void testNamespaces() throws RepositoryException {
+ RepositoryConnection connection = repository.getConnection();
+
+ connection.begin();
+ connection.setNamespace("ns1","http://localhost/ns1/");
+ connection.setNamespace("ns2","http://localhost/ns2/");
+
+ connection.commit();
+
+ Assert.assertEquals("http://localhost/ns1/", connection.getNamespace("ns1"));
+ Assert.assertEquals("http://localhost/ns2/", connection.getNamespace("ns2"));
+ Assert.assertEquals(2, connection.getNamespaces().asList().size());
+ Assert.assertThat(
+ connection.getNamespaces().asList(),
+ CoreMatchers.<Namespace>hasItems(
+ hasProperty("name", is("http://localhost/ns1/")),
+ hasProperty("name", is("http://localhost/ns2/"))
+ )
+ );
+
+ // update ns1 to a different URL
+ connection.begin();
+ connection.setNamespace("ns1","http://localhost/ns3/");
+ connection.commit();
+
+ Assert.assertEquals("http://localhost/ns3/", connection.getNamespace("ns1"));
+ Assert.assertThat(
+ connection.getNamespaces().asList(),
+ CoreMatchers.<Namespace>hasItems(
+ hasProperty("name", is("http://localhost/ns3/")),
+ hasProperty("name", is("http://localhost/ns2/"))
+ )
+ );
+
+
+ // remove ns2
+ connection.begin();
+ connection.removeNamespace("ns2");
+ connection.commit();
+
+ connection.begin();
+ Assert.assertEquals(1, connection.getNamespaces().asList().size());
+
+
+ connection.commit();
+ connection.close();
+
+ }
+
+
+ @Test
+ public void testDeleteTriple() throws RepositoryException, RDFParseException, IOException {
+ // load demo data
+ InputStream rdfXML = this.getClass().getResourceAsStream("demo-data.foaf");
+ assumeThat("Could not load test-data: demo-data.foaf", rdfXML, notNullValue(InputStream.class));
+
+ RepositoryConnection connectionRDF = repository.getConnection();
+ try {
+ connectionRDF.add(rdfXML, "http://localhost/foaf/", RDFFormat.RDFXML);
+ connectionRDF.commit();
+ } finally {
+ connectionRDF.close();
+ }
+ // get another connection and check if demo data is available
+ RepositoryConnection connection = repository.getConnection();
+
+ try {
+ connection.begin();
+ List<String> resources = ImmutableList.copyOf(
+ Iterables.transform(
+ ResourceUtils.listResources(connection),
+ new Function<Resource, String>() {
+ @Override
+ public String apply(Resource input) {
+ return input.stringValue();
+ }
+ }
+ )
+ );
+
+ // test if the result has the expected size
+ Assert.assertEquals(4, resources.size());
+
+ // test if the result contains all resources that have been used as subject
+ Assert.assertThat(resources, hasItems(
+ "http://localhost:8080/LMF/resource/hans_meier",
+ "http://localhost:8080/LMF/resource/sepp_huber",
+ "http://localhost:8080/LMF/resource/anna_schmidt"
+ ));
+ long oldsize = connection.size();
+ connection.commit();
+
+
+ // remove a resource and all its triples
+ connection.begin();
+ ResourceUtils.removeResource(connection, connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier"));
+ connection.commit();
+
+ connection.begin();
+ long newsize = connection.size();
+
+ // new size should be less, since we removed some triples
+ Assert.assertThat(newsize, lessThan(oldsize));
+
+ // the resource hans_meier should not be contained in the list of resources
+ List<String> resources2 = ImmutableList.copyOf(
+ Iterables.transform(
+ ResourceUtils.listResources(connection),
+ new Function<Resource, String>() {
+ @Override
+ public String apply(Resource input) {
+ return input.stringValue();
+ }
+ }
+ )
+ );
+
+ // test if the result has the expected size
+ Assert.assertEquals(3, resources2.size());
+
+ // test if the result does not contain the removed resource
+ Assert.assertThat(resources2, not(hasItem(
+ "http://localhost:8080/LMF/resource/hans_meier"
+ )));
+ } finally {
+ connection.commit();
+ connection.close();
+ }
+ }
+
+
+ /**
+ * Test a repeated addition of the same triple, because this is a special case in the database.
+ */
+ @Test
+ public void testRepeatedAdd() throws RepositoryException, IOException, RDFParseException {
+ // load demo data
+ InputStream rdfXML = this.getClass().getResourceAsStream("srfg-ontology.rdf");
+ assumeThat("Could not load test-data: srfg-ontology.rdf", rdfXML, notNullValue(InputStream.class));
+
+ long oldsize, newsize;
+ List<Statement> oldTriples, newTriples;
+
+ RepositoryConnection connectionRDF = repository.getConnection();
+ try {
+ connectionRDF.begin();
+ connectionRDF.add(rdfXML, "http://localhost/srfg/", RDFFormat.RDFXML);
+ connectionRDF.commit();
+
+ oldTriples = connectionRDF.getStatements(null,null,null,true).asList();
+ oldsize = connectionRDF.size();
+ } finally {
+ connectionRDF.close();
+ }
+
+
+ // get another connection and add the same data again
+ rdfXML = this.getClass().getResourceAsStream("srfg-ontology.rdf");
+ RepositoryConnection connection = repository.getConnection();
+
+ try {
+ connection.begin();
+ connection.add(rdfXML, "http://localhost/srfg/", RDFFormat.RDFXML);
+ connection.commit();
+
+ newTriples = connection.getStatements(null,null,null,true).asList();
+ newsize = connection.size();
+ } finally {
+ connection.commit();
+ connection.close();
+ }
+
+ Assert.assertEquals(oldTriples,newTriples);
+ Assert.assertEquals(oldsize,newsize);
+ }
+
+
+ /**
+ * Test adding-deleting-adding a triple
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRepeatedAddRemove() throws Exception {
+ String value = RandomStringUtils.randomAlphanumeric(8);
+
+ URI subject = repository.getValueFactory().createURI("http://localhost/resource/" + RandomStringUtils.randomAlphanumeric(8));
+ URI predicate = repository.getValueFactory().createURI("http://localhost/resource/" + RandomStringUtils.randomAlphanumeric(8));
+ Literal object1 = repository.getValueFactory().createLiteral(value);
+
+ RepositoryConnection connection1 = repository.getConnection();
+ try {
+ connection1.add(subject,predicate,object1);
+ connection1.commit();
+
+ Assert.assertTrue(connection1.hasStatement(subject,predicate,object1,true));
+
+ connection1.commit();
+ } finally {
+ connection1.close();
+ }
+
+ Literal object2 = repository.getValueFactory().createLiteral(value);
+ RepositoryConnection connection2 = repository.getConnection();
+ try {
+ Assert.assertTrue(connection2.hasStatement(subject,predicate,object2,true));
+
+ connection2.remove(subject,predicate,object2);
+ connection2.commit();
+
+ Assert.assertFalse(connection2.hasStatement(subject,predicate,object2,true));
+
+ connection2.commit();
+ } finally {
+ connection2.close();
+ }
+
+ Literal object3 = repository.getValueFactory().createLiteral(value);
+ RepositoryConnection connection3 = repository.getConnection();
+ try {
+ Assert.assertFalse(connection3.hasStatement(subject,predicate,object3,true));
+
+ connection3.add(subject,predicate,object3);
+ connection3.commit();
+
+ Assert.assertTrue(connection3.hasStatement(subject,predicate,object3,true));
+
+ connection3.commit();
+ } finally {
+ connection3.close();
+ }
+
+ Literal object4 = repository.getValueFactory().createLiteral(value);
+ RepositoryConnection connection4 = repository.getConnection();
+ try {
+ Assert.assertTrue(connection4.hasStatement(subject,predicate,object4,true));
+
+ connection4.commit();
+ } finally {
+ connection4.close();
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
new file mode 100644
index 0000000..f9cfcb8
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 The Apache Software Foundation
+ *
+ * Licensed 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.test.helper;
+
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.junit.Assume;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class DBConnectionChecker {
+
+ private DBConnectionChecker() {
+ // static only
+ }
+
+ public static void checkDatabaseAvailability(String jdbcUrl, String jdbcUser,
+ String jdbcPass, KiWiDialect dialect) {
+ try {
+ Class.forName(dialect.getDriverClass());
+ Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
+ conn.setAutoCommit(false);
+ Assume.assumeTrue("Database not available", conn.isValid(1000));
+ conn.commit();
+ conn.close();
+ } catch (SQLException e) {
+ Assume.assumeNoException("Database not available", e);
+ } catch (ClassNotFoundException e) {
+ Assume.assumeNoException("Missing DB driver", e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/resources/logback.xml b/kiwi/kiwi-triplestore/src/test/resources/logback.xml
new file mode 100644
index 0000000..08c9e0a
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/resources/logback.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ Copyright (c) 2013 Salzburg Research.
+ ~
+ ~ Licensed 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.
+ -->
+
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+<!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> -->
+ <pattern>%d{HH:mm:ss.SSS} %-5level - %msg%n</pattern>
+<!-- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> -->
+ </encoder>
+ </appender>
+
+ <logger name="com.mchange" level="INFO" />
+
+
+ <root level="debug">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/demo-data.foaf
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/demo-data.foaf b/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/demo-data.foaf
new file mode 100644
index 0000000..9f3f05f
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/demo-data.foaf
@@ -0,0 +1,69 @@
+<!--
+ ~ Copyright (c) 2012 Salzburg Research.
+ ~
+ ~ Licensed 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>Hans Meier is a software engineer living in 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: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>Sepp Huber is an alpinist living in Traunstein. He is a good climber, but not as famous as his cousin Alexander Huber.</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: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>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 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/c32963d5/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/srfg-ontology.rdf
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/srfg-ontology.rdf b/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/srfg-ontology.rdf
new file mode 100644
index 0000000..1b3bd02
--- /dev/null
+++ b/kiwi/kiwi-triplestore/src/test/resources/org/apache/marmotta/kiwi/test/srfg-ontology.rdf
@@ -0,0 +1,126 @@
+<!--
+ ~ Copyright (c) 2012 Salzburg Research.
+ ~
+ ~ Licensed 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.
+ -->
+
+<!DOCTYPE rdf:RDF [
+<!ENTITY lmf "http://localhost:8080/LMF/resource/">]>
+
+<rdf:RDF
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:lmfc="http://localhost:8080/LMF/resource/concepts/">
+
+
+ <lmfc:NationalProject about="&lmf;SNML-TNG">
+ <rdfs:label>SNML TNG</rdfs:label>
+ <rdfs:comment>Salzburg NewMediaLab - The Next Generation</rdfs:comment>
+ <lmfc:projectFolder>snml-tng</lmfc:projectFolder>
+ </lmfc:NationalProject>
+
+ <lmfc:NationalProject about="&lmf;SNML">
+ <rdfs:label>SNML</rdfs:label>
+ <rdfs:comment>Salzburg NewMediaLab</rdfs:comment>
+ <lmfc:projectFolder>snml</lmfc:projectFolder>
+ </lmfc:NationalProject>
+
+ <lmfc:NationalProject about="&lmf;myTV">
+ <rdfs:label>myTV</rdfs:label>
+ <rdfs:comment>my Semantically Enhanced Personalized TV Experience</rdfs:comment>
+ <lmfc:projectFolder>mytv</lmfc:projectFolder>
+ </lmfc:NationalProject>
+
+ <lmfc:NationalProject about="&lmf;ConnectMe">
+ <rdfs:label>ConnectMe</rdfs:label>
+ <rdfs:comment>Connected Media Experience</rdfs:comment>
+ <lmfc:projectFolder>connectme</lmfc:projectFolder>
+ </lmfc:NationalProject>
+
+ <lmfc:NationalProject about="&lmf;CAPKOM">
+ <rdfs:label>CAPKOM</rdfs:label>
+ <rdfs:comment>CAPKOM - Innovative Benutzeroberflächen für Men-schen mit kognitiver Beeinträchtigung</rdfs:comment>
+ <lmfc:projectFolder>capkom</lmfc:projectFolder>
+ </lmfc:NationalProject>
+
+
+ <lmfc:EUProject about="&lmf;KiWi">
+ <rdfs:label>KiWi</rdfs:label>
+ <rdfs:comment>KiWi - Knowledge in a Wiki</rdfs:comment>
+ <lmfc:projectFolder>kiwi</lmfc:projectFolder>
+ </lmfc:EUProject>
+
+ <lmfc:EUProject about="&lmf;IKS">
+ <rdfs:label>IKS</rdfs:label>
+ <rdfs:comment>IKS - Interactive Knowledge Stack</rdfs:comment>
+ <lmfc:projectFolder>iks</lmfc:projectFolder>
+ </lmfc:EUProject>
+
+ <lmfc:EUProject about="&lmf;Mosep">
+ <rdfs:label>Mosep</rdfs:label>
+ <rdfs:comment>Mosep - More self-esteem with my ePortfolio</rdfs:comment>
+ <lmfc:projectFolder>mosep</lmfc:projectFolder>
+ </lmfc:EUProject>
+
+ <lmfc:EUProject about="&lmf;ImportNET">
+ <rdfs:label>ImportNET</rdfs:label>
+ <rdfs:comment>Intelligent modular open source Platform for intercultural and cross-domain SME Networks</rdfs:comment>
+ <lmfc:projectFolder>importnet</lmfc:projectFolder>
+ </lmfc:EUProject>
+
+
+ <foaf:Project about="&lmf;KMT">
+ <rdfs:label>KMT</rdfs:label>
+ <rdfs:comment>Knowledge and Media Technologies</rdfs:comment>
+ </foaf:Project>
+
+
+ <foaf:Person about="&lmf;gguentner">
+ <foaf:name>Georg Güntner</foaf:name>
+ <foaf:nick>gguentner</foaf:nick>
+ <foaf:nick>georg.guentner@salzburgresearch.at</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;sschaffe">
+ <foaf:name>Sebastian Schaffert</foaf:name>
+ <foaf:nick>sschaffe</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;wbehrendt">
+ <foaf:name>Wernher Behrendt</foaf:name>
+ <foaf:nick>wbehrendt</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;uatzlinger">
+ <foaf:name>Ursula Atzlinger</foaf:name>
+ <foaf:nick>uatzlinger</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;awagner">
+ <foaf:name>Alexandra Wagner</foaf:name>
+ <foaf:nick>awagner</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;agruber">
+ <foaf:name>Andreas Gruber</foaf:name>
+ <foaf:nick>agruber</foaf:nick>
+ </foaf:Person>
+
+ <foaf:Person about="&lmf;bstroh">
+ <foaf:name>Birgit Strohmeier</foaf:name>
+ <foaf:nick>bstroh</foaf:nick>
+ </foaf:Person>
+
+
+</rdf:RDF>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-tripletable/pom.xml
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-tripletable/pom.xml b/kiwi/kiwi-tripletable/pom.xml
new file mode 100644
index 0000000..2960961
--- /dev/null
+++ b/kiwi/kiwi-tripletable/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2013 The Apache Software Foundation
+ ~
+ ~ Licensed 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>at.newmedialab.lmf</groupId>
+ <artifactId>kiwi-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kiwi-tripletable</artifactId>
+ <packaging>jar</packaging>
+
+ <name>KiWi Triplestore: Triple Table</name>
+
+ <description>
+ Provides a simple in-memory table using the Java Collections API to access triples. Additionally, the
+ triple table offers in-memory indexes for typical query operations (e.g. listing by subject).
+ </description>
+
+ <dependencies>
+ <!-- data model -->
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-model</artifactId>
+ </dependency>
+
+ <!-- Utilities -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c32963d5/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/ByteArray.java
----------------------------------------------------------------------
diff --git a/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/ByteArray.java b/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/ByteArray.java
new file mode 100644
index 0000000..f5a9ccc
--- /dev/null
+++ b/kiwi/kiwi-tripletable/src/main/java/org/apache/marmotta/kiwi/model/caching/ByteArray.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed 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.model.caching;
+
+import java.util.Arrays;
+
+/**
+* Add file description here!
+* <p/>
+* Author: Sebastian Schaffert
+*/
+final class ByteArray implements Comparable<ByteArray> {
+
+ private byte[] data;
+
+ ByteArray(byte[] data) {
+ this.data = data;
+ }
+
+ @Override
+ public int compareTo(ByteArray o) {
+ for(int i=0; i < data.length && i < o.data.length; i++) {
+ if(((int) data[i] & 0xff) < ((int) o.data[i] & 0xff)) {
+ return -1;
+ } else if(((int)data[i] & 0xff) > ((int)o.data[i] & 0xff)) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ByteArray byteArray = (ByteArray) o;
+
+ return Arrays.equals(data, byteArray.data);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return data != null ? Arrays.hashCode(data) : 0;
+ }
+}