You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/01/17 11:33:41 UTC

[1/2] git commit: - added externalizer test to make sure they do what they are supposed to - removed support for database-based ID generators to make use of id generators easier

Updated Branches:
  refs/heads/develop 56911f071 -> 347d72d29


- added externalizer test to make sure they do what they are supposed to
- removed support for database-based ID generators to make use of id generators easier


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/ed0c6e8c
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/ed0c6e8c
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/ed0c6e8c

Branch: refs/heads/develop
Commit: ed0c6e8c0e868d94fa0352b624443d894c807dd2
Parents: 9d4865e
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Jan 17 11:33:10 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Jan 17 11:33:10 2014 +0100

----------------------------------------------------------------------
 .../kiwi/caching/BNodeExternalizer.java         |   2 +-
 .../caching/BooleanLiteralExternalizer.java     |   2 +-
 .../kiwi/caching/DateLiteralExternalizer.java   |   2 +-
 .../kiwi/caching/DoubleLiteralExternalizer.java |   2 +-
 .../marmotta/kiwi/caching/ExternalizerIds.java  |  41 +++
 .../kiwi/caching/IntLiteralExternalizer.java    |   2 +-
 .../kiwi/caching/StringLiteralExternalizer.java |   2 +-
 .../marmotta/kiwi/caching/UriExternalizer.java  |   2 +-
 .../generator/DatabaseSequenceIDGenerator.java  |  75 -----
 .../marmotta/kiwi/generator/IDGenerator.java    |  22 +-
 .../kiwi/generator/IDGeneratorType.java         |  12 -
 .../generator/MemorySequenceIDGenerator.java    | 178 -----------
 .../kiwi/generator/SnowflakeIDGenerator.java    |  26 +-
 .../kiwi/generator/UUIDRandomIDGenerator.java   |  26 +-
 .../kiwi/generator/UUIDTimeIDGenerator.java     |  25 +-
 .../kiwi/persistence/KiWiConnection.java        |   6 +-
 .../marmotta/kiwi/test/TestValueFactory.java    | 318 +++++++++++++++++++
 .../test/externalizer/ExternalizerTest.java     | 188 +++++++++++
 .../kiwi/test/generator/SnowflakeTest.java      |   4 +-
 .../kiwi/test/generator/UUIDRandomTest.java     |   4 +-
 .../kiwi/test/generator/UUIDTimeTest.java       |   4 +-
 21 files changed, 565 insertions(+), 378 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
