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/06/18 12:42:49 UTC
[2/2] git commit: - further performance optimization by offering a
specialised triple lookup for existance checks
- further performance optimization by offering a specialised triple lookup for existance checks
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/257ff6bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/257ff6bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/257ff6bf
Branch: refs/heads/develop
Commit: 257ff6bf7b2f6b6ea54167a9475c4b4b967fe556
Parents: d0c0fa9
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Jun 18 12:42:42 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Jun 18 12:42:42 2013 +0200
----------------------------------------------------------------------
.../kiwi/persistence/KiWiConnection.java | 46 +++++++++++++++++---
.../marmotta/kiwi/sail/KiWiValueFactory.java | 12 +++--
.../kiwi/persistence/h2/statements.properties | 1 +
.../persistence/mysql/statements.properties | 1 +
.../persistence/pgsql/statements.properties | 1 +
5 files changed, 51 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/257ff6bf/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 2cb23c0..d570fac 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
@@ -42,12 +42,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
/**
@@ -1047,6 +1042,45 @@ public class KiWiConnection {
/**
+ * Return the identifier of the triple with the given subject, predicate, object and context, or null if this
+ * triple does not exist. Used for quick existance checks of triples.
+ *
+ * @param subject
+ * @param predicate
+ * @param object
+ * @param context
+ * @param inferred
+ * @return
+ */
+ public 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);
+ if(batched.size() > 0) {
+ return batched.iterator().next().getId();
+ }
+ }
+
+ requireJDBCConnection();
+ PreparedStatement loadTripleId = getPreparedStatement("load.triple");
+ loadTripleId.setLong(1, subject.getId());
+ loadTripleId.setLong(2, predicate.getId());
+ loadTripleId.setLong(3, object.getId());
+ loadTripleId.setLong(4, context.getId());
+
+ ResultSet result = loadTripleId.executeQuery();
+ try {
+ if(result.next()) {
+ return result.getLong(1);
+ } else {
+ return null;
+ }
+
+ } finally {
+ result.close();
+ }
+ }
+
+ /**
* Mark the triple passed as argument as deleted, setting the "deleted" flag to true and
* updating the timestamp value of "deletedAt".
* <p/>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/257ff6bf/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 7470a43..fad7a6b 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
@@ -703,7 +703,7 @@ public class KiWiValueFactory implements ValueFactory {
*/
public Statement createStatement(Resource subject, URI predicate, Value object, Resource context, KiWiConnection connection) {
IntArray cacheKey = IntArray.createSPOCKey(subject,predicate,object,context);
- Statement result = tripleRegistry.get(cacheKey);
+ KiWiTriple result = (KiWiTriple)tripleRegistry.get(cacheKey);
try {
if(result == null || ((KiWiTriple)result).isDeleted()) {
KiWiResource ksubject = convert(subject);
@@ -712,6 +712,7 @@ public class KiWiValueFactory implements ValueFactory {
KiWiResource kcontext = convert(context);
// test if the triple already exists in the database; if yes, return it
+ /*
List<Statement> triples = Iterations.asList(connection.listTriples(ksubject,kpredicate,kobject,kcontext,true));
if(triples.size() == 1) {
result = triples.get(0);
@@ -719,6 +720,12 @@ public class KiWiValueFactory implements ValueFactory {
result = new KiWiTriple(ksubject,kpredicate,kobject,kcontext);
((KiWiTriple)result).setMarkedForReasoning(true);
}
+ */
+ result = new KiWiTriple(ksubject,kpredicate,kobject,kcontext);
+ result.setId(connection.getTripleId(ksubject,kpredicate,kobject,kcontext,true));
+ if(result.getId() == null) {
+ result.setMarkedForReasoning(true);
+ }
tripleRegistry.put(cacheKey,result);
}
@@ -726,9 +733,6 @@ public class KiWiValueFactory implements ValueFactory {
} 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);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/257ff6bf/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
index 2fc9afc..8b788a3 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
@@ -61,6 +61,7 @@ store.tliteral = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt
store.namespace = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
store.triple = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false AND inferred = true
query.size = SELECT count(*) FROM triples WHERE deleted = false
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/257ff6bf/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
index c54e213..e40f24b 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
@@ -66,6 +66,7 @@ store.tliteral = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt
store.namespace = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
store.triple = INSERT IGNORE INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false AND inferred = true
query.size = SELECT count(*) FROM triples WHERE deleted = false
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/257ff6bf/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
index 2b2f0c6..994af7d 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
@@ -59,6 +59,7 @@ store.tliteral = INSERT INTO nodes (id,ntype,svalue,tvalue,ltype,createdAt
store.namespace = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (?,?,?,?)
store.triple = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
+load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false
query.size = SELECT count(*) FROM triples WHERE deleted = false
query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false