commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [6/8] incubator-commonsrdf git commit: Use contextFilter for graph modifications
Date Tue, 14 Jun 2016 15:45:06 GMT
Use contextFilter for graph modifications


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

Branch: refs/heads/rdf4j
Commit: 4dab5103d56f396dd17a3dd67f0980c0bad525c4
Parents: b6e938c
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Tue Jun 14 16:40:37 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Tue Jun 14 16:40:37 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/rdf4j/RDF4JGraph.java    |  4 ++
 .../rdf4j/impl/AbstractRepositoryGraphLike.java | 46 +------------------
 .../rdf/rdf4j/impl/RepositoryDatasetImpl.java   | 46 ++++++++++++++++++-
 .../rdf/rdf4j/impl/RepositoryGraphImpl.java     | 48 ++++++++++++++++++++
 4 files changed, 98 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4dab5103/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index d7cb50e..5333f31 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@ -19,11 +19,15 @@ package org.apache.commons.rdf.rdf4j;
 
 import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.rdf4j.impl.ModelGraphImpl;
+import org.apache.commons.rdf.rdf4j.impl.RepositoryGraphImpl;
 
 
 /**
  * Marker interface for RDF4J implementations of Graph.
  * 
+ * @see ModelGraphImpl
+ * @see RepositoryGraphImpl
  */
 public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> {
 	

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4dab5103/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
index b048674..bd47436 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
@@ -61,51 +61,7 @@ public abstract class AbstractRepositoryGraphLike<T extends TripleLike<BlankNode
 		// down
 	}
 
-	@Override
-	public void add(T tripleLike) {
-		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			conn.add(statement);
-			conn.commit();
-		}
-	}
-
-
-	@Override
-	public boolean contains(T tripleLike) {
-		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			return conn.hasStatement(statement, includeInferred);
-		}
-	}
-
-	@Override
-	public void remove(T tripleLike) {
-		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			conn.remove(statement);
-			conn.commit();
-		}
-	}
-
-	@Override
-	public void clear() {
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			conn.clear();
-			conn.commit();
-		}
-	}
-
-	@Override
-	public long size() {
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			// FIXME: The below might contain duplicate statements across
-			// multiple contexts
-			return conn.size();
-		}
-
-	}
-
+	
 	protected abstract T asTripleLike(Statement s);
 
 	protected RepositoryConnection getRepositoryConnection() {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4dab5103/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
index 7e18e5e..0fb8a78 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
@@ -47,6 +47,50 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad>
imp
 		super(repository);
 	}
 
+
+	@Override
+	public void add(Quad tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.add(statement);
+			conn.commit();
+		}
+	}
+
+
+	@Override
+	public boolean contains(Quad tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			return conn.hasStatement(statement, includeInferred);
+		}
+	}
+
+	@Override
+	public void remove(Quad tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.remove(statement);
+			conn.commit();
+		}
+	}
+
+	@Override
+	public void clear() {
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.clear();
+			conn.commit();
+		}
+	}
+
+	@Override
+	public long size() {
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			return conn.size();
+		}
+	}
+
+	
 	@Override
 	public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm
object) {
 		Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
@@ -128,7 +172,7 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad>
imp
 
 	@Override
 	public Graph getGraph() {
-		// TODO:  Specify default context only
+		// TODO:  Specify default context only? (the below will give the union graph)
 		return new RepositoryGraphImpl(repository, includeInferred);		
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/4dab5103/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
index 574ddb1..2950579 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
@@ -48,6 +48,54 @@ public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple>
imp
 		this.contextFilter = contextFilter;
 	}
 
+
+	@Override
+	public void add(Triple tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.add(statement, contextFilter);
+			conn.commit();
+		}
+	}
+
+
+	@Override
+	public boolean contains(Triple tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			return conn.hasStatement(statement, includeInferred, contextFilter);
+		}
+	}
+
+	@Override
+	public void remove(Triple tripleLike) {
+		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.remove(statement, contextFilter);
+			conn.commit();
+		}
+	}
+
+	@Override
+	public void clear() {
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			conn.clear(contextFilter);
+			conn.commit();
+		}
+	}
+
+	@Override
+	public long size() {
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			if (! includeInferred && contextFilter.length == 0) { 
+				return conn.size();
+			} else {
+				return stream().count();
+			}
+		}
+	}
+
+	
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
 		Resource subj = (Resource) rdf4jTermFactory.asValue(subject);


Mime
View raw message