commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/4] incubator-commonsrdf git commit: Use InternalRDF4JFactory for constructing
Date Tue, 04 Oct 2016 01:17:47 GMT
Use InternalRDF4JFactory for constructing

and reduce visibiliy of  *Impl to package protected


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

Branch: refs/heads/rdf4j
Commit: f9c298a9656de2a23f569285e578d7f78095becb
Parents: cbb5ca5
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Tue Oct 4 01:40:22 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Tue Oct 4 01:40:22 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/rdf4j/RDF4JGraph.java    |   4 -
 .../commons/rdf/rdf4j/RDF4JTermFactory.java     |  75 +++-----
 .../rdf4j/impl/AbstractRepositoryGraphLike.java |   8 +-
 .../commons/rdf/rdf4j/impl/BlankNodeImpl.java   |   4 +-
 .../apache/commons/rdf/rdf4j/impl/IRIImpl.java  |   4 +-
 .../rdf/rdf4j/impl/InternalRDF4JFactory.java    | 178 +++++++++++++++++++
 .../commons/rdf/rdf4j/impl/LiteralImpl.java     |   4 +-
 .../commons/rdf/rdf4j/impl/ModelGraphImpl.java  |   9 +-
 .../apache/commons/rdf/rdf4j/impl/QuadImpl.java |   7 +-
 .../rdf/rdf4j/impl/RepositoryDatasetImpl.java   |  28 ++-
 .../rdf/rdf4j/impl/RepositoryGraphImpl.java     |  34 ++--
 .../commons/rdf/rdf4j/impl/TripleImpl.java      |   5 +-
 12 files changed, 248 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/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 e0b7a29..93886a4 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
@@ -25,8 +25,6 @@ import org.apache.commons.rdf.api.Graph;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.rdf4j.impl.ModelGraphImpl;
-import org.apache.commons.rdf.rdf4j.impl.RepositoryGraphImpl;
 import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Resource;
 import org.eclipse.rdf4j.repository.Repository;
@@ -41,8 +39,6 @@ import org.eclipse.rdf4j.repository.Repository;
  * @see RDF4JTermFactory#asRDFTermGraphUnion(Repository)
  * @see RDF4JDataset#getGraph()
  * @see RDF4JDataset#getGraph(BlankNodeOrIRI)
