marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject [24/32] git commit: simplified KiWiNode I/O by moving all redundant methods to a separate class
Date Mon, 17 Mar 2014 10:23:15 GMT
simplified KiWiNode I/O by moving all redundant methods to a separate class


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

Branch: refs/heads/develop
Commit: 7c40b532b9a3dd1699418f3784c41a7a24101704
Parents: 766bef0
Author: Sebastian Schaffert <sschaffert@apache.org>
Authored: Wed Mar 5 14:36:14 2014 +0100
Committer: Sebastian Schaffert <sschaffert@apache.org>
Committed: Wed Mar 5 14:36:14 2014 +0100

----------------------------------------------------------------------
 .../hazelcast/serializer/BNodeSerializer.java   |  17 +-
 .../serializer/BooleanLiteralSerializer.java    |  22 +-
 .../serializer/DateLiteralSerializer.java       |  22 +-
 .../serializer/DoubleLiteralSerializer.java     |  22 +-
 .../serializer/IntLiteralSerializer.java        |  22 +-
 .../serializer/StringLiteralSerializer.java     |  29 +-
 .../hazelcast/serializer/TripleSerializer.java  | 101 +--
 .../hazelcast/serializer/UriSerializer.java     |  86 +--
 .../externalizer/BNodeExternalizer.java         |  17 +-
 .../BooleanLiteralExternalizer.java             |  22 +-
 .../externalizer/DateLiteralExternalizer.java   |  22 +-
 .../externalizer/DoubleLiteralExternalizer.java |  22 +-
 .../externalizer/IntLiteralExternalizer.java    |  22 +-
 .../externalizer/StringLiteralExternalizer.java |  29 +-
 .../externalizer/TripleExternalizer.java        |  99 +--
 .../externalizer/UriExternalizer.java           |  85 +--
 libraries/kiwi/kiwi-loader/pom.xml              |   9 -
 .../org/apache/marmotta/kiwi/io/KiWiIO.java     | 636 +++++++++++++++++++
 .../LDCachingKiWiPersistenceConnection.java     |   6 +-
 .../ldcache/services/test/LDCacheKiWiTest.java  |   5 +
 20 files changed, 692 insertions(+), 603 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
