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 2013/11/22 17:12:42 UTC

git commit: remove unnecessary boxing/unboxing of primitive types, as this has a major performance and memory impact in the triple store

Updated Branches:
  refs/heads/develop 101f41f1f -> 70b414649


remove unnecessary boxing/unboxing of primitive types, as this has a major performance and memory impact in the triple store


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

Branch: refs/heads/develop
Commit: 70b41464975e9d54d3c9fb63781aedf8e1868a72
Parents: 101f41f
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Nov 22 17:12:37 2013 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Nov 22 17:12:37 2013 +0100

----------------------------------------------------------------------
 .../kiwi/loader/generic/KiWiBatchHandler.java   |  4 +-
 .../kiwi/loader/generic/KiWiHandler.java        |  6 +-
 .../reasoner/model/program/Justification.java   |  6 +-
 .../kiwi/reasoner/model/program/Program.java    |  6 +-
 .../kiwi/reasoner/model/program/Rule.java       | 16 ++--
 .../persistence/KiWiReasoningConnection.java    | 41 ++++-----
 .../persistence/KWRLProgramPersistenceTest.java | 21 ++---
 .../persistence/KiWiSparqlConnection.java       |  6 +-
 .../marmotta/kiwi/model/rdf/KiWiNamespace.java  | 12 +--
 .../marmotta/kiwi/model/rdf/KiWiNode.java       | 91 ++++----------------
 .../marmotta/kiwi/model/rdf/KiWiTriple.java     | 20 ++---
 .../kiwi/persistence/KiWiConnection.java        | 64 +++++++-------
 .../marmotta/kiwi/sail/KiWiSailConnection.java  |  6 +-
 .../marmotta/kiwi/sail/KiWiValueFactory.java    |  8 +-
 .../marmotta/kiwi/test/PersistenceTest.java     | 57 +++++-------
 .../marmotta/kiwi/versioning/model/Version.java |  6 +-
 .../persistence/KiWiVersioningConnection.java   | 17 ++--
 .../LDCachingKiWiPersistenceConnection.java     |  2 +-
 18 files changed, 158 insertions(+), 231 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiBatchHandler.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiBatchHandler.java b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiBatchHandler.java