index 79c8b51..36212a8 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
@@ -42,7 +42,7 @@ public class BNodeExternalizer implements AdvancedExternalizer<KiWiAnonResource>
 
     @Override
     public Integer getId() {
-        return 23;
+        return ExternalizerIds.BNODE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
index 9c3c88d..5a32cf7 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
@@ -42,7 +42,7 @@ public class BooleanLiteralExternalizer implements AdvancedExternalizer<KiWiBool
 
     @Override
     public Integer getId() {
-        return 31;
+        return ExternalizerIds.BOOL_LITERAL;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
index 58c6aac..ba0db2b 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
@@ -42,7 +42,7 @@ public class DateLiteralExternalizer implements AdvancedExternalizer<KiWiDateLit
 
     @Override
     public Integer getId() {
-        return 29;
+        return ExternalizerIds.DATE_LITERAL;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
index cb755a6..710a8a3 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
@@ -42,7 +42,7 @@ public class DoubleLiteralExternalizer implements AdvancedExternalizer<KiWiDoubl
 
     @Override
     public Integer getId() {
-        return 37;
+        return ExternalizerIds.DOUBLE_LITERAL;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
new file mode 100644
index 0000000..da1eb64
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
@@ -0,0 +1,41 @@
+/*
+ * 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.caching;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerIds {
+
+    public static final int URI = 17;
+
+    public static final int BNODE = 23;
+
+    public static final int STRING_LITERAL = 19;
+
+    public static final int INT_LITERAL = 39;
+
+    public static final int DOUBLE_LITERAL = 37;
+
+    public static final int DATE_LITERAL = 29;
+
+    public static final int BOOL_LITERAL = 31;
+
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
index 64c1b04..8001f87 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
@@ -42,7 +42,7 @@ public class IntLiteralExternalizer implements AdvancedExternalizer<KiWiIntLiter
 
     @Override
     public Integer getId() {
-        return 37;
+        return ExternalizerIds.INT_LITERAL;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
index d8ad4d8..0d0559b 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
@@ -43,7 +43,7 @@ public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStrin
 
     @Override
     public Integer getId() {
-        return 19;
+        return ExternalizerIds.STRING_LITERAL;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
index 176db19..3139db1 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
@@ -41,7 +41,7 @@ public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
 
     @Override
     public Integer getId() {
-        return 17;
+        return ExternalizerIds.URI;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/DatabaseSequenceIDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/DatabaseSequenceIDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/DatabaseSequenceIDGenerator.java
deleted file mode 100644
index ddaa094..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/DatabaseSequenceIDGenerator.java
+++ /dev/null
@@ -1,75 +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.kiwi.generator;
-
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Generate IDs using database sequences
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DatabaseSequenceIDGenerator implements IDGenerator {
-
-    public DatabaseSequenceIDGenerator() {
-    }
-
-
-    /**
-     * Initialise the generator for the given persistence and module
-     */
-    @Override
-    public void init(KiWiPersistence persistence, String scriptName) {
-    }
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws java.sql.SQLException
-     */
-    @Override
-    public void commit(KiWiPersistence persistence, Connection con) throws SQLException {
-    }
-
-    /**
-     * Shut down this id generator, performing any cleanups that might be necessary.
-     *
-     * @param persistence
-     */
-    @Override
-    public void shutdown(KiWiPersistence persistence) {
-
-    }
-
-    /**
-     * Return the next unique id for the type with the given name using the generator's id generation strategy.
-     *
-     * @param name
-     * @return
-     */
-    @Override
-    public long getId(String name, KiWiConnection connection) throws SQLException {
-        return connection.getDatabaseSequence(name);
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGenerator.java
index 2318a8d..19a122c 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGenerator.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGenerator.java
@@ -17,12 +17,8 @@
 
 package org.apache.marmotta.kiwi.generator;
 
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-
 /**
  * An interface for database ID generators.
  *
@@ -32,25 +28,9 @@ public interface IDGenerator {
 
     /**
      * Return the next unique id for the type with the given name using the generator's id generation strategy.
-     * @param name
-     *
      * @return
      */
-    public long getId(String name, KiWiConnection connection) throws SQLException;
-
-    /**
-     * Initialise the generator for the given persistence and module
-     */
-    public void init(KiWiPersistence persistence, String scriptName);
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws java.sql.SQLException
-     */
-    void commit(KiWiPersistence persistence, Connection con) throws SQLException;
+    public long getId();
 
     /**
      * Shut down this id generator, performing any cleanups that might be necessary.

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGeneratorType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGeneratorType.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGeneratorType.java
index 86bb6a2..50e4c71 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGeneratorType.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/IDGeneratorType.java
@@ -23,18 +23,6 @@ package org.apache.marmotta.kiwi.generator;
  * @author Sebastian Schaffert (sschaffert@apache.org)
  */
 public enum IDGeneratorType {
-    /**
-     * Generate keys using database sequences (for databases which support it) or atomic table updates
-     */
-    DATABASE_SEQUENCE,
-
-    /**
-     * Load the sequences in-memory on startup and generate ids by incrementing an atomic counter. Much faster
-     * than database sequences and backwards-compatible, but only works for exclusive connections to the
-     * database (i.e. no other application is accessing the same database)
-     */
-    MEMORY_SEQUENCE,
-
 
     /**
      * Generate row ids using the least significant 8 bytes of time-based UUIDs as described in http://www.ietf.org/rfc/rfc4122.txt

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/MemorySequenceIDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/MemorySequenceIDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/MemorySequenceIDGenerator.java
deleted file mode 100644
index 908bc44..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/MemorySequenceIDGenerator.java
+++ /dev/null
@@ -1,178 +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.kiwi.generator;
-
-import com.google.common.util.concurrent.AtomicLongMap;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Generate unique IDs by incrementing an in-memory atomic long value for each sequence. This method is much faster
- * than database sequences and backwards compatible (because values are written back to the database on each commit),
- * but it does not work reliably if several applications access the same database.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class MemorySequenceIDGenerator implements IDGenerator {
-    private static Logger log = LoggerFactory.getLogger(MemorySequenceIDGenerator.class);
-
-    /**
-     * A map holding in-memory sequences to be used for sequence caching in case the appropriate configuration option
-     * is configued and batched commits are enabled.
-     */
-    private AtomicLongMap<String> memorySequences;
-
-
-    // keep track which memory sequences have been updated and need to be written back
-    private Set<String> sequencesUpdated;
-
-    private ReentrantLock sequencesLock;
-
-
-
-    public MemorySequenceIDGenerator() {
-        this.sequencesLock = new ReentrantLock();
-        this.sequencesUpdated = new HashSet<>();
-        memorySequences = AtomicLongMap.create();
-    }
-
-    /**
-     * Initialise in-memory sequences if the feature is enabled.
-     */
-    @Override
-    public void init(KiWiPersistence persistence, String scriptName) {
-        sequencesLock.lock();
-        try {
-            try {
-                Connection con = persistence.getJDBCConnection(true);
-                try {
-                    for(String sequenceName : persistence.getDialect().listSequences(scriptName)) {
-
-                        // load sequence value from database
-                        // if there is a preparation needed to update the transaction, run it first
-                        if(persistence.getDialect().hasStatement(sequenceName+".prep")) {
-                            PreparedStatement prepNodeId = con.prepareStatement(persistence.getDialect().getStatement(sequenceName+".prep"));
-                            prepNodeId.executeUpdate();
-                            prepNodeId.close();
-                        }
-
-                        PreparedStatement queryNodeId = con.prepareStatement(persistence.getDialect().getStatement(sequenceName));
-                        ResultSet resultNodeId = queryNodeId.executeQuery();
-                        try {
-                            if(resultNodeId.next()) {
-                                memorySequences.put(sequenceName,resultNodeId.getLong(1)-1);
-                            } else {
-                                throw new SQLException("the sequence did not return a new value");
-                            }
-                        } finally {
-                            resultNodeId.close();
-                        }
-
-                        con.commit();
-                    }
-                } finally {
-                    persistence.releaseJDBCConnection(con);
-                }
-            } catch(SQLException ex) {
-                log.warn("database error: could not initialise in-memory sequences",ex);
-            }
-        } finally {
-            sequencesLock.unlock();
-        }
-
-    }
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws SQLException
-     */
-    @Override
-    public void commit(KiWiPersistence persistence, Connection con) throws SQLException {
-        sequencesLock.lock();
-        try {
-            // clear existing list of updated sequences
-            Set<String> updated = this.sequencesUpdated;
-            this.sequencesUpdated = new HashSet<>();
-
-            try {
-                for(Map.Entry<String,Long> entry : memorySequences.asMap().entrySet()) {
-                    if( updated.contains(entry.getKey()) && entry.getValue() > 0) {
-                        PreparedStatement updateSequence = con.prepareStatement(persistence.getDialect().getStatement(entry.getKey()+".set"));
-                        updateSequence.setLong(1, entry.getValue());
-                        if(updateSequence.execute()) {
-                            updateSequence.getResultSet().close();
-                        } else {
-                            updateSequence.getUpdateCount();
-                        }
-                    }
-                }
-            } catch(SQLException ex) {
-                // MySQL deadlock state, in this case we retry anyways
-                if(!"40001".equals(ex.getSQLState())) {
-                    log.error("SQL exception:",ex);
-                }
-                throw ex;
-            }
-
-        } finally {
-            sequencesLock.unlock();
-        }
-    }
-
-    /**
-     * Shut down this id generator, performing any cleanups that might be necessary.
-     *
-     * @param persistence
-     */
-    @Override
-    public void shutdown(KiWiPersistence persistence) {
-
-    }
-
-    /**
-     * Return the next unique id for the type with the given name using the generator's id generation strategy.
-     *
-     * @param name
-     * @return
-     */
-    @Override
-    public long getId(String name, KiWiConnection connection) throws SQLException {
-        sequencesUpdated.add(name);
-
-        if(memorySequences != null) {
-            return memorySequences.incrementAndGet(name);
-        } else {
-            return 0;
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java
index efdac26..823ae9d 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/SnowflakeIDGenerator.java
@@ -17,7 +17,6 @@
 
 package org.apache.marmotta.kiwi.generator;
 
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,8 +25,6 @@ import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.UnknownHostException;
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.util.Enumeration;
 import java.util.Random;
 
@@ -116,27 +113,13 @@ public class SnowflakeIDGenerator implements IDGenerator {
     }
 
 
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws java.sql.SQLException
-     */
-    @Override
-    public void commit(KiWiPersistence persistence, Connection con) throws SQLException {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
     /**
      * Return the next unique id for the type with the given name using the generator's id generation strategy.
      *
-     * @param name
      * @return
      */
     @Override
-    public synchronized long getId(String name, KiWiConnection connection) throws SQLException {
+    public synchronized long getId() {
         long timestamp = System.currentTimeMillis();
         if(timestamp<lastTimestamp) {
             log.warn("Clock moved backwards. Refusing to generate id for {} milliseconds.",(lastTimestamp - timestamp));
@@ -163,13 +146,6 @@ public class SnowflakeIDGenerator implements IDGenerator {
     }
 
     /**
-     * Initialise the generator for the given persistence and module
-     */
-    @Override
-    public void init(KiWiPersistence persistence, String scriptName) {
-    }
-
-    /**
      * Shut down this id generator, performing any cleanups that might be necessary.
      *
      * @param persistence

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDRandomIDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDRandomIDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDRandomIDGenerator.java
index d5863d3..9ce8b75 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDRandomIDGenerator.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDRandomIDGenerator.java
@@ -19,12 +19,8 @@ package org.apache.marmotta.kiwi.generator;
 
 import com.fasterxml.uuid.Generators;
 import com.fasterxml.uuid.impl.RandomBasedGenerator;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
 
-import java.sql.Connection;
-import java.sql.SQLException;
-
 /**
  * Generate a long id using the least significant bits of a secure random UUDI
  *
@@ -40,25 +36,6 @@ public class UUIDRandomIDGenerator implements IDGenerator {
 
 
     /**
-     * Initialise the generator for the given persistence and module
-     */
-    @Override
-    public void init(KiWiPersistence persistence, String scriptName) {
-    }
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws java.sql.SQLException
-     */
-    @Override
-    public void commit(KiWiPersistence persistence, Connection con) throws SQLException {
-    }
-
-
-    /**
      * Shut down this id generator, performing any cleanups that might be necessary.
      *
      * @param persistence
@@ -71,11 +48,10 @@ public class UUIDRandomIDGenerator implements IDGenerator {
     /**
      * Return the next unique id for the type with the given name using the generator's id generation strategy.
      *
-     * @param name
      * @return
      */
     @Override
-    public long getId(String name, KiWiConnection connection) {
+    public long getId() {
         return generator.generate().getMostSignificantBits();
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDTimeIDGenerator.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDTimeIDGenerator.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDTimeIDGenerator.java
index 11662a2..a91bf61 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDTimeIDGenerator.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/generator/UUIDTimeIDGenerator.java
@@ -21,15 +21,12 @@ import com.fasterxml.uuid.EthernetAddress;
 import com.fasterxml.uuid.Generators;
 import com.fasterxml.uuid.ext.FileBasedTimestampSynchronizer;
 import com.fasterxml.uuid.impl.TimeBasedGenerator;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
 
 /**
  * Generate a long id using the most significant bits of a time-based UUID.
@@ -60,25 +57,6 @@ public class UUIDTimeIDGenerator implements IDGenerator {
 
 
     /**
-     * Initialise the generator for the given persistence and module
-     */
-    @Override
-    public void init(KiWiPersistence persistence, String scriptName) {
-    }
-
-    /**
-     * Commit the current state of memory sequences to the database using the connection passed as second argument.
-     *
-     * @param persistence
-     * @param con
-     * @throws java.sql.SQLException
-     */
-    @Override
-    public void commit(KiWiPersistence persistence, Connection con) throws SQLException {
-    }
-
-
-    /**
      * Shut down this id generator, performing any cleanups that might be necessary.
      *
      * @param persistence
@@ -98,11 +76,10 @@ public class UUIDTimeIDGenerator implements IDGenerator {
     /**
      * Return the next unique id for the type with the given name using the generator's id generation strategy.
      *
-     * @param name
      * @return
      */
     @Override
-    public synchronized long getId(String name, KiWiConnection connection) {
+    public synchronized long getId() {
         return generator.generate().getMostSignificantBits();
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index f4da3f5..20b6656 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -1744,7 +1744,7 @@ public class KiWiConnection implements AutoCloseable {
      * @throws SQLException
      */
     public long getNextSequence(String sequenceName) throws SQLException {
-        return persistence.getIdGenerator().getId(sequenceName,this);
+        return persistence.getIdGenerator().getId();
     }
 
     public long getDatabaseSequence(String sequenceName) throws SQLException {
@@ -2020,10 +2020,6 @@ public class KiWiConnection implements AutoCloseable {
         execution.execute(connection, new RetryCommand<Void>() {
             @Override
             public Void run() throws SQLException {
-                if(connection != null) {
-                    persistence.getIdGenerator().commit(persistence, connection);
-                }
-
                 if(tripleBatch != null && tripleBatch.size() > 0) {
                     flushBatch();
                 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/TestValueFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/TestValueFactory.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/TestValueFactory.java
new file mode 100644
index 0000000..3c68fb9
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/TestValueFactory.java
@@ -0,0 +1,318 @@
+/*
+ * 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.test;
+
+import com.google.common.base.Preconditions;
+import org.apache.marmotta.commons.sesame.model.LiteralCommons;
+import org.apache.marmotta.kiwi.generator.SnowflakeIDGenerator;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.openrdf.model.*;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * A value factory creating KiWi values without requiring a real repository
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class TestValueFactory implements ValueFactory {
+
+    private SnowflakeIDGenerator idGenerator;
+
+    public TestValueFactory() {
+        idGenerator = new SnowflakeIDGenerator(1);
+    }
+
+    /**
+     * Creates a new URI from the supplied string-representation.
+     *
+     * @param uri A string-representation of a URI.
+     * @return An object representing the URI.
+     * @throws IllegalArgumentException If the supplied string does not resolve to a legal (absolute) URI.
+     */
+    @Override
+    public URI createURI(String uri) {
+        KiWiUriResource r = new KiWiUriResource(uri, new Date());
+        r.setId(idGenerator.getId());
+
+        return r;
+    }
+
+    /**
+     * Creates a new URI from the supplied namespace and local name. Calling this
+     * method is funtionally equivalent to calling {@link #createURI(String)
+     * createURI(namespace+localName)}, but allows the ValueFactory to reuse
+     * supplied namespace and local name strings whenever possible. Note that the
+     * values returned by {@link org.openrdf.model.URI#getNamespace()} and
+     * {@link org.openrdf.model.URI#getLocalName()} are not necessarily the same as the values that
+     * are supplied to this method.
+     *
+     * @param namespace The URI's namespace.
+     * @param localName The URI's local name.
+     * @throws IllegalArgumentException If the supplied namespace and localname do not resolve to a legal
+     *                                  (absolute) URI.
+     */
+    @Override
+    public URI createURI(String namespace, String localName) {
+        return createURI(namespace+localName);
+    }
+
+    /**
+     * Creates a new bNode.
+     *
+     * @return An object representing the bNode.
+     */
+    @Override
+    public BNode createBNode() {
+        return createBNode(Long.toHexString(idGenerator.getId()));
+    }
+
+    /**
+     * Creates a new blank node with the given node identifier.
+     *
+     * @param nodeID The blank node identifier.
+     * @return An object representing the blank node.
+     */
+    @Override
+    public BNode createBNode(String nodeID) {
+        KiWiAnonResource r = new KiWiAnonResource(nodeID, new Date());
+        r.setId(idGenerator.getId());
+
+        return r;
+    }
+
+    /**
+     * Creates a new literal with the supplied label.
+     *
+     * @param label The literal's label.
+     */
+    @Override
+    public Literal createLiteral(String label) {
+        KiWiLiteral l = new KiWiStringLiteral(label, new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new literal with the supplied label and language attribute.
+     *
+     * @param label    The literal's label.
+     * @param language The literal's language attribute, or <tt>null</tt> if the literal
+     */
+    @Override
+    public Literal createLiteral(String label, String language) {
+        KiWiLiteral l = new KiWiStringLiteral(label, Locale.forLanguageTag(language), null, new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new literal with the supplied label and datatype.
+     *
+     * @param label    The literal's label.
+     * @param datatype The literal's datatype, or <tt>null</tt> if the literal doesn't
+     */
+    @Override
+    public Literal createLiteral(String label, URI datatype) {
+        KiWiUriResource t;
+        if(datatype instanceof KiWiUriResource) {
+            t = (KiWiUriResource) datatype;
+        } else {
+            t = (KiWiUriResource) createURI(datatype.stringValue());
+        }
+
+        KiWiLiteral l = new KiWiStringLiteral(label, null, t, new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:boolean</tt>-typed literal representing the
+     * specified value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:boolean</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(boolean value) {
+        KiWiLiteral l = new KiWiBooleanLiteral(value, (KiWiUriResource) createURI(LiteralCommons.getXSDType(Boolean.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:byte</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:byte</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(byte value) {
+        KiWiLiteral l = new KiWiIntLiteral(Long.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Byte.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:short</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:short</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(short value) {
+        KiWiLiteral l = new KiWiIntLiteral(Long.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Short.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:int</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:int</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(int value) {
+        KiWiLiteral l = new KiWiIntLiteral(Long.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Integer.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:long</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:long</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(long value) {
+        KiWiLiteral l = new KiWiIntLiteral(Long.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Long.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:float</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:float</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(float value) {
+        KiWiLiteral l = new KiWiDoubleLiteral(Double.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Float.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new <tt>xsd:double</tt>-typed literal representing the specified
+     * value.
+     *
+     * @param value The value for the literal.
+     * @return An <tt>xsd:double</tt>-typed literal for the specified value.
+     */
+    @Override
+    public Literal createLiteral(double value) {
+        KiWiLiteral l = new KiWiDoubleLiteral(Double.valueOf(value), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Double.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new literal representing the specified calendar that is typed
+     * using the appropriate XML Schema date/time datatype.
+     *
+     * @param calendar The value for the literal.
+     * @return An typed literal for the specified calendar.
+     */
+    @Override
+    public Literal createLiteral(XMLGregorianCalendar calendar) {
+        Date value = calendar.toGregorianCalendar().getTime();
+
+        return createLiteral(value);
+    }
+
+    /**
+     * Creates a new literal representing the specified date that is typed using
+     * the appropriate XML Schema date/time datatype.
+     *
+     * @param date
+     * @since 2.7.0
+     */
+    @Override
+    public Literal createLiteral(Date date) {
+        KiWiLiteral l = new KiWiDateLiteral(date, (KiWiUriResource) createURI(LiteralCommons.getXSDType(Date.class)), new Date());
+        l.setId(idGenerator.getId());
+
+        return l;
+    }
+
+    /**
+     * Creates a new statement with the supplied subject, predicate and object.
+     *
+     * @param subject   The statement's subject.
+     * @param predicate The statement's predicate.
+     * @param object    The statement's object.
+     * @return The created statement.
+     */
+    @Override
+    public Statement createStatement(Resource subject, URI predicate, Value object) {
+        return createStatement(subject, predicate, object, null);
+    }
+
+    /**
+     * Creates a new statement with the supplied subject, predicate and object
+     * and associated context.
+     *
+     * @param subject   The statement's subject.
+     * @param predicate The statement's predicate.
+     * @param object    The statement's object.
+     * @param context   The statement's context.
+     * @return The created statement.
+     */
+    @Override
+    public Statement createStatement(Resource subject, URI predicate, Value object, Resource context) {
+        Preconditions.checkArgument(subject instanceof KiWiNode);
+        Preconditions.checkArgument(predicate instanceof KiWiNode);
+        Preconditions.checkArgument(object instanceof KiWiNode);
+        Preconditions.checkArgument(context == null || context instanceof KiWiNode);
+
+        KiWiTriple t = new KiWiTriple((KiWiResource)subject,(KiWiUriResource)predicate,(KiWiNode)object,(KiWiResource)context, new Date());
+        t.setId(idGenerator.getId());
+
+        return t;
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
new file mode 100644
index 0000000..9e57267
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.test.externalizer;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.kiwi.caching.*;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.test.TestValueFactory;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.marshall.StreamingMarshaller;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerTest {
+
+    private static ValueFactory valueFactory = new TestValueFactory();
+
+    private static Random rnd = new Random();
+
+    private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
+
+    private static StreamingMarshaller marshaller;
+
+
+    @BeforeClass
+    public static void setup() {
+        AdvancedExternalizer[] externalizers =  new AdvancedExternalizer[] {
+                new UriExternalizer(),
+                new BNodeExternalizer(),
+                new StringLiteralExternalizer(),
+                new DateLiteralExternalizer(),
+                new BooleanLiteralExternalizer(),
+                new IntLiteralExternalizer(),
+                new DoubleLiteralExternalizer()
+        };
+
+
+        GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+                .transport()
+                    .defaultTransport()
+                .serialization()
+                    .addAdvancedExternalizer(externalizers)
+                .build();
+
+        Configuration             defaultConfiguration = new ConfigurationBuilder()
+                .clustering()
+                    .cacheMode(CacheMode.DIST_ASYNC)
+                .build();
+
+        EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+        marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+
+    }
+
+
+    @Test
+    public void testUriResource() throws Exception {
+        marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
+    }
+
+    @Test
+    public void testBNode() throws Exception {
+        marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
+    }
+
+    @Test
+    public void testStringLiteral() throws Exception {
+        marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
+    }
+
+    @Test
+    public void testLangLiteral() throws Exception {
+        marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
+    }
+
+    @Test
+    public void testTypeLiteral() throws Exception {
+        marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
+    }
+
+
+    @Test
+    public void testIntLiteral() throws Exception {
+        marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
+    }
+
+
+    /**
+     * Run the given object through the marshaller using an in-memory stream.
+     * @param origin
+     * @param <T>
+     * @return
+     */
+    private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+        log.info("- testing externalizer directly ...");
+        ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream(outBytes);
+
+        externalizer.writeObject(out, origin);
+        out.close();
+
+        log.info("  object {}: serialized with {} bytes", origin, outBytes.size());
+
+        ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+        ObjectInputStream in = new ObjectInputStream(inBytes);
+
+        T destination1 = externalizer.readObject(in);
+
+        Assert.assertEquals(origin,destination1);
+
+        log.info("- testing externalizer with infinispan marshaller ...");
+
+        byte[] bytes = marshaller.objectToByteBuffer(origin);
+        log.info("  object {}: serialized with {} bytes", origin, bytes.length);
+
+        Object destination2 = marshaller.objectFromByteBuffer(bytes);
+
+        Assert.assertEquals(origin, destination2);
+
+    }
+
+
+    /**
+     * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+     * @return
+     */
+    protected Value randomNode() {
+        Value object;
+        switch(rnd.nextInt(6)) {
+            case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+                break;
+            case 1: object = valueFactory.createBNode();
+                break;
+            case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+                break;
+            case 3: object = valueFactory.createLiteral(rnd.nextInt());
+                break;
+            case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+                break;
+            case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+                break;
+            default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+                break;
+
+        }
+        return object;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/SnowflakeTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/SnowflakeTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/SnowflakeTest.java
index 9e153b0..28b0881 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/SnowflakeTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/SnowflakeTest.java
@@ -52,7 +52,7 @@ public class SnowflakeTest {
         long start = System.currentTimeMillis();
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
             count++;
             log.trace("Generated ID: {}", id);
         }
@@ -68,7 +68,7 @@ public class SnowflakeTest {
         long oldid = 0;
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
 
             Assert.assertNotEquals(oldid,id);
             oldid = id;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDRandomTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDRandomTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDRandomTest.java
index 43debb5..f96627b 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDRandomTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDRandomTest.java
@@ -55,7 +55,7 @@ public class UUIDRandomTest {
         long start = System.currentTimeMillis();
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
             count++;
             log.trace("Generated ID: {}", id);
         }
@@ -72,7 +72,7 @@ public class UUIDRandomTest {
         long oldid = 0;
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
 
             Assert.assertNotEquals(oldid,id);
             oldid = id;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/ed0c6e8c/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDTimeTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDTimeTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDTimeTest.java
index 43dea59..be37894 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDTimeTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/generator/UUIDTimeTest.java
@@ -55,7 +55,7 @@ public class UUIDTimeTest {
         long start = System.currentTimeMillis();
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
             count++;
             log.trace("Generated ID: {}", id);
         }
@@ -72,7 +72,7 @@ public class UUIDTimeTest {
         long oldid = 0;
 
         while(System.currentTimeMillis() < start + 5000) {
-            long id = generator.getId(null,null);
+            long id = generator.getId();
 
             Assert.assertNotEquals(oldid,id);
             oldid = id;


[2/2] git commit: Merge remote-tracking branch 'origin/develop' into develop

Posted by ss...@apache.org.
Merge remote-tracking branch 'origin/develop' into develop


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/347d72d2
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/347d72d2
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/347d72d2

Branch: refs/heads/develop
Commit: 347d72d291647642da87112355b4f7a9d831a40d
Parents: ed0c6e8 56911f0
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Jan 17 11:33:23 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Jan 17 11:33:23 2014 +0100

----------------------------------------------------------------------
 .../ldclient/services/ldclient/LDClient.java    |   2 +-
 .../ldclient/ldclient-provider-freebase/pom.xml |  72 +++++++++++++
 .../endpoint/freebase/FreebaseEndpoint.java     |  38 +++++++
 .../provider/freebase/FreebaseProvider.java     | 101 +++++++++++++++++++
 ...ache.marmotta.ldclient.api.endpoint.Endpoint |   1 +
 ....marmotta.ldclient.api.provider.DataProvider |   1 +
 .../test/freebase/TestFreebaseProvider.java     |  76 ++++++++++++++
 .../src/test/resources/logback.xml              |  27 +++++
 .../ldclient/test/freebase/m.07zqbwz.sparql     |  26 +++++
 .../ldclient/test/freebase/m.0nzm.sparql        |  27 +++++
 .../ldclient/test/freebase/m.0wqhskn.sparql     |  27 +++++
 libraries/ldclient/pom.xml                      |   5 +-
 12 files changed, 400 insertions(+), 3 deletions(-)
----------------------------------------------------------------------