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/08/02 14:47:12 UTC

git commit: further code improvements

Updated Branches:
  refs/heads/develop e505371ef -> d551ec077


further code improvements


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

Branch: refs/heads/develop
Commit: d551ec077b95fd4641acf8cec2263764530bce3a
Parents: e505371
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Aug 2 14:47:06 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Aug 2 14:47:06 2013 +0200

----------------------------------------------------------------------
 .../kiwi/reasoner/engine/ReasoningEngine.java   |  28 -----
 .../kiwi/persistence/KiWiGarbageCollector.java  |   7 +-
 .../marmotta/kiwi/sail/KiWiValueFactory.java    | 104 +++++++------------
 3 files changed, 36 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d551ec07/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
index dd42ae5..9e24148 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
@@ -483,34 +483,6 @@ public class ReasoningEngine implements TransactionListener {
 
     }
 
-    /**
-     * Store new justifications in the database. The method performs a batched operation to avoid
-     * excessive resource use.
-     *
-     * @param justifications
-     */
-    private void storeJustifications(Iterable<Justification> justifications) {
-        // persist the justifications that have been created in the rule processing
-        long counter = 0;
-        updateTaskStatus("storing new justifications ...");
-
-        try {
-            KiWiReasoningConnection connection = persistence.getConnection();
-            try {
-                connection.storeJustifications(justifications);
-                connection.commit();
-            } catch (SQLException ex) {
-                connection.rollback();
-                throw ex;
-            } finally {
-                connection.close();
-            }
-        } catch (SQLException ex) {
-            log.error("DATABASE ERROR: could not add new justifications for triples, database state will be inconsistent! Message: {}",ex.getMessage());
-            log.debug("Exception details:",ex);
-        }
-    }
-
 
     /**
      * This method iterates over all triples that are passed as argument and

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d551ec07/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
index 74ceb4f..5c69a39 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiGarbageCollector.java
@@ -223,12 +223,7 @@ public class KiWiGarbageCollector extends Thread {
             if(count > 0 && round % 10 == 1) {
                 // flush all nodes from the value factory first
                 if(persistence.getValueFactory() != null) {
-                    KiWiConnection vfConnection = persistence.getConnection();
-                    try {
-                        persistence.getValueFactory().flushBatch(vfConnection);
-                    } finally {
-                        vfConnection.close();
-                    }
+                    persistence.getValueFactory().flushBatch();
                 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d551ec07/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 1c5927d..2d65db6 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
@@ -183,28 +183,27 @@ public class KiWiValueFactory implements ValueFactory {
                     if(result == null) {
                         result = new KiWiUriResource(uri);
 
-                        if(result.getId() == null) {
-                            if(batchCommit) {
-                                commitLock.enter();
-                                try {
-                                    result.setId(connection.getNodeId());
-                                    nodeBatch.add(result);
-                                    batchUriLookup.put(uri,result);
-
-                                    if(nodeBatch.size() >= batchSize) {
-                                        flushBatch(connection);
-                                    }
-                                } finally {
-                                    commitLock.leave();
+                        if(batchCommit) {
+                            result.setId(connection.getNodeId());
+                            batchUriLookup.put(uri,result);
+
+                            commitLock.enter();
+                            try {
+                                nodeBatch.add(result);
+
+                                if(nodeBatch.size() >= batchSize) {
+                                    flushBatch(connection);
                                 }
-                            } else {
-                                connection.storeNode(result, false);
+                            } finally {
+                                commitLock.leave();
                             }
+                        } else {
+                            connection.storeNode(result, false);
                         }
 
-                        if(result.getId() == null) {
-                            log.error("node ID is null!");
-                        }
+                    }
+                    if(result.getId() == null) {
+                        log.error("node ID is null!");
                     }
 
                     return result;
@@ -264,24 +263,25 @@ public class KiWiValueFactory implements ValueFactory {
                     if(result == null) {
                         result = new KiWiAnonResource(nodeID);
 
-                        if(result.getId() == null) {
-                            if(batchCommit) {
-                                commitLock.enter();
-                                try {
-                                    result.setId(connection.getNodeId());
-                                    nodeBatch.add(result);
-                                    batchBNodeLookup.put(nodeID,result);
-                                    if(nodeBatch.size() >= batchSize) {
-                                        flushBatch(connection);
-                                    }
-                                } finally {
-                                    commitLock.leave();
+                        if(batchCommit) {
+                            commitLock.enter();
+                            try {
+                                result.setId(connection.getNodeId());
+                                nodeBatch.add(result);
+                                batchBNodeLookup.put(nodeID,result);
+                                if(nodeBatch.size() >= batchSize) {
+                                    flushBatch(connection);
                                 }
-                            } else {
-                                connection.storeNode(result, false);
+                            } finally {
+                                commitLock.leave();
                             }
+                        } else {
+                            connection.storeNode(result, false);
                         }
                     }
+                    if(result.getId() == null) {
+                        log.error("node ID is null!");
+                    }
 
                     return result;
                 } catch (SQLException e) {
@@ -479,11 +479,12 @@ public class KiWiValueFactory implements ValueFactory {
 
                     if(result.getId() == null) {
                         if(batchCommit) {
+                            result.setId(connection.getNodeId());
+                            batchLiteralLookup.put(LiteralCommons.createCacheKey(value.toString(),locale,type), result);
+
                             commitLock.enter();
                             try {
-                                result.setId(connection.getNodeId());
                                 nodeBatch.add(result);
-                                batchLiteralLookup.put(LiteralCommons.createCacheKey(value.toString(),locale,type), result);
 
                                 if(nodeBatch.size() >= batchSize) {
                                     flushBatch(connection);
@@ -635,41 +636,6 @@ public class KiWiValueFactory implements ValueFactory {
     @Override
     public Statement createStatement(Resource subject, URI predicate, Value object, Resource context) {
         return new ContextStatementImpl(subject,predicate,object,context);
-        /*
-        tripleLock.lock();
-        KiWiConnection connection = aqcuireConnection();
-        try {
-            IntArray cacheKey = IntArray.createSPOCKey(subject,predicate,object,context);
-            Statement result = tripleRegistry.get(cacheKey);
-            if(result == null || ((KiWiTriple)result).isDeleted()) {
-                KiWiResource ksubject   = convert(subject);
-                KiWiUriResource kpredicate = convert(predicate);
-                KiWiNode kobject    = convert(object);
-                KiWiResource    kcontext   = convert(context);
-
-                // test if the triple already exists in the database; if yes, return it
-                List<Statement> triples = connection.listTriples(ksubject,kpredicate,kobject,kcontext,true).asList();
-                if(triples.size() == 1) {
-                    result = triples.get(0);
-                } else {
-                    result = new KiWiTriple(ksubject,kpredicate,kobject,kcontext);
-                    ((KiWiTriple)result).setMarkedForReasoning(true);
-                }
-
-                tripleRegistry.put(cacheKey,result);
-            }
-            return result;
-        } catch (SQLException e) {
-            log.error("database error, could not load triple", e);
-            throw new IllegalStateException("database error, could not load triple",e);
-        } catch (RepositoryException e) {
-            log.error("database error, could not load triple", e);
-            throw new IllegalStateException("database error, could not load triple",e);
-        } finally {
-            releaseConnection(connection);
-            tripleLock.unlock();
-        }
-        */
     }
 
     /**