- * @see ModelGraphImpl
- * @see RepositoryGraphImpl
  */
 public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> {
 	

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
index 1b4f1bd..7869cbf 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
@@ -23,25 +23,17 @@ import java.util.UUID;
 
 // To avoid confusion, avoid importing
 // classes that are in both
-// commons.rdf and openrdf.model (e.g. IRI)
+// commons.rdf and openrdf.model (e.g. IRI, Literal)
 import org.apache.commons.rdf.api.BlankNode;
 import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.Dataset;
 import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.Quad;
 import org.apache.commons.rdf.api.RDFTerm;
 import org.apache.commons.rdf.api.RDFTermFactory;
 import org.apache.commons.rdf.api.Triple;
 import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.rdf4j.impl.BlankNodeImpl;
-import org.apache.commons.rdf.rdf4j.impl.IRIImpl;
-import org.apache.commons.rdf.rdf4j.impl.LiteralImpl;
-import org.apache.commons.rdf.rdf4j.impl.ModelGraphImpl;
-import org.apache.commons.rdf.rdf4j.impl.QuadImpl;
-import org.apache.commons.rdf.rdf4j.impl.RepositoryDatasetImpl;
-import org.apache.commons.rdf.rdf4j.impl.RepositoryGraphImpl;
-import org.apache.commons.rdf.rdf4j.impl.TripleImpl;
+import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
 import org.eclipse.rdf4j.model.BNode;
 import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Resource;
@@ -101,7 +93,12 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
  * therefore uses a unique {@link RDF4JTermFactory} internally.
  *
  */
-public class RDF4JTermFactory implements RDFTermFactory {
+public final class RDF4JTermFactory implements RDFTermFactory {
+	
+	/**
+	 * InternalRDF4JFactory is deliberately abstract
+	 */
+	private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory(){};
 
 	/**
 	 * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
@@ -131,13 +128,13 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	@SuppressWarnings("unchecked")
 	public static <T extends Value> RDF4JTerm<T> asRDFTerm(final T value, UUID salt)
{
 		if (value instanceof BNode) {
-			return (RDF4JTerm<T>) new BlankNodeImpl((BNode) value, salt);
+			return (RDF4JTerm<T>) rdf4j.createBlankNodeImpl((BNode) value, salt);
 		}
 		if (value instanceof org.eclipse.rdf4j.model.Literal) {
-			return (RDF4JTerm<T>) new LiteralImpl((org.eclipse.rdf4j.model.Literal) value);
+			return (RDF4JTerm<T>) rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal)
value);
 		}
 		if (value instanceof org.eclipse.rdf4j.model.IRI) {
-			return (RDF4JTerm<T>) new IRIImpl((org.eclipse.rdf4j.model.IRI) value);
+			return (RDF4JTerm<T>) rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
 		}
 		throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
 	}
@@ -153,12 +150,17 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	public RDF4JTermFactory(ValueFactory valueFactory) {
 		this(valueFactory, UUID.randomUUID());
 	}
+	
+	public RDF4JTermFactory(UUID salt) {
+		this(SimpleValueFactory.getInstance(), salt);
+	}
 
 	public RDF4JTermFactory(ValueFactory valueFactory, UUID salt) {
 		this.valueFactory = valueFactory;
 		this.salt = salt;
 	}
 	
+
 	/**
 	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
 	 * <p>
@@ -180,28 +182,9 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A {@link RDF4JQuad} that is equivalent to the statement
 	 */
 	public RDF4JQuad asQuad(final Statement statement) {
-		return new QuadImpl(statement, salt);
-	}
-
-	/**
-	 * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
-	 *
-	 * @see #asQuad(Statement)
-	 * @param statement
-	 *            The statement to convert
-	 * @param salt
-	 *            A {@link UUID} salt to use for uniquely mapping any
-	 *            {@link BNode}s. The salt should typically be the same for
-	 *            multiple statements in the same {@link Repository} or
-	 *            {@link Model} to ensure {@link BlankNode#equals(Object)} and
-	 *            {@link BlankNode#uniqueReference()} works as intended.
-	 * @return A {@link RDF4JQuad} that is equivalent to the statement
-	 */
-	public static RDF4JQuad asQuad(final Statement statement, UUID salt) {
-		return new QuadImpl(statement, salt);
+		return rdf4j.createQuadImpl(statement, salt);
 	}
 
-
 	/**
 	 *
 	 * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
@@ -246,7 +229,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A {@link Dataset} backed by the RDF4J repository.
 	 */
 	public RDF4JDataset asRDFTermDataset(Repository repository) {
-		return new RepositoryDatasetImpl(repository, false, false);
+		return rdf4j.createRepositoryDatasetImpl(repository, false, false);
 	}
 
 	/**
@@ -261,7 +244,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A {@link Dataset} backed by the RDF4J repository.
 	 */
 	public RDF4JDataset asRDFTermDataset(Repository repository, boolean includeInferred) {
-		return new RepositoryDatasetImpl(repository, false, includeInferred);
+		return rdf4j.createRepositoryDatasetImpl(repository, false, includeInferred);
 	}
 
 	/**
@@ -274,7 +257,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return Adapted {@link Graph}.
 	 */
 	public RDF4JGraph asRDFTermGraph(Model model) {
-		return new ModelGraphImpl(model);
+		return rdf4j.createModelGraphImpl(model, this);
 	}
 
 	/**
@@ -290,7 +273,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A {@link Graph} backed by the RDF4J repository.
 	 */
 	public RDF4JGraph asRDFTermGraph(Repository repository) {
-		return new RepositoryGraphImpl(repository, false, false);
+		return rdf4j.createRepositoryGraphImpl(repository, false, false);
 	}
 
 	/**
@@ -307,7 +290,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A union {@link Graph} backed by the RDF4J repository.
 	 */
 	public RDF4JGraph asRDFTermGraphUnion(Repository repository) {
-		return new RepositoryGraphImpl(repository, false, true);
+		return rdf4j.createRepositoryGraphImpl(repository, false, true);
 	}
 	
 	/**
@@ -333,7 +316,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 		/** NOTE: asValue() deliberately CAN handle <code>null</code> */
 		Resource[] resources = contexts.stream()
 				.map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
-		return new RepositoryGraphImpl(Objects.requireNonNull(repository), 
+		return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository), 
 				false, true, resources);		
 	}
 	
@@ -348,14 +331,10 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 *            RDF4J {@link Repository} to connect to.
 	 * @param includeInferred
 	 *            If true, any inferred triples are included in the graph
-	 * @param unionGraph
-	 *            If true, triples from any context is included in the graph,
-	 *            otherwise only triples in the default context
-	 *            <code>null</code>.
 	 * @return A {@link Graph} backed by the RDF4J repository.
 	 */
-	public RDF4JGraph asRDFTermGraph(Repository repository, boolean includeInferred, boolean
unionGraph) {
-		return new RepositoryGraphImpl(repository, includeInferred, unionGraph);
+	public RDF4JGraph asRDFTermGraph(Repository repository, boolean includeInferred) {
+		return rdf4j.createRepositoryGraphImpl(repository, false, includeInferred);
 	}
 
 	/**
@@ -413,7 +392,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	 * @return A {@link RDF4JTriple} that is equivalent to the statement
 	 */
 	public RDF4JTriple asTriple(final Statement statement) {
-		return new TripleImpl(statement, salt);
+		return rdf4j.createTripleImpl(statement, salt);
 	}
 
 	/**
@@ -535,7 +514,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	}
 
 	@Override
-	public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object)
+	public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI
predicate, RDFTerm object)
 			throws IllegalArgumentException, UnsupportedOperationException {
 		final Statement statement = getValueFactory().createStatement(
 				(org.eclipse.rdf4j.model.Resource) asValue(subject),

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/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 4ae7d5b..a0c577f 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
@@ -30,7 +30,7 @@ import org.eclipse.rdf4j.model.Statement;
 import org.eclipse.rdf4j.repository.Repository;
 import org.eclipse.rdf4j.repository.RepositoryConnection;
 
-public abstract class AbstractRepositoryGraphLike<T extends TripleLike<BlankNodeOrIRI,
IRI, RDFTerm>>
+abstract class AbstractRepositoryGraphLike<T extends TripleLike<BlankNodeOrIRI, IRI,
RDFTerm>>
 		implements RDF4JGraphLike<T> {
 
 	protected final Repository repository;
@@ -38,11 +38,7 @@ public abstract class AbstractRepositoryGraphLike<T extends TripleLike<BlankNode
 	protected final boolean handleInitAndShutdown;
 	protected final RDF4JTermFactory rdf4jTermFactory;
 
-	public AbstractRepositoryGraphLike(Repository repository) {
-		this(repository, true, false);
-	}
-
-	public AbstractRepositoryGraphLike(Repository repository, boolean handleInitAndShutdown,
boolean includeInferred) {
+	AbstractRepositoryGraphLike(Repository repository, boolean handleInitAndShutdown, boolean
includeInferred) {
 		this.repository = repository;
 		this.includeInferred = includeInferred;
 		this.handleInitAndShutdown = handleInitAndShutdown;

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
index 625088a..bdb82d1 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
@@ -25,14 +25,14 @@ import org.apache.commons.rdf.rdf4j.RDF4JBlankNode;
 import org.eclipse.rdf4j.model.BNode;
 import org.eclipse.rdf4j.rio.turtle.TurtleUtil;
 
-public final class BlankNodeImpl extends AbstractRDFTerm<BNode>
+final class BlankNodeImpl extends AbstractRDFTerm<BNode>
 	implements RDF4JBlankNode {
 	
 	private transient int hashCode = 0;
 	private long saltUUIDleast;
 	private long saltUUIDmost;
 	
-	public BlankNodeImpl(BNode bNode, UUID salt) {
+	BlankNodeImpl(BNode bNode, UUID salt) {
 		super(bNode);			
 		// Space-efficient storage of salt UUID
 		saltUUIDmost = salt.getMostSignificantBits();

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
index 9ae6741..e88ac27 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
@@ -19,10 +19,10 @@ package org.apache.commons.rdf.rdf4j.impl;
 
 import org.apache.commons.rdf.rdf4j.RDF4JIRI;
 
-public final class IRIImpl extends AbstractRDFTerm<org.eclipse.rdf4j.model.IRI> 
+final class IRIImpl extends AbstractRDFTerm<org.eclipse.rdf4j.model.IRI> 
 	implements RDF4JIRI {
 
-	public IRIImpl(org.eclipse.rdf4j.model.IRI iri) {
+	IRIImpl(org.eclipse.rdf4j.model.IRI iri) {
 		super(iri);			
 	}
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
new file mode 100644
index 0000000..2616226
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
@@ -0,0 +1,178 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.rdf4j.impl;
+
+import java.util.UUID;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.rdf4j.RDF4JBlankNode;
+import org.apache.commons.rdf.rdf4j.RDF4JDataset;
+import org.apache.commons.rdf.rdf4j.RDF4JGraph;
+import org.apache.commons.rdf.rdf4j.RDF4JIRI;
+import org.apache.commons.rdf.rdf4j.RDF4JLiteral;
+import org.apache.commons.rdf.rdf4j.RDF4JQuad;
+import org.apache.commons.rdf.rdf4j.RDF4JTerm;
+import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
+import org.apache.commons.rdf.rdf4j.RDF4JTriple;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.repository.Repository;
+
+/**
+ * Factory for {@link RDF4JTerm} instances.
+ * <p>
+ * <strong>Internal class:</strong> This "abstract" class is intended for
+ * internal use by Commons RDF and may change in any minor update. Use instead
+ * {@link RDF4JTermFactory} methods like
+ * {@link RDF4JTermFactory#createBlankNode()},
+ * {@link RDF4JTermFactory#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
+ * {@link RDF4JTermFactory#asRDFTermGraph(Repository)}.
+ * <p>
+ * This class exists as a <code>public</code> bridge between the packages
+ * {@link org.apache.commons.rdf.rdf4j} and
+ * {@link org.apache.commons.rdf.rdf4j.impl} by exposing the package-public
+ * constructors.
+ * 
+ * @see RDF4JTermFactory
+ */
+public abstract class InternalRDF4JFactory {
+
+	/**
+	 * Construct a {@link RDF4JBlankNode} from a RDF4J {@link BNode}.
+	 * 
+	 * @param bNode
+	 *            RDF4J {@link BNode} to adapt
+	 * @param salt
+	 *            {@link UUID} to use for {@link BlankNode#uniqueReference()} in
+	 *            combination with {@link BNode#getID()}
+	 * @return Adapted {@link RDF4JBlankNode}
+	 */
+	public RDF4JBlankNode createBlankNodeImpl(BNode bNode, UUID salt) {
+		return new BlankNodeImpl(bNode, salt);
+	}
+
+	/**
+	 * Construct a {@link RDF4JIRI} from a RDF4J {@link IRI}.
+	 * 
+	 * @param iri
+	 *            RDF4J {@link IRI} to adapt
+	 * @return Adapted {@link RDF4JIRI}
+	 */
+	public RDF4JIRI createIRIImpl(IRI iri) {
+		return new IRIImpl(iri);
+	}
+
+	/**
+	 * Construct a {@link RDF4JLiteral} from a RDF4J {@link Literal}.
+	 * 
+	 * @param bNode
+	 *            RDF4J {@link Literal}
+	 * @return Adapted {@link RDF4JLiteral}
+	 */
+	public RDF4JLiteral createLiteralImpl(Literal literal) {
+		return new LiteralImpl(literal);
+	}
+
+	/**
+	 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
+	 * <p>
+	 * Changes in the graph will be reflected in the model, and vice versa.
+	 * 
+	 * @param model
+	 *            RDF4J {@link Model} to adapt
+	 * @param rdf4jTermFactory
+	 *            factory to use for adapting graph triples
+	 * @return Adapted {@link RDF4JGraph}
+	 */
+	public RDF4JGraph createModelGraphImpl(Model model, RDF4JTermFactory rdf4jTermFactory) {
+		return new ModelGraphImpl(model, rdf4jTermFactory);
+	}
+
+	/**
+	 * Construct a {@link RDF4JQuad} from a RDF4J {@link Statement}.
+	 * 
+	 * @param statement
+	 *            RDF4J {@link Statement} to adapt
+	 * @param uuid
+	 *            {@link UUID} for adapting any {@link BNode}s
+	 * @return Adapted {@link RDF4JQuad}
+	 */
+	public RDF4JQuad createQuadImpl(Statement statement, UUID salt) {
+		return new QuadImpl(statement, salt);
+	}
+
+	/**
+	 * Construct a {@link RDF4JDataset} from a RDF4J {@link Repository}.
+	 * <p>
+	 * Changes in the dataset will be reflected in the repsitory, and vice
+	 * versa.
+	 * 
+	 * @param repository
+	 *            RDF4J {@link Repository} to adapt
+	 * @param handleInitAndShutdown
+	 *            If <code>true</code>, the {@link RDF4JDataset} will initialize
+	 *            the repository (if needed), and shut it down on
+	 *            {@link RDF4JDataset#close()}.
+	 * @param includeInferred
+	 *            If true, any inferred quads are included in the dataset
+	 * 
+	 * @return Adapted {@link RDF4JDataset}
+	 */
+	public RDF4JDataset createRepositoryDatasetImpl(Repository repository, boolean handleInitAndShutdown,
+			boolean includeInferred) {
+		return new RepositoryDatasetImpl(repository, handleInitAndShutdown, includeInferred);
+	}
+
+	/**
+	 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
+	 * <p>
+	 * Changes in the graph will be reflected in the model, and vice versa.
+	 * 
+	 * @param repository
+	 *            RDF4J {@link Repository} to adapt
+	 * @param handleInitAndShutdown
+	 *            If <code>true</code>, the {@link RDF4JGraph} will initialize
+	 *            the repository (if needed), and shut it down on
+	 *            {@link RDF4JGraph#close()}.
+	 * @param includeInferred
+	 *            If true, any inferred quads are included in the dataset
+	 * @return Adapted {@link RDF4JGraph}
+	 */
+	public RDF4JGraph createRepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown,
+			boolean includeInferred, Resource... contextMask) {
+		return new RepositoryGraphImpl(repository, handleInitAndShutdown, includeInferred, contextMask);
+	}
+
+	/**
+	 * Construct a {@link RDF4JTriple} from a RDF4J {@link Statement}.
+	 * 
+	 * @param statement
+	 *            RDF4J {@link Statement} to adapt
+	 * @param uuid
+	 *            {@link UUID} for adapting any {@link BNode}s
+	 * @return Adapted {@link RDF4JTriple}
+	 */
+	public RDF4JTriple createTripleImpl(Statement statement, UUID salt) {
+		return new TripleImpl(statement, salt);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
index 0305059..aef298d 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
@@ -24,13 +24,13 @@ import org.apache.commons.rdf.rdf4j.RDF4JLiteral;
 import org.eclipse.rdf4j.model.vocabulary.XMLSchema;
 import org.eclipse.rdf4j.rio.turtle.TurtleUtil;
 
-public final class LiteralImpl 
+final class LiteralImpl 
 	extends AbstractRDFTerm<org.eclipse.rdf4j.model.Literal>
     implements RDF4JLiteral {		
 
 	private static final String QUOTE = "\"";
 	
-	public LiteralImpl(org.eclipse.rdf4j.model.Literal literal) {
+	LiteralImpl(org.eclipse.rdf4j.model.Literal literal) {
 		super(literal);			
 	}
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
index 994bf81..e207007 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
@@ -33,17 +33,12 @@ import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Resource;
 import org.eclipse.rdf4j.repository.Repository;
 
-public final class ModelGraphImpl implements RDF4JGraph {
+final class ModelGraphImpl implements RDF4JGraph {
 	
 	private Model model;
 	private RDF4JTermFactory rdf4jTermFactory;
 
-	public ModelGraphImpl(Model model) {
-		this.model = model;	
-		this.rdf4jTermFactory = new RDF4JTermFactory();
-	}
-
-	public ModelGraphImpl(Model model, RDF4JTermFactory rdf4jTermFactory) {
+	ModelGraphImpl(Model model, RDF4JTermFactory rdf4jTermFactory) {
 		this.model = model;	
 		this.rdf4jTermFactory = rdf4jTermFactory;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
index ce39f61..18a0c84 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
@@ -29,16 +29,17 @@ import org.apache.commons.rdf.rdf4j.RDF4JQuad;
 import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
 import org.eclipse.rdf4j.model.Statement;
 
-public final class QuadImpl implements Quad, RDF4JQuad {
+final class QuadImpl implements Quad, RDF4JQuad {
 		private transient int hashCode = 0;	
 		private UUID salt;
 		private final Statement statement;
 		
-		public QuadImpl(Statement statement, UUID salt) {
+		QuadImpl(Statement statement, UUID salt) {
 			this.statement = statement;
 			this.salt = salt;
 		}
 	
+		@Override
 		public Statement asStatement() { 
 			return statement;
 		}
@@ -63,7 +64,7 @@ public final class QuadImpl implements Quad, RDF4JQuad {
 		public Optional<BlankNodeOrIRI> getGraphName() {
 			if (statement.getContext() == null) { 
 				return Optional.empty();
-			}
+			}			
 			BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4JTermFactory.asRDFTerm(statement.getContext(),
salt);
 			return Optional.of(g);
 		}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/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 04d685c..936dae8 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
@@ -36,17 +36,12 @@ import org.eclipse.rdf4j.repository.Repository;
 import org.eclipse.rdf4j.repository.RepositoryConnection;
 import org.eclipse.rdf4j.repository.RepositoryResult;
 
-public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad> implements
RDF4JDataset, Dataset {
+class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad> implements RDF4JDataset,
Dataset {
 
-	public RepositoryDatasetImpl(Repository repository, boolean handleInitAndShutdown, boolean
includeInferred) {
+	RepositoryDatasetImpl(Repository repository, boolean handleInitAndShutdown, boolean includeInferred)
{
 		super(repository, handleInitAndShutdown, includeInferred);
 	}
 
-	public RepositoryDatasetImpl(Repository repository) {
-		this(repository, false, false);
-	}
-
-
 	@Override
 	public void add(Quad tripleLike) {
 		Statement statement = rdf4jTermFactory.asStatement(tripleLike);
@@ -155,10 +150,11 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad>
imp
 		Value obj = rdf4jTermFactory.asValue(object);
 		Resource[] contexts = asContexts(graphName);
 
-		RepositoryConnection conn = getRepositoryConnection();
-		// NOTE: connection will be closed outside by the Iterations.stream()
-		RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred,
contexts);
-		return Iterations.stream(statements).map(this::asTripleLike);
+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred,
contexts);
+			// NOTE: RepositoryResult will be closed outside by the Iterations.stream()
+			return Iterations.stream(statements).map(this::asTripleLike);
+		}
 	}
 
 	@Override
@@ -181,10 +177,12 @@ public class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad>
imp
 
 	@Override
 	public Stream<BlankNodeOrIRI> getGraphNames() {
-		RepositoryConnection conn = getRepositoryConnection();
-		RepositoryResult<Resource> contexts = conn.getContextIDs();
-		// NOTE: connection will be closed outside by the Iterations.stream()
-		return Iterations.stream(contexts).map(g -> (BlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(g));
+		// FIXME: Will the below close the connection before the stream has been consumed outside?

+		try (RepositoryConnection conn = getRepositoryConnection()) {
+			RepositoryResult<Resource> contexts = conn.getContextIDs();
+			// NOTE: connection will be closed outside by the Iterations.stream()
+			return Iterations.stream(contexts).map(g -> (BlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(g));
+		}
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/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 4c09110..5238cca 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
@@ -39,22 +39,11 @@ import org.eclipse.rdf4j.repository.Repository;
 import org.eclipse.rdf4j.repository.RepositoryConnection;
 import org.eclipse.rdf4j.repository.RepositoryResult;
 
-public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple> implements
Graph, RDF4JGraph {
+class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple> implements Graph,
RDF4JGraph {
 
 	private final Resource[] contextMask;
 
-	public RepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown, boolean
includeInferred, boolean unionGraph) {
-		super(repository, handleInitAndShutdown, includeInferred);
-		if (unionGraph) {
-			// no context mask, aka any context
-			this.contextMask = new Resource[] { };
-		} else {
-			// default context: null
-			this.contextMask = new Resource[] { null };
-		}
-	}
-
-	public RepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown, boolean
includeInferred, Resource... contextMask) {
+	RepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown, boolean includeInferred,
Resource... contextMask) {
 		super(repository, handleInitAndShutdown, includeInferred);
 		this.contextMask = Objects.requireNonNull(contextMask);
 	}
@@ -97,15 +86,18 @@ public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple>
imp
 
 	@Override
 	public long size() {
-		try (RepositoryConnection conn = getRepositoryConnection()) {
-			if (! includeInferred && contextMask.length == 0) { 
+		if (!includeInferred && contextMask.length == 0) {
+			try (RepositoryConnection conn = getRepositoryConnection()) {
 				return conn.size();
-			} else {
-				return stream().count();
+			}
+		} else {
+			try (Stream<RDF4JTriple> stream = stream()) {
+				long s = stream.count();
+				stream.close();
+				return s;
 			}
 		}
 	}
-
 	
 	@Override
 	public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
@@ -150,9 +142,9 @@ public class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple>
imp
 		org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
 		Value obj = rdf4jTermFactory.asValue(object);
 		RepositoryConnection conn = getRepositoryConnection();
-		// FIXME: Is it OK that we don't close the connection?
-		RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred,
contextMask);
-		return Iterations.stream(statements).map(this::asTripleLike);
+			RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred,
contextMask);
+			// NOTE: Iterations.stream should close RepositoryResult as long as our caller closes
the stream
+			return Iterations.stream(statements).map(this::asTripleLike);
 	}
 	
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f9c298a9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
index bddd7f3..e1dcb60 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
@@ -27,15 +27,16 @@ import org.apache.commons.rdf.rdf4j.RDF4JTermFactory;
 import org.apache.commons.rdf.rdf4j.RDF4JTriple;
 import org.eclipse.rdf4j.model.Statement;
 
-public final class TripleImpl implements Triple, RDF4JTriple {
+final class TripleImpl implements Triple, RDF4JTriple {
 		private UUID salt;	
 		private final Statement statement;
 		
-		public TripleImpl(Statement statement, UUID salt) {
+		TripleImpl(Statement statement, UUID salt) {
 			this.statement = statement;
 			this.salt = salt;
 		}
 	
+		@Override
 		public Statement asStatement() { 
 			return statement;
 		}


Mime
View raw message