index e105b39..4ec58b4 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
@@ -20,11 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -42,22 +41,12 @@ public class BNodeSerializer implements StreamSerializer<KiWiAnonResource> {
 
     @Override
     public void write(ObjectDataOutput output, KiWiAnonResource object) throws IOException {
-        output.writeLong(object.getId());
-        DataIO.writeString(output, object.stringValue());
-        output.writeLong(object.getCreated().getTime());
+        KiWiIO.writeBNode(output, object);
     }
 
     @Override
     public KiWiAnonResource read(ObjectDataInput input) throws IOException {
-        long id = input.readLong(); 
-        String anonId = DataIO.readString(input);
-
-        Date created = new Date(input.readLong());
-
-        KiWiAnonResource r = new KiWiAnonResource(anonId,created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readBNode(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
index 0246e35..5792b84 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
@@ -20,11 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -41,27 +40,12 @@ public class BooleanLiteralSerializer implements StreamSerializer<KiWiBooleanLit
 
     @Override
     public void write(ObjectDataOutput output, KiWiBooleanLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeBoolean(object.booleanValue());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeBooleanLiteral(output,object);
     }
 
     @Override
     public KiWiBooleanLiteral read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-        boolean content = input.readBoolean();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readBooleanLiteral(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
index 1ddd75d..209378c 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
@@ -20,11 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -41,27 +40,12 @@ public class DateLiteralSerializer implements StreamSerializer<KiWiDateLiteral>
 
     @Override
     public void write(ObjectDataOutput output, KiWiDateLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getDateContent().getTime());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeDateLiteral(output,object);
     }
 
     @Override
     public KiWiDateLiteral read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-        Date content = new Date(input.readLong());
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readDateLiteral(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
index 61ba8e4..3a4719a 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
@@ -20,11 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -40,27 +39,12 @@ public class DoubleLiteralSerializer implements StreamSerializer<KiWiDoubleLiter
 
     @Override
     public void write(ObjectDataOutput output, KiWiDoubleLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeDouble(object.getDoubleContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeDoubleLiteral(output,object);
     }
 
     @Override
     public KiWiDoubleLiteral read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-        double content = input.readDouble();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readDoubleLiteral(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
index 12d49b4..4d77667 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
@@ -20,11 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -41,27 +40,12 @@ public class IntLiteralSerializer implements StreamSerializer<KiWiIntLiteral> {
 
     @Override
     public void write(ObjectDataOutput output, KiWiIntLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getIntContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeIntLiteral(output,object);
     }
 
     @Override
     public KiWiIntLiteral read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-        long content = input.readLong();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readIntLiteral(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
index 6531aa0..687c321 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
@@ -20,13 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
-import java.util.Locale;
 
 /**
  * Add file description here!
@@ -43,32 +40,12 @@ public class StringLiteralSerializer implements StreamSerializer<KiWiStringLiter
 
     @Override
     public void write(ObjectDataOutput output, KiWiStringLiteral object) throws IOException {
-        output.writeLong(object.getId());
-
-        DataIO.writeString(output, object.getContent());
-        DataIO.writeString(output, object.getLanguage());
-
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeStringLiteral(output,object);
     }
 
     @Override
     public KiWiStringLiteral read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-
-        String content = DataIO.readString(input);
-        String lang    = DataIO.readString(input);
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readStringLiteral(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
index cb2de2a..fa5b312 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
@@ -20,15 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
@@ -36,12 +31,6 @@ import java.util.Date;
  */
 public class TripleSerializer implements StreamSerializer<KiWiTriple> {
 
-
-    public static final int MODE_DEFAULT = 1;
-    public static final int MODE_PREFIX  = 2;
-
-
-
     @Override
     public int getTypeId() {
         return ExternalizerIds.TRIPLE;
@@ -49,96 +38,12 @@ public class TripleSerializer implements StreamSerializer<KiWiTriple> {
 
     @Override
     public void write(ObjectDataOutput output, KiWiTriple object) throws IOException {
-        output.writeLong(object.getId());
-
-        // in case subject and object are both uris we use a special prefix-compressed mode
-        if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
-            String sUri = object.getSubject().stringValue();
-            String oUri = object.getObject().stringValue();
-
-            String prefix = StringUtils.getCommonPrefix(sUri,oUri);
-
-            output.writeByte(MODE_PREFIX);
-            DataIO.writeString(output,prefix);
-
-            output.writeLong(object.getSubject().getId());
-            DataIO.writeString(output, sUri.substring(prefix.length()));
-            output.writeLong(object.getSubject().getCreated().getTime());
-
-            output.writeObject(object.getPredicate());
-
-            output.writeLong(object.getObject().getId());
-            DataIO.writeString(output, oUri.substring(prefix.length()));
-            output.writeLong(object.getObject().getCreated().getTime());
-        } else {
-            output.writeByte(MODE_DEFAULT);
-
-            output.writeObject(object.getSubject());
-            output.writeObject(object.getPredicate());
-            output.writeObject(object.getObject());
-        }
-
-        output.writeObject(object.getContext());
-        output.writeObject(object.getCreator());
-        output.writeBoolean(object.isDeleted());
-        output.writeBoolean(object.isInferred());
-        output.writeBoolean(object.isNewTriple());
-        output.writeLong(object.getCreated().getTime());
-        if(object.getDeletedAt() != null) {
-            output.writeLong(object.getDeletedAt().getTime());
-        } else {
-            output.writeLong(0);
-        }
+        KiWiIO.writeTriple(output,object);
     }
 
     @Override
     public KiWiTriple read(ObjectDataInput input) throws IOException {
-
-        KiWiTriple result = new KiWiTriple();
-        result.setId(input.readLong());
-
-        int mode = input.readByte();
-        if(mode == MODE_PREFIX) {
-            String prefix = DataIO.readString(input);
-
-            long sId = input.readLong();
-            String sUri = prefix + DataIO.readString(input);
-            long sTime = input.readLong();
-            KiWiUriResource s = new KiWiUriResource(sUri);
-            s.setId(sId);
-            s.setCreated(new Date(sTime));
-            result.setSubject(s);
-
-            result.setPredicate((KiWiUriResource) input.readObject());
-
-            long oId = input.readLong();
-            String oUri = prefix + DataIO.readString(input);
-            long oTime = input.readLong();
-            KiWiUriResource o = new KiWiUriResource(oUri);
-            o.setId(oId);
-            o.setCreated(new Date(oTime));
-            result.setObject(o);
-
-        } else {
-            result.setSubject((KiWiResource) input.readObject());
-            result.setPredicate((KiWiUriResource) input.readObject());
-            result.setObject((KiWiNode) input.readObject());
-        }
-        result.setContext((KiWiResource) input.readObject());
-        result.setCreator((KiWiResource) input.readObject());
-        result.setDeleted(input.readBoolean());
-        result.setInferred(input.readBoolean());
-        result.setNewTriple(input.readBoolean());
-
-        result.setCreated(new Date(input.readLong()));
-
-        long deletedAt = input.readLong();
-        if(deletedAt > 0) {
-            result.setDeletedAt(new Date(deletedAt));
-        }
-
-
-        return result;
+        return KiWiIO.readTriple(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
index 0f235d5..5418436 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
@@ -20,13 +20,10 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
 import com.hazelcast.nio.ObjectDataInput;
 import com.hazelcast.nio.ObjectDataOutput;
 import com.hazelcast.nio.serialization.StreamSerializer;
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.openrdf.model.vocabulary.*;
 
 import java.io.IOException;
-import java.util.Date;
 
 /**
  * Add file description here!
@@ -35,16 +32,6 @@ import java.util.Date;
  */
 public class UriSerializer implements StreamSerializer<KiWiUriResource> {
 
-    private static final int PREFIX_UNKNOWN = 0;
-    private static final int PREFIX_XSD     = 1;
-    private static final int PREFIX_RDF     = 2;
-    private static final int PREFIX_RDFS    = 3;
-    private static final int PREFIX_SKOS    = 4;
-    private static final int PREFIX_DC      = 5;
-    private static final int PREFIX_DCT     = 6;
-    private static final int PREFIX_OWL     = 7;
-
-
     @Override
     public int getTypeId() {
         return ExternalizerIds.URI;
@@ -52,79 +39,12 @@ public class UriSerializer implements StreamSerializer<KiWiUriResource> {
 
     @Override
     public void write(ObjectDataOutput output, KiWiUriResource object) throws IOException {
-        output.writeLong(object.getId());
-
-        // compression for commonly used constant prefixes
-        if(object.stringValue().startsWith(XSD.NAMESPACE)) {
-            output.writeByte(PREFIX_XSD);
-            DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
-            output.writeByte(PREFIX_RDF);
-            DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
-            output.writeByte(PREFIX_RDFS);
-            DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
-            output.writeByte(PREFIX_SKOS);
-            DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
-            output.writeByte(PREFIX_DC);
-            DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
-            output.writeByte(PREFIX_DCT);
-            DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
-            output.writeByte(PREFIX_OWL);
-            DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
-        } else {
-            output.writeByte(PREFIX_UNKNOWN);
-            DataIO.writeString(output, object.stringValue());
-        }
-
-        output.writeLong(object.getCreated().getTime());
+        KiWiIO.writeURI(output, object);
     }
 
     @Override
     public KiWiUriResource read(ObjectDataInput input) throws IOException {
-        long id = input.readLong();
-
-        int prefixMode = input.readByte();
-        String uriPrefix = "";
-        String uriSuffix = DataIO.readString(input);
-
-        switch (prefixMode) {
-            case PREFIX_XSD:
-                uriPrefix = XSD.NAMESPACE;
-                break;
-            case PREFIX_RDF:
-                uriPrefix = RDF.NAMESPACE;
-                break;
-            case PREFIX_RDFS:
-                uriPrefix = RDFS.NAMESPACE;
-                break;
-            case PREFIX_SKOS:
-                uriPrefix = SKOS.NAMESPACE;
-                break;
-            case PREFIX_DC:
-                uriPrefix = DC.NAMESPACE;
-                break;
-            case PREFIX_DCT:
-                uriPrefix = DCTERMS.NAMESPACE;
-                break;
-            case PREFIX_OWL:
-                uriPrefix = OWL.NAMESPACE;
-                break;
-            default:
-                uriPrefix = "";
-                break;
-        }
-
-        Date created = new Date(input.readLong());
-
-        KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readURI(input);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
index e9ad806..d94c9ce 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
@@ -17,7 +17,7 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
@@ -25,7 +25,6 @@ import org.infinispan.commons.util.Util;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -48,22 +47,12 @@ public class BNodeExternalizer extends BaseExternalizer<KiWiAnonResource> implem
 
     @Override
     public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
-        output.writeLong(object.getId());
-        DataIO.writeString(output, object.stringValue());
-        output.writeLong(object.getCreated().getTime());
+        KiWiIO.writeBNode(output, object);
     }
 
     @Override
     public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        String anonId = DataIO.readString(input);
-
-        Date created = new Date(input.readLong());
-
-        KiWiAnonResource r = new KiWiAnonResource(anonId,created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readBNode(input);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
index 73793bf..a079eeb 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
@@ -17,15 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -47,26 +46,11 @@ public class BooleanLiteralExternalizer extends BaseExternalizer<KiWiBooleanLite
 
     @Override
     public void writeObject(ObjectOutput output, KiWiBooleanLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeBoolean(object.booleanValue());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeBooleanLiteral(output,object);
     }
 
     @Override
     public KiWiBooleanLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        boolean content = input.readBoolean();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readBooleanLiteral(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
index 532d70e..b4f804c 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
@@ -17,15 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -47,26 +46,11 @@ public class DateLiteralExternalizer extends BaseExternalizer<KiWiDateLiteral> i
 
     @Override
     public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getDateContent().getTime());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeDateLiteral(output,object);
     }
 
     @Override
     public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        Date content = new Date(input.readLong());
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readDateLiteral(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
index 66b40f9..d5748b5 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
@@ -17,15 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -47,26 +46,11 @@ public class DoubleLiteralExternalizer extends BaseExternalizer<KiWiDoubleLitera
 
     @Override
     public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeDouble(object.getDoubleContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeDoubleLiteral(output,object);
     }
 
     @Override
     public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        double content = input.readDouble();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readDoubleLiteral(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
index 3f2052a..82eb719 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
@@ -17,15 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -47,26 +46,11 @@ public class IntLiteralExternalizer extends BaseExternalizer<KiWiIntLiteral> imp
 
     @Override
     public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
-        output.writeLong(object.getId());
-        output.writeLong(object.getIntContent());
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeIntLiteral(output,object);
     }
 
     @Override
     public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-        long content = input.readLong();
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readIntLiteral(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
index 015698c..62f9da2 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
@@ -17,17 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -49,31 +46,11 @@ public class StringLiteralExternalizer extends BaseExternalizer<KiWiStringLitera
 
     @Override
     public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
-        output.writeLong(object.getId());
-
-        DataIO.writeString(output, object.getContent());
-        DataIO.writeString(output, object.getLanguage());
-
-        output.writeObject(object.getDatatype());
-
-        output.writeLong(object.getCreated().getTime());
-
+        KiWiIO.writeStringLiteral(output,object);
     }
 
     @Override
     public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-
-        String content = DataIO.readString(input);
-        String lang    = DataIO.readString(input);
-
-        KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
-        Date created = new Date(input.readLong());
-
-        KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readStringLiteral(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
index 562475d..97c24ea 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
@@ -17,19 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
-import org.apache.commons.lang3.StringUtils;
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -39,10 +34,6 @@ import java.util.Set;
 public class TripleExternalizer extends BaseExternalizer<KiWiTriple> implements AdvancedExternalizer<KiWiTriple> {
 
 
-    public static final int MODE_DEFAULT = 1;
-    public static final int MODE_PREFIX  = 2;
-
-
     @Override
     public Set<Class<? extends KiWiTriple>> getTypeClasses() {
         return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
@@ -55,95 +46,11 @@ public class TripleExternalizer extends BaseExternalizer<KiWiTriple> implements
 
     @Override
     public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
-        output.writeLong(object.getId());
-
-        // in case subject and object are both uris we use a special prefix-compressed mode
-        if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
-            String sUri = object.getSubject().stringValue();
-            String oUri = object.getObject().stringValue();
-
-            String prefix = StringUtils.getCommonPrefix(sUri,oUri);
-
-            output.writeByte(MODE_PREFIX);
-            DataIO.writeString(output,prefix);
-
-            output.writeLong(object.getSubject().getId());
-            DataIO.writeString(output, sUri.substring(prefix.length()));
-            output.writeLong(object.getSubject().getCreated().getTime());
-
-            output.writeObject(object.getPredicate());
-
-            output.writeLong(object.getObject().getId());
-            DataIO.writeString(output, oUri.substring(prefix.length()));
-            output.writeLong(object.getObject().getCreated().getTime());
-        } else {
-            output.writeByte(MODE_DEFAULT);
-
-            output.writeObject(object.getSubject());
-            output.writeObject(object.getPredicate());
-            output.writeObject(object.getObject());
-        }
-
-        output.writeObject(object.getContext());
-        output.writeObject(object.getCreator());
-        output.writeBoolean(object.isDeleted());
-        output.writeBoolean(object.isInferred());
-        output.writeBoolean(object.isNewTriple());
-        output.writeLong(object.getCreated().getTime());
-        if(object.getDeletedAt() != null) {
-            output.writeLong(object.getDeletedAt().getTime());
-        } else {
-            output.writeLong(0);
-        }
+        KiWiIO.writeTriple(output,object);
     }
 
     @Override
     public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-
-        KiWiTriple result = new KiWiTriple();
-        result.setId(input.readLong());
-
-        int mode = input.readByte();
-        if(mode == MODE_PREFIX) {
-            String prefix = DataIO.readString(input);
-
-            long sId = input.readLong();
-            String sUri = prefix + DataIO.readString(input);
-            long sTime = input.readLong();
-            KiWiUriResource s = new KiWiUriResource(sUri);
-            s.setId(sId);
-            s.setCreated(new Date(sTime));
-            result.setSubject(s);
-
-            result.setPredicate((KiWiUriResource) input.readObject());
-
-            long oId = input.readLong();
-            String oUri = prefix + DataIO.readString(input);
-            long oTime = input.readLong();
-            KiWiUriResource o = new KiWiUriResource(oUri);
-            o.setId(oId);
-            o.setCreated(new Date(oTime));
-            result.setObject(o);
-
-        } else {
-            result.setSubject((KiWiResource) input.readObject());
-            result.setPredicate((KiWiUriResource) input.readObject());
-            result.setObject((KiWiNode) input.readObject());
-        }
-        result.setContext((KiWiResource) input.readObject());
-        result.setCreator((KiWiResource) input.readObject());
-        result.setDeleted(input.readBoolean());
-        result.setInferred(input.readBoolean());
-        result.setNewTriple(input.readBoolean());
-
-        result.setCreated(new Date(input.readLong()));
-
-        long deletedAt = input.readLong();
-        if(deletedAt > 0) {
-            result.setDeletedAt(new Date(deletedAt));
-        }
-
-
-        return result;
+        return KiWiIO.readTriple(input);
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
index cfd9dc2..d29f87a 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
@@ -17,17 +17,14 @@
 
 package org.apache.marmotta.kiwi.infinispan.externalizer;
 
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.io.KiWiIO;
 import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
 import org.infinispan.commons.marshall.AdvancedExternalizer;
 import org.infinispan.commons.util.Util;
-import org.openrdf.model.vocabulary.*;
 
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.Date;
 import java.util.Set;
 
 /**
@@ -37,15 +34,6 @@ import java.util.Set;
  */
 public class UriExternalizer extends BaseExternalizer<KiWiUriResource> implements AdvancedExternalizer<KiWiUriResource> {
 
-    private static final int PREFIX_UNKNOWN = 0;
-    private static final int PREFIX_XSD     = 1;
-    private static final int PREFIX_RDF     = 2;
-    private static final int PREFIX_RDFS    = 3;
-    private static final int PREFIX_SKOS    = 4;
-    private static final int PREFIX_DC      = 5;
-    private static final int PREFIX_DCT     = 6;
-    private static final int PREFIX_OWL     = 7;
-
     @Override
     public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
         return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
@@ -58,79 +46,12 @@ public class UriExternalizer extends BaseExternalizer<KiWiUriResource> implement
 
     @Override
     public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
-        output.writeLong(object.getId());
-
-        // compression for commonly used constant prefixes
-        if(object.stringValue().startsWith(XSD.NAMESPACE)) {
-            output.writeByte(PREFIX_XSD);
-            DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
-            output.writeByte(PREFIX_RDF);
-            DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
-            output.writeByte(PREFIX_RDFS);
-            DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
-            output.writeByte(PREFIX_SKOS);
-            DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
-            output.writeByte(PREFIX_DC);
-            DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
-            output.writeByte(PREFIX_DCT);
-            DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
-        } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
-            output.writeByte(PREFIX_OWL);
-            DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
-        } else {
-            output.writeByte(PREFIX_UNKNOWN);
-            DataIO.writeString(output, object.stringValue());
-        }
-
-        output.writeLong(object.getCreated().getTime());
+        KiWiIO.writeURI(output, object);
     }
 
     @Override
     public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-        long id = input.readLong();
-
-        int prefixMode = input.readByte();
-        String uriPrefix = "";
-        String uriSuffix = DataIO.readString(input);
-
-        switch (prefixMode) {
-            case PREFIX_XSD:
-                uriPrefix = XSD.NAMESPACE;
-                break;
-            case PREFIX_RDF:
-                uriPrefix = RDF.NAMESPACE;
-                break;
-            case PREFIX_RDFS:
-                uriPrefix = RDFS.NAMESPACE;
-                break;
-            case PREFIX_SKOS:
-                uriPrefix = SKOS.NAMESPACE;
-                break;
-            case PREFIX_DC:
-                uriPrefix = DC.NAMESPACE;
-                break;
-            case PREFIX_DCT:
-                uriPrefix = DCTERMS.NAMESPACE;
-                break;
-            case PREFIX_OWL:
-                uriPrefix = OWL.NAMESPACE;
-                break;
-            default:
-                uriPrefix = "";
-                break;
-        }
-
-        Date created = new Date(input.readLong());
-
-        KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
-        r.setId(id);
-
-        return r;
+        return KiWiIO.readURI(input);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-loader/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-loader/pom.xml b/libraries/kiwi/kiwi-loader/pom.xml
index 9d13fb1..3913a72 100644
--- a/libraries/kiwi/kiwi-loader/pom.xml
+++ b/libraries/kiwi/kiwi-loader/pom.xml
@@ -81,15 +81,6 @@
             <type>test-jar</type>
         </dependency>
         <dependency>
-            <!-- License: CPL-1.0 http://www.opensource.org/licenses/cpl1.0
-                As a MAVEN dependency it is not included in a source release. As a TEST dependency
-                it is not included in a BINARY release, so no need to mention in N&L. -->
-            <groupId>com.github.stefanbirkner</groupId>
-            <artifactId>system-rules</artifactId>
-            <version>1.4.0</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.openrdf.sesame</groupId>
             <artifactId>sesame-rio-rdfxml</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
new file mode 100644
index 0000000..584b22a
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
@@ -0,0 +1,636 @@
+/*
+ * 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.io;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.openrdf.model.vocabulary.*;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class KiWiIO {
+
+    private static final int PREFIX_UNKNOWN = 0;
+    private static final int PREFIX_XSD     = 1;
+    private static final int PREFIX_RDF     = 2;
+    private static final int PREFIX_RDFS    = 3;
+    private static final int PREFIX_SKOS    = 4;
+    private static final int PREFIX_DC      = 5;
+    private static final int PREFIX_DCT     = 6;
+    private static final int PREFIX_OWL     = 7;
+
+
+    private static final int TYPE_URI       = 1;
+    private static final int TYPE_BNODE     = 2;
+    private static final int TYPE_BOOLEAN   = 3;
+    private static final int TYPE_DATE      = 4;
+    private static final int TYPE_DOUBLE    = 5;
+    private static final int TYPE_INT       = 6;
+    private static final int TYPE_STRING    = 7;
+
+
+    public static final int MODE_DEFAULT = 1;
+    public static final int MODE_PREFIX  = 2;
+
+
+    private static Map<Class<? extends KiWiNode>, Integer> classTable = new HashMap<>();
+    static {
+        classTable.put(KiWiUriResource.class,    TYPE_URI);
+        classTable.put(KiWiAnonResource.class,   TYPE_BNODE);
+        classTable.put(KiWiBooleanLiteral.class, TYPE_BOOLEAN);
+        classTable.put(KiWiDateLiteral.class,    TYPE_DATE);
+        classTable.put(KiWiDoubleLiteral.class,  TYPE_DOUBLE);
+        classTable.put(KiWiIntLiteral.class,     TYPE_INT);
+        classTable.put(KiWiStringLiteral.class,  TYPE_STRING);
+    }
+
+    /**
+     * Efficiently serialize a KiWiNode to a DataOutput destination. The type of node will be encoded with a single
+     * byte usinbg the TYPE_* constants defined in this class
+     *
+     * @param output  DataOutput destination
+     * @param node  KiWiNode to serialize
+     * @throws IOException
+     */
+    public static void writeNode(DataOutput output, KiWiNode node) throws IOException {
+        if(node == null) {
+            output.writeByte(0);
+        } else {
+            int type = classTable.get(node.getClass());
+            output.writeByte(type);
+            switch (type) {
+                case TYPE_URI:
+                    writeURI(output, (KiWiUriResource) node);
+                    break;
+                case TYPE_BNODE:
+                    writeBNode(output, (KiWiAnonResource) node);
+                    break;
+                case TYPE_BOOLEAN:
+                    writeBooleanLiteral(output, (KiWiBooleanLiteral) node);
+                    break;
+                case TYPE_DATE:
+                    writeDateLiteral(output, (KiWiDateLiteral) node);
+                    break;
+                case TYPE_DOUBLE:
+                    writeDoubleLiteral(output, (KiWiDoubleLiteral) node);
+                    break;
+                case TYPE_INT:
+                    writeIntLiteral(output, (KiWiIntLiteral) node);
+                    break;
+                case TYPE_STRING:
+                    writeStringLiteral(output, (KiWiStringLiteral) node);
+                    break;
+                default:
+                    throw new IllegalArgumentException("unknown KiWiNode type: "+node.getClass());
+            }
+        }
+    }
+
+
+    /**
+     * Read a KiWiNode serialized with writeNode and return it. The type indicator is used to determine which type
+     * of resource to instantiate.
+     *
+     * @param input DataInput source
+     * @return an instance of a subclass of KiWiNode, depending on the type indicator read from the source
+     * @throws IOException
+     */
+    public static KiWiNode readNode(DataInput input) throws IOException {
+        int type = input.readByte();
+        switch (type) {
+            case 0:
+                return null;
+            case TYPE_URI:
+                return readURI(input);
+            case TYPE_BNODE:
+                return readBNode(input);
+            case TYPE_BOOLEAN:
+                return readBooleanLiteral(input);
+            case TYPE_DATE:
+                return readDateLiteral(input);
+            case TYPE_DOUBLE:
+                return readDoubleLiteral(input);
+            case TYPE_INT:
+                return readIntLiteral(input);
+            case TYPE_STRING:
+                return readStringLiteral(input);
+            default:
+                throw new IllegalArgumentException("unknown KiWiNode type: "+type);
+        }
+
+    }
+
+    /**
+     * Efficiently serialize a KiWiUriResource to a DataOutput destination, using prefix compression for commonly used
+     * prefixes.
+     *
+     * @param out  DataOutput destination
+     * @param uri  KiWiUriResource to serialize
+     * @throws IOException
+     */
+    public static void writeURI(DataOutput out, KiWiUriResource uri) throws IOException {
+        if(uri == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(uri.getId());
+
+            // compression for commonly used constant prefixes
+            if(uri.stringValue().startsWith(XSD.NAMESPACE)) {
+                out.writeByte(PREFIX_XSD);
+                DataIO.writeString(out, uri.stringValue().substring(XSD.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(RDF.NAMESPACE)) {
+                out.writeByte(PREFIX_RDF);
+                DataIO.writeString(out, uri.stringValue().substring(RDF.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(RDFS.NAMESPACE)) {
+                out.writeByte(PREFIX_RDFS);
+                DataIO.writeString(out, uri.stringValue().substring(RDFS.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(SKOS.NAMESPACE)) {
+                out.writeByte(PREFIX_SKOS);
+                DataIO.writeString(out, uri.stringValue().substring(SKOS.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(DC.NAMESPACE)) {
+                out.writeByte(PREFIX_DC);
+                DataIO.writeString(out, uri.stringValue().substring(DC.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(DCTERMS.NAMESPACE)) {
+                out.writeByte(PREFIX_DCT);
+                DataIO.writeString(out, uri.stringValue().substring(DCTERMS.NAMESPACE.length()));
+            } else if(uri.stringValue().startsWith(OWL.NAMESPACE)) {
+                out.writeByte(PREFIX_OWL);
+                DataIO.writeString(out, uri.stringValue().substring(OWL.NAMESPACE.length()));
+            } else {
+                out.writeByte(PREFIX_UNKNOWN);
+                DataIO.writeString(out, uri.stringValue());
+            }
+
+            out.writeLong(uri.getCreated().getTime());
+        }
+    }
+
+
+    /**
+     * Read a KiWiUriResource serialized with writeURI and return it.
+     *
+     * @param input DataInput source
+     * @return a KiWiUriResource
+     * @throws IOException
+     */
+    public static KiWiUriResource readURI(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+
+
+            int prefixMode = input.readByte();
+            String uriPrefix = "";
+            String uriSuffix = DataIO.readString(input);
+
+            switch (prefixMode) {
+                case PREFIX_XSD:
+                    uriPrefix = XSD.NAMESPACE;
+                    break;
+                case PREFIX_RDF:
+                    uriPrefix = RDF.NAMESPACE;
+                    break;
+                case PREFIX_RDFS:
+                    uriPrefix = RDFS.NAMESPACE;
+                    break;
+                case PREFIX_SKOS:
+                    uriPrefix = SKOS.NAMESPACE;
+                    break;
+                case PREFIX_DC:
+                    uriPrefix = DC.NAMESPACE;
+                    break;
+                case PREFIX_DCT:
+                    uriPrefix = DCTERMS.NAMESPACE;
+                    break;
+                case PREFIX_OWL:
+                    uriPrefix = OWL.NAMESPACE;
+                    break;
+                default:
+                    uriPrefix = "";
+                    break;
+            }
+
+            Date created = new Date(input.readLong());
+
+            KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiAnonResource to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param bnode the KiWiAnonResource to serialize
+     * @throws IOException
+     */
+    public static void writeBNode(DataOutput out, KiWiAnonResource bnode) throws IOException {
+        if(bnode == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(bnode.getId());
+            DataIO.writeString(out, bnode.stringValue());
+            out.writeLong(bnode.getCreated().getTime());
+        }
+    }
+
+    /**
+     * Read a KiWiAnonResource serialized with writeBNode from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiAnonResource
+     * @throws IOException
+     */
+    public static KiWiAnonResource readBNode(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            String anonId = DataIO.readString(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiAnonResource r = new KiWiAnonResource(anonId,created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiBooleanLiteral to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param literal the KiWiBooleanLiteral to serialize
+     * @throws IOException
+     */
+    public static void writeBooleanLiteral(DataOutput out, KiWiBooleanLiteral literal) throws IOException {
+        if(literal == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(literal.getId());
+            out.writeBoolean(literal.booleanValue());
+            writeURI(out, literal.getType());
+            out.writeLong(literal.getCreated().getTime());
+        }
+    }
+
+
+    /**
+     * Read a KiWiBooleanLiteral serialized with writeBooleanLiteral from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiBooleanLiteral
+     * @throws IOException
+     */
+    public static KiWiBooleanLiteral readBooleanLiteral(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            boolean content = input.readBoolean();
+
+            KiWiUriResource dtype = readURI(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiDateLiteral to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param literal the KiWiDateLiteral to serialize
+     * @throws IOException
+     */
+    public static void writeDateLiteral(DataOutput out, KiWiDateLiteral literal) throws IOException {
+        if(literal == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(literal.getId());
+            out.writeLong(literal.getDateContent().getTime());
+            writeURI(out, literal.getType());
+            out.writeLong(literal.getCreated().getTime());
+        }
+    }
+
+
+    /**
+     * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiDateLiteral
+     * @throws IOException
+     */
+    public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            Date content = new Date(input.readLong());
+
+            KiWiUriResource dtype = readURI(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiDoubleLiteral to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param literal the KiWiDoubleLiteral to serialize
+     * @throws IOException
+     */
+    public static void writeDoubleLiteral(DataOutput out, KiWiDoubleLiteral literal) throws IOException {
+        if(literal == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(literal.getId());
+            out.writeDouble(literal.getDoubleContent());
+            writeURI(out, literal.getType());
+            out.writeLong(literal.getCreated().getTime());
+        }
+    }
+
+
+    /**
+     * Read a KiWiDoubleLiteral serialized with writeDoubleLiteral from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiDoubleLiteral
+     * @throws IOException
+     */
+    public static KiWiDoubleLiteral readDoubleLiteral(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            double content = input.readDouble();
+
+            KiWiUriResource dtype = readURI(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiIntLiteral to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param literal the KiWiIntLiteral to serialize
+     * @throws IOException
+     */
+    public static void writeIntLiteral(DataOutput out, KiWiIntLiteral literal) throws IOException {
+        if(literal == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(literal.getId());
+            out.writeLong(literal.getIntContent());
+            writeURI(out, literal.getType());
+            out.writeLong(literal.getCreated().getTime());
+        }
+    }
+
+
+    /**
+     * Read a KiWiIntLiteral serialized with writeIntLiteral from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiIntLiteral
+     * @throws IOException
+     */
+    public static KiWiIntLiteral readIntLiteral(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            long content = input.readLong();
+
+            KiWiUriResource dtype = readURI(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+
+    /**
+     * Efficiently serialize a KiWiStringLiteral to a DataOutput destination.
+     *
+     * @param out the destination
+     * @param literal the KiWiStringLiteral to serialize
+     * @throws IOException
+     */
+    public static void writeStringLiteral(DataOutput out, KiWiStringLiteral literal) throws IOException {
+        if(literal == null) {
+            out.writeLong(-1L);
+        } else {
+            out.writeLong(literal.getId());
+            DataIO.writeString(out, literal.getContent());
+            DataIO.writeString(out, literal.getLanguage());
+            writeURI(out, literal.getType());
+            out.writeLong(literal.getCreated().getTime());
+        }
+    }
+
+
+
+    /**
+     * Read a KiWiStringLiteral serialized with writeStringLiteral from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiStringLiteral
+     * @throws IOException
+     */
+    public static KiWiStringLiteral readStringLiteral(DataInput input) throws IOException {
+        long id = input.readLong();
+
+        if(id == -1) {
+            return null;
+        } else {
+            String content = DataIO.readString(input);
+            String lang    = DataIO.readString(input);
+
+            KiWiUriResource dtype = readURI(input);
+
+            Date created = new Date(input.readLong());
+
+            KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+            r.setId(id);
+
+            return r;
+        }
+    }
+
+
+    /**
+     * Efficiently serialize a KiWiTriple to a DataOutput destination.
+     *
+     * @param output the destination
+     * @param triple the KiWiTriple to serialize
+     * @throws IOException
+     */
+    public static void writeTriple(DataOutput output, KiWiTriple triple) throws IOException {
+        output.writeLong(triple.getId());
+
+        // in case subject and object are both uris we use a special prefix-compressed mode
+        if(triple.getSubject().isUriResource() && triple.getObject().isUriResource()) {
+            String sUri = triple.getSubject().stringValue();
+            String oUri = triple.getObject().stringValue();
+
+            String prefix = StringUtils.getCommonPrefix(sUri, oUri);
+
+            output.writeByte(MODE_PREFIX);
+            DataIO.writeString(output,prefix);
+
+            output.writeLong(triple.getSubject().getId());
+            DataIO.writeString(output, sUri.substring(prefix.length()));
+            output.writeLong(triple.getSubject().getCreated().getTime());
+
+            writeURI(output,triple.getPredicate());
+
+            output.writeLong(triple.getObject().getId());
+            DataIO.writeString(output, oUri.substring(prefix.length()));
+            output.writeLong(triple.getObject().getCreated().getTime());
+        } else {
+            output.writeByte(MODE_DEFAULT);
+
+            writeNode(output,triple.getSubject());
+            writeURI(output,triple.getPredicate());
+            writeNode(output,triple.getObject());
+
+        }
+
+        writeNode(output,triple.getContext());
+        writeNode(output,triple.getCreator());
+        output.writeBoolean(triple.isDeleted());
+        output.writeBoolean(triple.isInferred());
+        output.writeBoolean(triple.isNewTriple());
+        output.writeLong(triple.getCreated().getTime());
+        if(triple.getDeletedAt() != null) {
+            output.writeLong(triple.getDeletedAt().getTime());
+        } else {
+            output.writeLong(0);
+        }
+    }
+
+
+    /**
+     * Read a KiWiTriple serialized with writeTriple from a DataInput source
+     *
+     * @param input the source
+     * @return the de-serialized KiWiTriple
+     * @throws IOException
+     */
+    public static KiWiTriple readTriple(DataInput input) throws IOException {
+        KiWiTriple result = new KiWiTriple();
+        result.setId(input.readLong());
+
+        int mode = input.readByte();
+        if(mode == MODE_PREFIX) {
+            String prefix = DataIO.readString(input);
+
+            long sId = input.readLong();
+            String sUri = prefix + DataIO.readString(input);
+            long sTime = input.readLong();
+            KiWiUriResource s = new KiWiUriResource(sUri);
+            s.setId(sId);
+            s.setCreated(new Date(sTime));
+            result.setSubject(s);
+
+            result.setPredicate(readURI(input));
+
+            long oId = input.readLong();
+            String oUri = prefix + DataIO.readString(input);
+            long oTime = input.readLong();
+            KiWiUriResource o = new KiWiUriResource(oUri);
+            o.setId(oId);
+            o.setCreated(new Date(oTime));
+            result.setObject(o);
+
+        } else {
+            result.setSubject((KiWiResource) readNode(input));
+            result.setPredicate(readURI(input));
+            result.setObject(readNode(input));
+        }
+        result.setContext((KiWiResource) readNode(input));
+        result.setCreator((KiWiResource) readNode(input));
+        result.setDeleted(input.readBoolean());
+        result.setInferred(input.readBoolean());
+        result.setNewTriple(input.readBoolean());
+
+        result.setCreated(new Date(input.readLong()));
+
+        long deletedAt = input.readLong();
+        if(deletedAt > 0) {
+            result.setDeletedAt(new Date(deletedAt));
+        }
+
+
+        return result;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java b/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
index 17bfa9b..f2d9b47 100644
--- a/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
+++ b/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
@@ -25,7 +25,6 @@ import org.apache.marmotta.kiwi.persistence.util.ResultSetIteration;
 import org.apache.marmotta.kiwi.persistence.util.ResultTransformerFunction;
 import org.apache.marmotta.ldcache.backend.kiwi.model.KiWiCacheEntry;
 import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.infinispan.Cache;
 import org.openrdf.model.URI;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,6 +35,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.Date;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -53,13 +53,13 @@ public class LDCachingKiWiPersistenceConnection implements Closeable {
     /**
      * Cache entries by resource
      */
-    private Cache<String,KiWiCacheEntry> entryResourceCache;
+    private Map<String,KiWiCacheEntry> entryResourceCache;
 
 
     /**
      * Cache entries by ID
      */
-    private Cache<Long,KiWiCacheEntry> entryIdCache;
+    private Map<Long,KiWiCacheEntry> entryIdCache;
 
 
     public LDCachingKiWiPersistenceConnection(KiWiConnection connection) throws SQLException {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java b/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
index 7d3a297..1320198 100644
--- a/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
+++ b/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.marmotta.ldcache.services.test;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.kiwi.persistence.KiWiDialect;
 import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
 import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
@@ -24,6 +25,7 @@ import org.apache.marmotta.kiwi.sail.KiWiStore;
 import org.apache.marmotta.ldcache.api.LDCachingBackend;
 import org.apache.marmotta.ldcache.backend.kiwi.LDCachingKiWiBackend;
 import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheTest;
+import org.junit.Assume;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -127,6 +129,9 @@ public class LDCacheKiWiTest extends BaseLDCacheTest {
      */
     @Override
     protected LDCachingBackend createBackend() {
+        Assume.assumeNotNull(jdbcUrl);
+        Assume.assumeTrue(!StringUtils.isBlank(jdbcUrl));
+
         try {
             KiWiStore store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred");
             final Repository repository = new SailRepository(store);


Mime
View raw message