Updated Branches:
  refs/heads/develop 4484151b0 -> 5a5659a13

fixed MARMOTTA-254, reason was that after rollback triples would still remain 
in cache


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

Branch: refs/heads/develop
Commit: 5a5659a1307abda3355534daaa4de23089bdedb9
Parents: 4484151
Author: Sebastian Schaffert <[email protected]>
Authored: Wed Jun 5 09:59:44 2013 +0200
Committer: Sebastian Schaffert <[email protected]>
Committed: Wed Jun 5 09:59:44 2013 +0200

----------------------------------------------------------------------
 .../marmotta/kiwi/persistence/KiWiConnection.java  |    9 +--
 .../marmotta/kiwi/sail/KiWiSailConnection.java     |   15 ++++--
 .../apache/marmotta/kiwi/test/RepositoryTest.java  |   40 +++++++++++++++
 3 files changed, 53 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5a5659a1/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 19e10bc..0232dab 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
@@ -924,11 +924,6 @@ public class KiWiConnection {
      * @throws NullPointerException in case the subject, predicate, object or 
context have not been persisted
      */
     public synchronized void storeTriple(KiWiTriple triple) throws 
SQLException {
-        // if the node already has an ID, storeNode should not be called, 
since it is already persisted
-        if(triple.getId() != null) {
-            log.warn("triple {} already had a triple ID, not persisting", 
triple);
-            return;
-        }
 
         Preconditions.checkNotNull(triple.getSubject().getId());
         Preconditions.checkNotNull(triple.getPredicate().getId());
@@ -939,7 +934,9 @@ public class KiWiConnection {
         requireJDBCConnection();
 
         // retrieve a new triple ID and set it in the object
-        triple.setId(getNextSequence("seq.triples"));
+        if(triple.getId() == null) {
+            triple.setId(getNextSequence("seq.triples"));
+        }
 
         PreparedStatement insertTriple = getPreparedStatement("store.triple");
         insertTriple.setLong(1,triple.getId());

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5a5659a1/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 6336f9f..5644514 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
@@ -167,11 +167,7 @@ public class KiWiSailConnection extends 
NotifyingSailConnectionBase implements I
                 KiWiTriple triple = 
(KiWiTriple)valueFactory.createStatement(ksubj,kpred,kobj,kcontext, 
databaseConnection);
                 triple.setInferred(inferred);
 
-                if(triple.getId() == null) {
-                    databaseConnection.storeTriple(triple);
-                    triplesAdded = true;
-                    notifyStatementAdded(triple);
-                } else if(deletedStatementsLog.contains(triple.getId())) {
+                if(triple.getId() != null && 
deletedStatementsLog.contains(triple.getId())) {
                     // this is a hack for a concurrency problem that may occur 
in case the triple is removed in the
                     // transaction and then added again; in these cases the 
createStatement method might return
                     // an expired state of the triple because it uses its own 
database connection
@@ -179,6 +175,15 @@ public class KiWiSailConnection extends 
NotifyingSailConnectionBase implements I
                     databaseConnection.undeleteTriple(triple);
                     triplesAdded = true;
                     notifyStatementAdded(triple);
+                } else {
+                    try {
+                        databaseConnection.storeTriple(triple);
+                        triplesAdded = true;
+                        notifyStatementAdded(triple);
+                    } catch (SQLException ex) {
+                        // triple already exists, just issue a warning
+                        log.warn("adding triple to database failed, triple 
probably already exists; message: {}", ex.getMessage());
+                    }
                 }
 
                 added.add(triple);

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5a5659a1/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
----------------------------------------------------------------------
diff --git 
a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
 
b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
index 67ec618..691a2af 100644
--- 
a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
+++ 
b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
@@ -548,4 +548,44 @@ public class RepositoryTest {
 
     }
 
+    /**
+     * Test the rollback functionality of the triple store by adding a triple, 
rolling back, adding the triple again.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testRollback() throws Exception {
+        String value = RandomStringUtils.randomAlphanumeric(8);
+
+        URI subject = 
repository.getValueFactory().createURI("http://localhost/resource/"; + 
RandomStringUtils.randomAlphanumeric(8));
+        URI predicate = 
repository.getValueFactory().createURI("http://localhost/resource/"; + 
RandomStringUtils.randomAlphanumeric(8));
+        Literal object = repository.getValueFactory().createLiteral(value);
+
+        RepositoryConnection connection1 = repository.getConnection();
+        try {
+            connection1.begin();
+            connection1.add(subject,predicate,object);
+            connection1.rollback();
+
+        } finally {
+            connection1.close();
+        }
+
+        RepositoryConnection connection2 = repository.getConnection();
+        try {
+            connection2.begin();
+            
Assert.assertFalse(connection2.hasStatement(subject,predicate,object,true));
+
+            connection2.add(subject,predicate,object);
+            connection2.commit();
+
+            
Assert.assertTrue(connection2.hasStatement(subject,predicate,object,true));
+
+            connection2.commit();
+        } finally {
+            connection2.close();
+        }
+
+    }
+
 }

Reply via email to