- changed the SQL statement used by the KiWi Garbage Collector (fixes 
MARMOTTA-175)
- added methods for explicitly calling the garbage collector (semi-fixes 
MARMOTTA-157, but the methods still need to be called somewhere :) )


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

Branch: refs/heads/develop
Commit: f9ce1c9dafcb0412f82be11b56eecbfff5817a40
Parents: 6526592
Author: Sebastian Schaffert <[email protected]>
Authored: Fri Mar 29 12:10:09 2013 +0100
Committer: Sebastian Schaffert <[email protected]>
Committed: Fri Mar 29 12:10:09 2013 +0100

----------------------------------------------------------------------
 .../kiwi/persistence/KiWiGarbageCollector.java     |   15 +---
 .../marmotta/kiwi/persistence/KiWiPersistence.java |   20 ++++
 .../apache/marmotta/kiwi/test/PersistenceTest.java |   74 +++++++++++++++
 .../ldpath/parser/DefaultConfiguration.java        |    4 +-
 4 files changed, 99 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f9ce1c9d/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 f832dd8..7d674a5 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
@@ -99,7 +99,7 @@ public class KiWiGarbageCollector extends Thread {
     }
 
 
-    private int garbageCollect() throws SQLException {
+    protected int garbageCollect() throws SQLException {
         round++;
 
         Connection con = persistence.getJDBCConnection();
@@ -190,13 +190,12 @@ public class KiWiGarbageCollector extends Thread {
         builder.append("DELETE FROM triples WHERE deleted = true");
 
         if(tripleTableDependencies.size() > 0) {
-            builder.append(" AND NOT EXISTS (");
 
             Iterator<TableDependency> iterator = 
tripleTableDependencies.iterator();
             while (iterator.hasNext()) {
                 TableDependency next = iterator.next();
 
-                builder.append("(");
+                builder.append(" AND NOT EXISTS (");
                 builder.append("SELECT ");
                 builder.append(next.column);
                 builder.append(" FROM ");
@@ -206,13 +205,8 @@ public class KiWiGarbageCollector extends Thread {
                 builder.append(" = triples.id");
 
                 builder.append(")");
-
-                if(iterator.hasNext()) {
-                    builder.append(" UNION ");
-                }
             }
 
-            builder.append(")");
         }
         return builder.toString();
     }
@@ -228,7 +222,6 @@ public class KiWiGarbageCollector extends Thread {
             while (iterator.hasNext()) {
                 TableDependency next = iterator.next();
 
-                builder.append("(");
                 builder.append("SELECT ");
                 builder.append(next.column);
                 builder.append(" FROM ");
@@ -240,11 +233,9 @@ public class KiWiGarbageCollector extends Thread {
                 builder.append(")");
 
                 if(iterator.hasNext()) {
-                    builder.append(" UNION ");
+                    builder.append(" AND NOT EXISTS (");
                 }
             }
-
-            builder.append(")");
         }
         return builder.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f9ce1c9d/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index bb8604d..3df970d 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -406,5 +406,25 @@ public class KiWiPersistence {
         cacheManager.clear();
     }
 
+    /**
+     * Notify the garbage collector thread to run. The garbage collection will 
be executed in the scope of the
+     * garbage collector thread.
+     */
+    public void notifyGarbageCollector() {
+        synchronized (garbageCollector) {
+            garbageCollector.notify();
+        }
+    }
+
+    /**
+     * Force the garbage collector to execute instantly in the scope of the 
calling thread.
+     *
+     * @throws SQLException
+     */
+    public void forceGarbageCollector() throws SQLException {
+        synchronized (garbageCollector) {
+            garbageCollector.garbageCollect();
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f9ce1c9d/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 4b0384c..c863cbf 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
@@ -1110,4 +1110,78 @@ public class PersistenceTest {
             connection.close();
         }
     }
+
+    /**
+     * Test if the garbage collection runs successfully.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testGarbageCollector() throws Exception {
+        // store some triples first
+
+        KiWiConnection connection = persistence.getConnection();
+        try {
+            KiWiUriResource stype    = new 
KiWiUriResource(Namespaces.NS_XSD+"string");
+            KiWiUriResource subject  = new 
KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
+            KiWiUriResource pred_1   = new 
KiWiUriResource("http://localhost/predicate/P1";);
+            KiWiUriResource pred_2   = new 
KiWiUriResource("http://localhost/predicate/P2";);
+            KiWiUriResource object_1 = new 
KiWiUriResource("http://localhost/resource/"+RandomStringUtils.randomAlphanumeric(8));
+            KiWiStringLiteral object_2 = new 
KiWiStringLiteral(RandomStringUtils.randomAlphanumeric(32),null,stype);
+            KiWiUriResource context  = new 
KiWiUriResource("http://localhost/context/"+RandomStringUtils.randomAlphanumeric(8));
+
+            connection.storeNode(stype);
+            connection.storeNode(subject);
+            connection.storeNode(pred_1);
+            connection.storeNode(pred_2);
+            connection.storeNode(object_1);
+            connection.storeNode(object_2);
+            connection.storeNode(context);
+
+            KiWiTriple triple1 = new 
KiWiTriple(subject,pred_1,object_1,context);
+            KiWiTriple triple2 = new 
KiWiTriple(subject,pred_2,object_2,context);
+
+            connection.storeTriple(triple1);
+            connection.storeTriple(triple2);
+
+            connection.commit();
+
+            // delete all triples again
+            connection.deleteTriple(triple1);
+            connection.deleteTriple(triple2);
+
+            connection.commit();
+
+            // test database contents
+            PreparedStatement stmt = 
connection.getJDBCConnection().prepareStatement("SELECT * FROM triples WHERE 
deleted = true");
+            ResultSet dbResult1 = stmt.executeQuery();
+
+            Assert.assertTrue(dbResult1.next());
+            Assert.assertEquals((long) triple1.getId(), 
dbResult1.getLong("id"));
+            Assert.assertEquals((long) triple1.getSubject().getId(), 
dbResult1.getLong("subject"));
+            Assert.assertEquals((long) triple1.getPredicate().getId(), 
dbResult1.getLong("predicate"));
+            
Assert.assertEquals((long)triple1.getObject().getId(),dbResult1.getLong("object"));
+
+            Assert.assertTrue(dbResult1.next());
+            Assert.assertEquals((long)triple2.getId(),dbResult1.getLong("id"));
+            
Assert.assertEquals((long)triple2.getSubject().getId(),dbResult1.getLong("subject"));
+            
Assert.assertEquals((long)triple2.getPredicate().getId(),dbResult1.getLong("predicate"));
+            
Assert.assertEquals((long)triple2.getObject().getId(),dbResult1.getLong("object"));
+
+            dbResult1.close();
+
+
+            persistence.forceGarbageCollector();
+
+            // test database contents
+            ResultSet dbResult2 = stmt.executeQuery();
+
+            Assert.assertFalse(dbResult2.next());
+
+
+        } finally {
+            connection.close();
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/f9ce1c9d/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/parser/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git 
a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/parser/DefaultConfiguration.java
 
b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/parser/DefaultConfiguration.java
index faba2d5..baaca6b 100644
--- 
a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/parser/DefaultConfiguration.java
+++ 
b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/parser/DefaultConfiguration.java
@@ -112,7 +112,7 @@ public class DefaultConfiguration<Node> extends 
Configuration<Node> {
 
     private void addDefaultFunctions() {
         for (SelectorFunction<Node> f : functionLoader) {
-            log.info("registering LDPath function: {}",f.getSignature());
+            log.debug("registering LDPath function: {}",f.getSignature());
             addFunction(f);
         }
     }
@@ -123,7 +123,7 @@ public class DefaultConfiguration<Node> extends 
Configuration<Node> {
 
     private void addDefaultTestFunctions() {
         for (TestFunction<Node> t : testLoader) {
-            log.info("registering LDPath test function: {}", t.getSignature());
+            log.debug("registering LDPath test function: {}", 
t.getSignature());
             addTestFunction(t);
         }
     }

Reply via email to