index dc72d9c..8e12416 100644
--- a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiBatchHandler.java
+++ b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiBatchHandler.java
@@ -164,7 +164,7 @@ public abstract class KiWiBatchHandler extends KiWiHandler implements RDFHandler
 
     @Override
     protected void storeNode(KiWiNode node) throws SQLException {
-        if(node.getId() == null) {
+        if(node.getId() < 0) {
             node.setId(connection.getNextSequence("nodes"));
         }
 
@@ -183,7 +183,7 @@ public abstract class KiWiBatchHandler extends KiWiHandler implements RDFHandler
 
     @Override
     protected void storeTriple(KiWiTriple result) throws SQLException {
-        if(result.getId() == null) {
+        if(result.getId() < 0) {
             result.setId(connection.getNextSequence("triples"));
         }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
index 34ab27c..03704e2 100644
--- a/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
+++ b/libraries/kiwi/kiwi-loader/src/main/java/org/apache/marmotta/kiwi/loader/generic/KiWiHandler.java
@@ -356,7 +356,7 @@ public class KiWiHandler implements RDFHandler {
 
             }
 
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 storeNode(result);
             }
 
@@ -383,7 +383,7 @@ public class KiWiHandler implements RDFHandler {
             } else {
                 nodesLoaded++;
             }
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 log.error("node ID is null!");
             }
 
@@ -406,7 +406,7 @@ public class KiWiHandler implements RDFHandler {
             } else {
                 nodesLoaded++;
             }
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 log.error("node ID is null!");
             }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
index 5de904e..f6c08c4 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
@@ -43,7 +43,7 @@ import java.util.Set;
  */
 public class Justification  {
 
-    private Long id;
+    private long id = -1L;
 
     /**
      * The triple that is supported by this justification
@@ -74,11 +74,11 @@ public class Justification  {
         supportingRules   = new HashSet<Rule>();
     }
 
-    public Long getId() {
+    public long getId() {
         return id;
     }
 
-    public void setId(Long id) {
+    public void setId(long id) {
         this.id = id;
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Program.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Program.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Program.java
index 285a085..13aadf3 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Program.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Program.java
@@ -29,7 +29,7 @@ import java.util.Map;
  */
 public class Program {
 
-    private Long id;
+    private long id = -1L;
 
     private String name;
 
@@ -45,11 +45,11 @@ public class Program {
         namespaces = new HashMap<String, String>();
     }
 
-    public Long getId() {
+    public long getId() {
         return id;
     }
 
-    public void setId(Long id) {
+    public void setId(long id) {
         this.id = id;
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Rule.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Rule.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Rule.java
index 8475815..ff8605b 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Rule.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Rule.java
@@ -50,7 +50,7 @@ import java.util.Map;
 public class Rule {
 
 
-    private Long id;
+    private long id = -1L;
 
 
     /**
@@ -82,15 +82,15 @@ public class Rule {
     public Rule() {
     }
 
-    public Rule(Long id) {
+    public Rule(long id) {
         this.id = id;
     }
 
-    public Long getId() {
+    public long getId() {
         return id;
     }
 
-    public void setId(Long id) {
+    public void setId(long id) {
         this.id = id;
     }
 
@@ -176,8 +176,8 @@ public class Rule {
 
         Rule rule = (Rule) o;
 
-        if(id != null) {
-            return rule.id != null && id.equals(rule.id);
+        if(id >= 0) {
+            return rule.id == id;
         } else {
 
             if (head != null ? !head.equals(rule.head) : rule.head != null) return false;
@@ -196,8 +196,8 @@ public class Rule {
 
     @Override
     public int hashCode() {
-        if(id != null) {
-            return id.hashCode() * 37;
+        if(id >= 0) {
+            return (int)id * 37;
         } else {
             int result = name != null ? name.hashCode() : 0;
             result = 31 * result + (head != null ? head.hashCode() : 0);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
index 94daf8a..6de7eba 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
@@ -48,7 +48,6 @@ import org.openrdf.model.ValueFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -92,7 +91,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public void storeRule(Rule rule, Map<String, String> namespaces) throws SQLException {
-        if(rule.getId() != null) {
+        if(rule.getId() >= 0) {
             log.warn("rule {} already had a database ID, not persisting", rule);
             return;
         }
@@ -220,7 +219,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public void removeRule(Rule rule) throws SQLException {
-        if(rule.getId() == null) {
+        if(rule.getId() <= 0) {
             log.warn("rule {} does not have a database ID, cannot delete", rule);
             return;
         }
@@ -247,7 +246,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public void storeProgram(Program program) throws SQLException {
-        if(program.getId() != null) {
+        if(program.getId() >= 0) {
             throw new SQLException("Program already stored in the database");
         }
 
@@ -399,7 +398,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
 
                         deleteJustifications(oldRule);
 
-                        oldRule.setId(null);
+                        oldRule.setId(-1L);
                     }
                 }
                 deleteProgramRule.executeBatch();
@@ -564,7 +563,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public void deleteProgram(Program program) throws SQLException {
-        if(program.getId() == null) {
+        if(program.getId() <= 0) {
             log.warn("cannot delete non-persistent program (name={})!", program.getName());
             return;
         }
@@ -617,7 +616,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * Store a collection of new justification in the database. Uses an SQL batch operation to speed up
      * database insertion.
      *
-     * @param justification
+     * @param justifications
      * @throws SQLException
      */
     public void storeJustifications(Iterable<Justification> justifications) throws SQLException {
@@ -633,7 +632,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
             justificationAddRule.clearBatch();
 
             for(Justification j : justifications) {
-                if(j.getId() != null) {
+                if(j.getId() >= 0) {
                     log.warn("justification is already stored in database, not persisting again (database ID: {})", j.getId());
                 } else {
                     j.setId(getNextSequence("seq.justifications"));
@@ -648,7 +647,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
 
                     // insert join entries for all supporting triples
                     for(KiWiTriple supportingTriple : j.getSupportingTriples()) {
-                        if(supportingTriple.getId() == null) {
+                        if(supportingTriple.getId() < 0) {
                             log.error("supporting triple is not persistent, cannot store justification (triple={})",supportingTriple);
                         } else {
                             justificationAddTriple.clearParameters();
@@ -660,7 +659,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
 
                     // insert join entries for all supporting rules
                     for(Rule supportingRule : j.getSupportingRules()) {
-                        if(supportingRule.getId() == null) {
+                        if(supportingRule.getId() <= 0) {
                             log.error("supporting rule is not persistent, cannot store justification (rule={})",supportingRule);
                         } else {
                             justificationAddRule.clearParameters();
@@ -683,7 +682,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
     /**
      * Delete the justifications given as argument (batch operation).
      *
-     * @param rule
+     * @param justifications
      * @throws SQLException
      */
     public void deleteJustifications(Iterable<Justification> justifications) throws SQLException {
@@ -694,7 +693,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
     /**
      * Delete the justifications given as argument (batch operation).
      *
-     * @param rule
+     * @param justifications
      * @throws SQLException
      */
     public void deleteJustifications(Iteration<Justification, SQLException> justifications) throws SQLException {
@@ -711,7 +710,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
 
             while(justifications.hasNext()) {
                 Justification j = justifications.next();
-                if(j.getId() == null) {
+                if(j.getId() < 0) {
                     log.error("cannot delete justification since it does not have a database ID");
                 } else {
                     deleteJustificationRules.setLong(1, j.getId());
@@ -748,7 +747,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
     /**
      * Delete the justifications referring to a certain triple given as argument.
      *
-     * @param rule
+     * @param triple
      * @throws SQLException
      */
     public void deleteJustifications(KiWiTriple triple) throws SQLException {
@@ -781,7 +780,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public CloseableIteration<Justification,SQLException> listJustificationsBySupporting(Rule rule) throws SQLException {
-        if(rule.getId() == null) {
+        if(rule.getId() <= 0) {
             return new EmptyIteration<Justification, SQLException>();
         } else {
             requireJDBCConnection();
@@ -809,7 +808,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public CloseableIteration<Justification,SQLException> listJustificationsBySupporting(KiWiTriple triple) throws SQLException {
-        if(triple.getId() == null) {
+        if(triple.getId() < 0) {
             return new EmptyIteration<Justification, SQLException>();
         } else {
             requireJDBCConnection();
@@ -837,7 +836,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public CloseableIteration<Justification,SQLException> listJustificationsForTriple(KiWiTriple triple) throws SQLException {
-        if(triple.getId() == null) {
+        if(triple.getId() < 0) {
             return new EmptyIteration<Justification, SQLException>();
         } else {
             return listJustificationsForTriple(triple.getId());
@@ -846,7 +845,7 @@ public class KiWiReasoningConnection extends KiWiConnection {
 
     /**
      * List all justifications supporting the given triple.
-     * @param triple
+     * @param tripleId
      * @return
      * @throws SQLException
      */
@@ -942,8 +941,6 @@ public class KiWiReasoningConnection extends KiWiConnection {
      *                        on the kind of filter, filtering will be carried out by the database or in memory
      * @param orderBy         list of variables by whose bindings the result rows should be ordered; variables
      *                        at the beginning of the list take precedence over variables that are further behind
-     * @param optional        allow variables to be unbound; if this parameter is set, at least one variable
-     *                        needs to give a result
      * @return a list of bindings matching the query patterns and filters, ordered by the specified
      *         variables and offset and limited by the parameters given
      */
@@ -1091,14 +1088,14 @@ public class KiWiReasoningConnection extends KiWiConnection {
             for(int i = 0; i<fields.length; i++) {
                 // find node id of the resource or literal field and use it in the where clause
                 // in this way we can avoid setting too many query parameters
-                Long nodeId = null;
+                long nodeId = -1;
                 if(fields[i] != null && fields[i].isLiteralField()) {
                     nodeId = ((KiWiNode)((LiteralField)fields[i]).getLiteral()).getId();
                 } else if(fields[i] != null && fields[i].isResourceField()) {
                     nodeId = ((KiWiNode)((ResourceField)fields[i]).getResource()).getId();
                 }
 
-                if(nodeId != null) {
+                if(nodeId >= 0) {
                     String condition = pName+"."+positions[i]+" = " + nodeId;
                     whereConditions.add(condition);
                 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/persistence/KWRLProgramPersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/persistence/KWRLProgramPersistenceTest.java b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/persistence/KWRLProgramPersistenceTest.java
index b945334..300214a 100644
--- a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/persistence/KWRLProgramPersistenceTest.java
+++ b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/persistence/KWRLProgramPersistenceTest.java
@@ -17,14 +17,7 @@
  */
 package org.apache.marmotta.kiwi.reasoner.test.persistence;
 
-import static org.hamcrest.Matchers.hasItems;
 import info.aduna.iteration.CloseableIteration;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
@@ -37,10 +30,7 @@ import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
 import org.junit.runner.RunWith;
 import org.openrdf.repository.Repository;
 import org.openrdf.repository.sail.SailRepository;
@@ -48,6 +38,13 @@ import org.openrdf.sail.memory.MemoryStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.Matchers.hasItems;
+
 /**
  * This test verifies the persistence functionality of the reasoning component regarding storing, loading and deleting
  * reasoning programs.
@@ -129,7 +126,7 @@ public class KWRLProgramPersistenceTest {
             connection.storeProgram(p);
             connection.commit();
 
-            Assert.assertNotNull("program did not get a database ID",p.getId());
+            Assert.assertTrue("program did not get a database ID", p.getId() >= 0);
 
             // load the program by name and check if it is equal to the original program
             Program p1 = connection.loadProgram("test-001");
@@ -165,7 +162,7 @@ public class KWRLProgramPersistenceTest {
             connection.storeProgram(p);
             connection.commit();
 
-            Assert.assertNotNull("program did not get a database ID",p.getId());
+            Assert.assertTrue("program did not get a database ID", p.getId() >= 0);
 
 
             // load the program by name and check if it is equal to the original program

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
index 6ae4add..a9c06dd 100644
--- a/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
+++ b/libraries/kiwi/kiwi-sparql/src/main/java/org/apache/marmotta/kiwi/sparql/persistence/KiWiSparqlConnection.java
@@ -291,7 +291,7 @@ public class KiWiSparqlConnection {
             for(int i = 0; i<fields.length; i++) {
                 // find node id of the resource or literal field and use it in the where clause
                 // in this way we can avoid setting too many query parameters
-                Long nodeId = null;
+                long nodeId = -1;
                 if(fields[i] != null && fields[i].hasValue()) {
                     Value v = valueFactory.convert(fields[i].getValue());
                     if(v instanceof KiWiNode) {
@@ -300,7 +300,7 @@ public class KiWiSparqlConnection {
                         throw new IllegalArgumentException("the values in this query have not been created by the KiWi value factory");
                     }
 
-                    if(nodeId != null) {
+                    if(nodeId >= 0) {
                         String condition = pName+"."+positions[i]+" = " + nodeId;
                         whereConditions.add(condition);
                     }
@@ -365,7 +365,7 @@ public class KiWiSparqlConnection {
             for(Iterator<Resource> it = vctx.getValue().iterator(); it.hasNext(); ) {
                 Value v = valueFactory.convert(it.next());
                 if(v instanceof KiWiNode) {
-                    Long nodeId = ((KiWiNode) v).getId();
+                    long nodeId = ((KiWiNode) v).getId();
 
                     cCond.append(varName);
                     cCond.append(".context = ");

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
index 42957f3..3e2c5d2 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNamespace.java
@@ -32,7 +32,7 @@ public class KiWiNamespace implements Namespace, Serializable {
 
 	private static final long serialVersionUID = 4894726437788578181L;
 
-	private Long id;
+	private long id = -1L;
 	
     private String prefix;
     
@@ -42,7 +42,7 @@ public class KiWiNamespace implements Namespace, Serializable {
 
     private Date modified;
     
-	private Boolean deleted;
+	private boolean deleted;
     
     public KiWiNamespace() {
         this.created = new Date();
@@ -74,14 +74,14 @@ public class KiWiNamespace implements Namespace, Serializable {
 	/**
 	 * @return the id
 	 */
-	public Long getId() {
+	public long getId() {
 		return id;
 	}
 
 	/**
 	 * @param id the id to set
 	 */
-	public void setId(Long id) {
+	public void setId(long id) {
 		this.id = id;
 	}
 
@@ -144,7 +144,7 @@ public class KiWiNamespace implements Namespace, Serializable {
 
         KiWiNamespace that = (KiWiNamespace) o;
 
-        if (deleted != null ? !deleted.equals(that.deleted) : that.deleted != null) return false;
+        if (deleted != that.deleted) return false;
         if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) return false;
         if (uri != null ? !uri.equals(that.uri) : that.uri != null) return false;
 
@@ -155,7 +155,7 @@ public class KiWiNamespace implements Namespace, Serializable {
     public int hashCode() {
         int result = prefix != null ? prefix.hashCode() : 0;
         result = 31 * result + (uri != null ? uri.hashCode() : 0);
-        result = 31 * result + (deleted != null ? deleted.hashCode() : 0);
+        result = 31 * result + (deleted ? 1 : 0);
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNode.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNode.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNode.java
index 99049cb..7e5c448 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNode.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiNode.java
@@ -33,40 +33,24 @@ import java.util.Date;
  * @author sschaffe
  */
 public abstract class KiWiNode implements Value, Serializable {
-    
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 4652575123005436645L;
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 4652575123005436645L;
 
     /**
      * Unique ID of the KiWiNode in the database. This ID should not be exposed to the outside, it may be
      * different between different KiWi installations.
      */
-	private Long id;
+    private long id = -1L;
 
 
     /**
      * The creation date of the KiWiNode.
      **/
-     private Date created;
+    private Date created;
 
-    /**
-     * indicates that the node has been marked as deleted (and can possibly be completely removed from the database)
-     */
-    private boolean deleted;
-
-    /**
-     * indicates that the node is cached by the Linked Data Caching service and not local
-     */
-    private boolean cached;
-    
-    /**
-     * A flag to indicate whether the state of a node has changed and needs to be persisted in the database. Set by
-     * createResource/createLiteral/... and used by TripleStorePersister.
-     */
-    // @Transient
-    private boolean changed = false;
 
     protected KiWiNode() {
         this(new Date());
@@ -74,8 +58,6 @@ public abstract class KiWiNode implements Value, Serializable {
 
     protected KiWiNode(Date created) {
         this.created   = created;
-        this.deleted   = false;
-        this.cached    = false;
     }
 
 
@@ -83,21 +65,21 @@ public abstract class KiWiNode implements Value, Serializable {
      * Return the database ID of this node. Can be used to refer to the node in the context of one triple store
      * instance, but should not be exposed outside.
      *
-	 * @return the (internal) database id
-	 */
-	public Long getId() {
-		return id;
-	}
+     * @return the (internal) database id
+     */
+    public long getId() {
+        return id;
+    }
 
 
-	/**
+    /**
      * Update the database id of the node.
      *
-	 * @param id the id to set
-	 */
-	public void setId(Long id) {
-		this.id = id;
-	}
+     * @param id the id to set
+     */
+    public void setId(long id) {
+        this.id = id;
+    }
 
     /**
      * Return the timestamp when this node has been created
@@ -119,43 +101,6 @@ public abstract class KiWiNode implements Value, Serializable {
 
 
     /**
-     * Returns true in case the node has been marked deleted.
-     *
-     * @return the deleted
-     */
-    public boolean isDeleted() {
-        return deleted;
-    }
-
-    /**
-     * Flag this node as deleted
-     *
-     * @param deleted the deleted to set
-     */
-    public void setDeleted(boolean deleted) {
-        this.deleted = deleted;
-    }
-
-
-    public boolean isChanged() {
-        return changed;
-    }
-
-    public void setChanged(boolean changed) {
-        this.changed = changed;
-    }
-
-
-    public boolean isCached() {
-        return cached;
-    }
-
-    public void setCached(boolean cached) {
-        this.cached = cached;
-    }
-
-
-    /**
      * Return true in case the node is a uri resource (avoids instanceof test)
      *
      * @return true if the node is a URI, false otherwise

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
index a6e5f58..716acb1 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/model/rdf/KiWiTriple.java
@@ -52,7 +52,7 @@ public class KiWiTriple  implements Statement, Serializable {
 	 */
 	private static final long serialVersionUID = -8726615974625660845L;
 	
-	private Long id;
+	private long id = -1L;
 	
 
     private KiWiResource    subject;
@@ -69,12 +69,12 @@ public class KiWiTriple  implements Statement, Serializable {
 
     private Date deletedAt;
 
-	private Boolean deleted;
+	private boolean deleted;
 
-    private Boolean inferred;
+    private boolean inferred;
 
     //@Transient
-    private Boolean markedForReasoning;
+    private boolean markedForReasoning;
 
 	
 	public KiWiTriple() {
@@ -234,14 +234,14 @@ public class KiWiTriple  implements Statement, Serializable {
     /**
 	 * @return the id
 	 */
-	public Long getId() {
+	public long getId() {
 		return id;
 	}
 
 	/**
 	 * @param id the id to set
 	 */
-	public void setId(Long id) {
+	public void setId(long id) {
 		this.id = id;
 	}
 
@@ -250,7 +250,7 @@ public class KiWiTriple  implements Statement, Serializable {
 	/**
 	 * @return the deleted
 	 */
-	public Boolean isDeleted() {
+	public boolean isDeleted() {
 		return deleted;
 	}
 
@@ -258,7 +258,7 @@ public class KiWiTriple  implements Statement, Serializable {
 	/**
 	 * @param deleted the deleted to set
 	 */
-	public void setDeleted(Boolean deleted) {
+	public void setDeleted(boolean deleted) {
 		this.deleted = deleted;
 	}
 
@@ -311,11 +311,11 @@ public class KiWiTriple  implements Statement, Serializable {
     }
 
 
-    public Boolean isMarkedForReasoning() {
+    public boolean isMarkedForReasoning() {
         return markedForReasoning;
     }
 
-    public void setMarkedForReasoning(Boolean markedForReasoning) {
+    public void setMarkedForReasoning(boolean markedForReasoning) {
         this.markedForReasoning = markedForReasoning;
     }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/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 0b3d0b7..b27ead2 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
@@ -307,7 +307,7 @@ public class KiWiConnection {
      */
     public void storeNamespace(KiWiNamespace namespace) throws SQLException {
         // TODO: add unique constraints to table
-        if(namespace.getId() != null) {
+        if(namespace.getId() >= 0) {
             log.warn("trying to store namespace which is already persisted: {}",namespace);
             return;
         }
@@ -334,7 +334,7 @@ public class KiWiConnection {
      * @throws SQLException in case a database error occurred
      */
     public void deleteNamespace(KiWiNamespace namespace) throws SQLException {
-        if(namespace.getId() == null) {
+        if(namespace.getId() < 0) {
             log.warn("trying to remove namespace which is not persisted: {}",namespace);
             return;
         }
@@ -376,7 +376,7 @@ public class KiWiConnection {
      * @throws SQLException
      */
     public long getSize(KiWiResource context) throws SQLException {
-        if(context.getId() == null) {
+        if(context.getId() < 0) {
             return 0;
         };
 
@@ -604,7 +604,7 @@ public class KiWiConnection {
         requireJDBCConnection();
 
         // ltype not persisted
-        if(ltype != null && ltype.getId() == null) {
+        if(ltype != null && ltype.getId() < 0) {
             return null;
         }
 
@@ -670,7 +670,7 @@ public class KiWiConnection {
 
         KiWiUriResource ltype = loadUriResource(Namespaces.NS_XSD + "dateTime");
 
-        if(ltype == null || ltype.getId() == null) {
+        if(ltype == null || ltype.getId() < 0) {
             return null;
         }
 
@@ -725,7 +725,7 @@ public class KiWiConnection {
         KiWiUriResource ltype = loadUriResource(Namespaces.NS_XSD + "integer");
 
         // ltype not persisted
-        if(ltype == null || ltype.getId() == null) {
+        if(ltype == null || ltype.getId() < 0) {
             return null;
         }
 
@@ -780,7 +780,7 @@ public class KiWiConnection {
         KiWiUriResource ltype = loadUriResource(Namespaces.NS_XSD + "double");
 
         // ltype not persisted
-        if(ltype == null || ltype.getId() == null) {
+        if(ltype == null || ltype.getId() < 0) {
             return null;
         }
 
@@ -835,7 +835,7 @@ public class KiWiConnection {
         KiWiUriResource ltype = loadUriResource(Namespaces.NS_XSD + "boolean");
 
         // ltype not persisted
-        if(ltype == null || ltype.getId() == null) {
+        if(ltype == null || ltype.getId() < 0) {
             return null;
         }
 
@@ -882,7 +882,7 @@ public class KiWiConnection {
         // ensure the data type of a literal is persisted first
         if(node instanceof KiWiLiteral) {
             KiWiLiteral literal = (KiWiLiteral)node;
-            if(literal.getType() != null && literal.getType().getId() == null) {
+            if(literal.getType() != null && literal.getType().getId() < 0) {
                 storeNode(literal.getType(), batch);
             }
         }
@@ -890,7 +890,7 @@ public class KiWiConnection {
         requireJDBCConnection();
 
         // retrieve a new node id and set it in the node object
-        if(node.getId() == null) {
+        if(node.getId() < 0) {
             node.setId(getNextSequence("seq.nodes"));
         }
 
@@ -1039,7 +1039,7 @@ public class KiWiConnection {
 
             requireJDBCConnection();
 
-            boolean hasId = triple.getId() != null;
+            boolean hasId = triple.getId() >= 0;
 
             if(hasId && deletedStatementsLog.contains(triple.getId())) {
                 // this is a hack for a concurrency problem that may occur in case the triple is removed in the
@@ -1052,7 +1052,7 @@ public class KiWiConnection {
                 return true;
             } else {
                 // retrieve a new triple ID and set it in the object
-                if(triple.getId() == null) {
+                if(triple.getId() < 0) {
                     triple.setId(getNextSequence("seq.triples"));
                 }
 
@@ -1126,7 +1126,7 @@ public class KiWiConnection {
      * @param inferred
      * @return
      */
-    public synchronized Long getTripleId(final KiWiResource subject, final KiWiUriResource predicate, final KiWiNode object, final KiWiResource context, final boolean inferred) throws SQLException {
+    public synchronized long getTripleId(final KiWiResource subject, final KiWiUriResource predicate, final KiWiNode object, final KiWiResource context, final boolean inferred) throws SQLException {
         if(tripleBatch != null && tripleBatch.size() > 0) {
             Collection<KiWiTriple> batched = tripleBatch.listTriples(subject,predicate,object,context, false);
             if(batched.size() > 0) {
@@ -1150,7 +1150,7 @@ public class KiWiConnection {
             if(result.next()) {
                 return result.getLong(1);
             } else {
-                return null;
+                return -1L;
             }
 
         } finally {
@@ -1182,7 +1182,7 @@ public class KiWiConnection {
                     triple.setDeleted(true);
                     triple.setDeletedAt(new Date());
 
-                    if (triple.getId() == null) {
+                    if (triple.getId() < 0) {
                         log.warn("attempting to remove non-persistent triple: {}", triple);
                         removeCachedTriple(triple);
                     } else {
@@ -1235,7 +1235,7 @@ public class KiWiConnection {
      * @param triple
      */
     public void undeleteTriple(KiWiTriple triple) throws SQLException {
-        if(triple.getId() == null) {
+        if(triple.getId() < 0) {
             log.warn("attempting to undelete non-persistent triple: {}",triple);
             return;
         }
@@ -1439,16 +1439,16 @@ public class KiWiConnection {
      */
     private CloseableIteration<Statement, SQLException> listTriplesInternal(KiWiResource subject, KiWiUriResource predicate, KiWiNode object, KiWiResource context, boolean inferred, final boolean wildcardContext) throws SQLException {
         // if one of the database ids is null, there will not be any database results, so we can return an empty result
-        if(subject != null && subject.getId() == null) {
+        if(subject != null && subject.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(predicate != null && predicate.getId() == null) {
+        if(predicate != null && predicate.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(object != null && object.getId() == null) {
+        if(object != null && object.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(context != null && context.getId() == null) {
+        if(context != null && context.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
 
@@ -1545,7 +1545,7 @@ public class KiWiConnection {
      */
     protected KiWiNode constructNodeFromDatabase(ResultSet row) throws SQLException {
 
-        Long id = row.getLong("id");
+        long id = row.getLong("id");
 
         Element cached = nodeCache.get(id);
 
@@ -1563,13 +1563,13 @@ public class KiWiConnection {
             return result;
         } else if("bnode".equals(ntype)) {
             KiWiAnonResource result = new KiWiAnonResource(row.getString("svalue"), new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
 
             cacheNode(result);
             return result;
         } else if("string".equals(ntype)) {
             final KiWiStringLiteral result = new KiWiStringLiteral(row.getString("svalue"), new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
 
             if(row.getString("lang") != null) {
                 result.setLocale(getLocale(row.getString("lang")));
@@ -1582,7 +1582,7 @@ public class KiWiConnection {
             return result;
         } else if("int".equals(ntype)) {
             KiWiIntLiteral result = new KiWiIntLiteral(row.getLong("ivalue"), null, new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
             if(row.getLong("ltype") != 0) {
                 result.setType((KiWiUriResource) loadNodeById(row.getLong("ltype")));
             }
@@ -1591,7 +1591,7 @@ public class KiWiConnection {
             return result;
         } else if("double".equals(ntype)) {
             KiWiDoubleLiteral result = new KiWiDoubleLiteral(row.getDouble("dvalue"), null, new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
             if(row.getLong("ltype") != 0) {
                 result.setType((KiWiUriResource) loadNodeById(row.getLong("ltype")));
             }
@@ -1600,7 +1600,7 @@ public class KiWiConnection {
             return result;
         } else if("boolean".equals(ntype)) {
             KiWiBooleanLiteral result = new KiWiBooleanLiteral(row.getBoolean("bvalue"),null,new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
 
             if(row.getLong("ltype") != 0) {
                 result.setType((KiWiUriResource) loadNodeById(row.getLong("ltype")));
@@ -1610,7 +1610,7 @@ public class KiWiConnection {
             return result;
         } else if("date".equals(ntype)) {
             KiWiDateLiteral result = new KiWiDateLiteral(new Date(row.getTimestamp("tvalue").getTime()), null, new Date(row.getTimestamp("createdAt").getTime()));
-            result.setId(row.getLong("id"));
+            result.setId(id);
 
             if(row.getLong("ltype") != 0) {
                 result.setType((KiWiUriResource) loadNodeById(row.getLong("ltype")));
@@ -1760,7 +1760,7 @@ public class KiWiConnection {
 
 
     private void cacheNode(KiWiNode node) {
-        if(node.getId() != null) {
+        if(node.getId() >= 0) {
             nodeCache.put(new Element(node.getId(), node));
         }
         if(node instanceof KiWiUriResource) {
@@ -1773,13 +1773,13 @@ public class KiWiConnection {
     }
 
     private void cacheTriple(KiWiTriple triple) {
-        if(triple.getId() != null) {
+        if(triple.getId() >= 0) {
             tripleCache.put(new Element(triple.getId(),triple));
         }
     }
 
     private void removeCachedTriple(KiWiTriple triple) {
-        if(triple.getId() != null) {
+        if(triple.getId() >= 0) {
             tripleCache.remove(triple.getId());
         }
     }
@@ -2043,7 +2043,7 @@ public class KiWiConnection {
         if(tripleBatch != null && tripleBatch.size() > 0) {
             synchronized (tripleBatch) {
                 for(KiWiTriple triple : tripleBatch) {
-                    triple.setId(null);
+                    triple.setId(-1L);
                 }
                 tripleBatch.clear();
             }
@@ -2142,7 +2142,7 @@ public class KiWiConnection {
                                 }
 
                                 // retrieve a new triple ID and set it in the object
-                                if(triple.getId() == null) {
+                                if(triple.getId() < 0) {
                                     triple.setId(getNextSequence("seq.triples"));
                                 }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
index a9d1a8f..4420061 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiSailConnection.java
@@ -409,7 +409,7 @@ public class KiWiSailConnection extends NotifyingSailConnectionBase implements I
             CloseableIteration<? extends Statement, SailException> triples = getStatementsInternal(subj,pred,obj,true,contexts);
             while(triples.hasNext()) {
                 KiWiTriple triple = (KiWiTriple)triples.next();
-                if(triple.getId() != null) {
+                if(triple.getId() >= 0) {
                     databaseConnection.deleteTriple(triple);
                     triplesRemoved = true;
                     notifyStatementRemoved(triple);
@@ -440,7 +440,7 @@ public class KiWiSailConnection extends NotifyingSailConnectionBase implements I
             CloseableIteration<? extends Statement, SailException> triples = getStatementsInternal(subj,pred,obj,true,valueFactory.createURI(inferredContext));
             while(triples.hasNext()) {
                 KiWiTriple triple = (KiWiTriple)triples.next();
-                if(triple.getId() != null && triple.isInferred()) {
+                if(triple.getId() >= 0 && triple.isInferred()) {
                     databaseConnection.deleteTriple(triple);
                     triplesRemoved = true;
                     notifyStatementRemoved(triple);
@@ -462,7 +462,7 @@ public class KiWiSailConnection extends NotifyingSailConnectionBase implements I
      */
     public boolean removeInferredStatement(KiWiTriple triple) throws SailException {
         try {
-            if(triple.getId() != null && triple.isInferred()) {
+            if(triple.getId() >= 0 && triple.isInferred()) {
                 databaseConnection.deleteTriple(triple);
                 triplesRemoved = true;
                 notifyStatementRemoved(triple);

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
index c615f69..794df02 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
@@ -171,7 +171,7 @@ public class KiWiValueFactory implements ValueFactory {
                 connection.storeNode(result, false);
 
             }
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 log.error("node ID is null!");
             }
 
@@ -234,7 +234,7 @@ public class KiWiValueFactory implements ValueFactory {
 
                 connection.storeNode(result, false);
             }
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 log.error("node ID is null!");
             }
 
@@ -471,7 +471,7 @@ public class KiWiValueFactory implements ValueFactory {
 
             }
 
-            if(result.getId() == null) {
+            if(result.getId() < 0) {
                 connection.storeNode(result, false);
             }
 
@@ -639,7 +639,7 @@ public class KiWiValueFactory implements ValueFactory {
 
                 result = new KiWiTriple(ksubject,kpredicate,kobject,kcontext);
                 result.setId(connection.getTripleId(ksubject,kpredicate,kobject,kcontext,true));
-                if(result.getId() == null) {
+                if(result.getId() < 0) {
                     result.setMarkedForReasoning(true);
                 }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
index 1f9245e..e2144bd 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -16,35 +16,12 @@
  */
 package org.apache.marmotta.kiwi.test;
 
-import static org.apache.marmotta.commons.sesame.model.LiteralCommons.getRDFLangStringType;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.hasItems;
 import info.aduna.iteration.Iterations;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Random;
-
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.marmotta.commons.sesame.model.Namespaces;
 import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNamespace;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.model.rdf.*;
 import org.apache.marmotta.kiwi.persistence.KiWiConnection;
 import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
 import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -55,6 +32,18 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.openrdf.model.Statement;
 
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+
+import static org.apache.marmotta.commons.sesame.model.LiteralCommons.getRDFLangStringType;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
+
 /**
  * This test verifies the persistence functionality of the KiWi triple store. 
  *
@@ -118,7 +107,7 @@ public class PersistenceTest {
             connection.storeNode(uri, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(uri.getId());
+            Assert.assertTrue(uri.getId() >= 0);
 
             KiWiNode testUri1 = connection.loadNodeById(uri.getId());
 
@@ -195,7 +184,7 @@ public class PersistenceTest {
             connection.storeNode(bnode, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(bnode.getId());
+            Assert.assertTrue(bnode.getId() >= 0);
 
             KiWiNode testBNode1 = connection.loadNodeById(bnode.getId());
 
@@ -274,7 +263,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -353,7 +342,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -431,7 +420,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -513,7 +502,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -600,7 +589,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -705,7 +694,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -809,7 +798,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 
@@ -912,7 +901,7 @@ public class PersistenceTest {
             connection.storeNode(literal, false);
 
             // check if it then has a database ID
-            Assert.assertNotNull(literal.getId());
+            Assert.assertTrue(literal.getId() >= 0);
 
             KiWiNode testLiteral1 = connection.loadNodeById(literal.getId());
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/model/Version.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/model/Version.java b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/model/Version.java
index 6fa967a..2329b05 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/model/Version.java
+++ b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/model/Version.java
@@ -28,7 +28,7 @@ import org.apache.marmotta.kiwi.transactions.model.TransactionData;
  */
 public class Version extends TransactionData {
 
-    private Long id;
+    private long id = -1L;
 
     private KiWiResource creator;
 
@@ -47,11 +47,11 @@ public class Version extends TransactionData {
         this.commitTime     = data.getCommitTime();
     }
 
-    public Long getId() {
+    public long getId() {
         return id;
     }
 
-    public void setId(Long id) {
+    public void setId(long id) {
         this.id = id;
     }
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
index 2ef8946..844a0be 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
+++ b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
@@ -38,7 +38,6 @@ import org.openrdf.repository.RepositoryResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -72,7 +71,7 @@ public class KiWiVersioningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public void storeVersion(Version data) throws SQLException {
-        if(data.getId() != null) {
+        if(data.getId() >= 0) {
             log.warn("version {} already had a version ID, not persisting", data);
             return;
         }
@@ -319,7 +318,7 @@ public class KiWiVersioningConnection extends KiWiConnection {
      * @throws SQLException
      */
     private CloseableIteration<Version, SQLException> listVersionsInternal(KiWiResource r) throws SQLException {
-        if(r.getId() == null) {
+        if(r.getId() < 0) {
             return new EmptyIteration<Version, SQLException>();
         } else {
             requireJDBCConnection();
@@ -421,7 +420,7 @@ public class KiWiVersioningConnection extends KiWiConnection {
         PreparedStatement queryVersions = getPreparedStatement("load.versions_by_resource_between");
         synchronized (queryVersions) {
             queryVersions.clearParameters();
-            if(r.getId() == null) {
+            if(r.getId() < 0) {
                 return new EmptyIteration<Version, SQLException>();
             } else {
                 queryVersions.setLong(1, r.getId());
@@ -539,16 +538,16 @@ public class KiWiVersioningConnection extends KiWiConnection {
      */
     private CloseableIteration<Statement, SQLException> listTriplesInternalSnapshot(KiWiResource subject, KiWiUriResource predicate, KiWiNode object, KiWiResource context, boolean inferred, Date snapshotDate) throws SQLException {
         // if one of the database ids is null, there will not be any database results, so we can return an empty result
-        if(subject != null && subject.getId() == null) {
+        if(subject != null && subject.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(predicate != null && predicate.getId() == null) {
+        if(predicate != null && predicate.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(object != null && object.getId() == null) {
+        if(object != null && object.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
-        if(context != null && context.getId() == null) {
+        if(context != null && context.getId() < 0) {
             return new EmptyIteration<Statement, SQLException>();
         }
 
@@ -652,7 +651,7 @@ public class KiWiVersioningConnection extends KiWiConnection {
      * @throws SQLException
      */
     public long getSnapshotSize(KiWiResource context, Date snapshotDate) throws SQLException {
-        if(context.getId() == null) {
+        if(context.getId() < 0) {
             return 0;
         };
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/70b41464/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 63e4063..bd79539 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
@@ -149,7 +149,7 @@ public class LDCachingKiWiPersistenceConnection  {
             kEntry.setTripleCount(entry.getTripleCount());
         }
 
-        if(! (entry.getResource() instanceof KiWiResource) || ((KiWiResource) entry.getResource()).getId() == null) {
+        if(! (entry.getResource() instanceof KiWiResource) || ((KiWiResource) entry.getResource()).getId() < 0) {
             throw new IllegalStateException("the resource contained in the cache entry is not a KiWiResource!");
         }