Class RepositoryDatasetImpl
- All Implemented Interfaces:
AutoCloseable, Dataset, GraphLike<Quad>, RDF4JDataset, RDF4JGraphLike<Quad>
-
Field Summary
Fields inherited from class AbstractRepositoryGraphLike
handleInitAndShutdown, includeInferred, rdf4jTermFactory, repository, salt -
Constructor Summary
ConstructorsConstructorDescriptionRepositoryDatasetImpl(org.eclipse.rdf4j.repository.Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Add a quad to the dataset, possibly mapping any of the components to those supported by this dataset.voidAdd a statement.private org.eclipse.rdf4j.model.Resource[]asContexts(Optional<BlankNodeOrIRI> graphName) protected RDF4JQuadasTripleLike(org.eclipse.rdf4j.model.Statement s) voidclear()Remove all statements.booleancontains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Check if dataset contains a pattern of quads.booleanCheck if statement is contained.getGraph()Get the default graph of this dataset.getGraph(BlankNodeOrIRI graphName) Get a named graph in this dataset.Get the graph names in this Dataset.iterate()Iterate over contained statements.iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Get an Iterable for iterating over the quads in the dataset that match the pattern.voidremove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Remove a concrete pattern of quads from the default graph of the dataset.voidAdd a statement.longsize()Number of statements.stream()Return a Stream of contained statements.stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Get all quads contained by the dataset matched with the pattern.Methods inherited from class AbstractRepositoryGraphLike
asModel, asRepository, close, getRepositoryConnectionMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RDF4JGraphLike
asModel, asRepository
-
Constructor Details
-
RepositoryDatasetImpl
RepositoryDatasetImpl(org.eclipse.rdf4j.repository.Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred)
-
-
Method Details
-
add
-
contains
Description copied from interface:GraphLikeCheck if statement is contained. -
remove
-
clear
-
size
-
add
Description copied from interface:DatasetAdd a quad to the dataset, possibly mapping any of the components to those supported by this dataset. -
contains
public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Description copied from interface:DatasetCheck if dataset contains a pattern of quads.- Specified by:
containsin interfaceDataset- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- True if the dataset contains any quads that match the given pattern.
-
asContexts
-
remove
public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Description copied from interface:DatasetRemove a concrete pattern of quads from the default graph of the dataset.- Specified by:
removein interfaceDataset- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)
-
stream
Description copied from interface:GraphLikeReturn a Stream of contained statements.- Specified by:
streamin interfaceDataset- Specified by:
streamin interfaceGraphLike<Quad>- Specified by:
streamin interfaceRDF4JDataset- Returns:
- A
StreamofTripleLikestatements.
-
stream
public Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Description copied from interface:RDF4JDatasetGet all quads contained by the dataset matched with the pattern.The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object)method for eachQuad.The behaviour of the
Streamis not specified ifDataset.add(Quad),Dataset.remove(Quad)orDataset.clear()are called on theDatasetbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.Note that for datasets backed by a repository (
RDF4JGraphLike.asRepository()is present), the stream must be closed withBaseStream.close().This can generally achieved using a try-with-resources block, e.g.:
int subjects; try (Stream<RDF4JQuad> s : graph.stream()) { subjects = s.map(RDF4JQuad::getSubject).distinct().count() }- Specified by:
streamin interfaceDataset- Specified by:
streamin interfaceRDF4JDataset- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- A
Streamover the matched quads.
-
iterate
public ClosableIterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateExceptionDescription copied from interface:GraphLikeIterate over contained statements.- Specified by:
iteratein interfaceDataset- Specified by:
iteratein interfaceGraphLike<Quad>- Specified by:
iteratein interfaceRDF4JDataset- Returns:
- An
IterableofTripleLikestatements. - Throws:
ConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.IllegalStateException- if theIterablehas been reused
-
iterate
public ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws ConcurrentModificationException, IllegalStateException Description copied from interface:RDF4JDatasetGet an Iterable for iterating over the quads in the dataset that match the pattern.This method is meant to be used with a Java for-each loop, e.g.:
IRI alice = factory.createIRI("http://example.com/alice"); IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/"); for (Quad t : dataset.iterate(null, alice, knows, null)) { System.out.println(t.getGraphName()); System.out.println(t.getObject()); }The behaviour of the iterator is not specified if
Dataset.add(Quad),Dataset.remove(Quad)orDataset.clear(), are called on theDatasetbefore it terminates. It is undefined if the returnedIteratorsupports theIterator.remove()method.Implementations may throw
ConcurrentModificationExceptionfrom Iterator methods if they detect a concurrency conflict while the Iterator is active.The
Iterable.iterator()must only be called once, that is the Iterable must only be iterated over once. AIllegalStateExceptionmay be thrown on attempt to reuse the Iterable.The default implementation of this method will call
Dataset.stream(Optional, BlankNodeOrIRI, IRI, RDFTerm)to return itsBaseStream.iterator().Note that for datasets backed by a repository (
RDF4JGraphLike.asRepository()is present), the iterable must be closed withAutoCloseable.close().This can generally achieved using a try-with-resources block, e.g.:
try (ClosableIterable<Quad> s : graph.iterate(g,s,p,o)) { for (Quad q : quads) { return q; // OK to terminate for-loop early } }If you don't use a try-with-resources block, the iterator will attempt to close the ClosableIterable when reaching the end of the iteration.- Specified by:
iteratein interfaceDataset- Specified by:
iteratein interfaceRDF4JDataset- Parameters:
graphName- The graph the quad belongs to, wrapped as anOptional(nullis a wildcard,Optional.empty()is the default graph)subject- The quad subject (nullis a wildcard)predicate- The quad predicate (nullis a wildcard)object- The quad object (nullis a wildcard)- Returns:
- A
Iterablethat returnsIteratorover the matching quads in the dataset - Throws:
ConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.IllegalStateException- if theIterablehas been reused
-
asTripleLike
- Specified by:
asTripleLikein classAbstractRepositoryGraphLike<Quad>
-
getGraph
Description copied from interface:DatasetGet the default graph of this dataset.The
Triples of the default graph are equivalent to theQuads in this Dataset which has theQuad.getGraphName()set toOptional.empty().It is unspecified if modifications to the returned Graph are reflected in this Dataset.
The returned graph MAY be empty.
-
getGraph
Description copied from interface:DatasetGet a named graph in this dataset.The
Triples of the named graph are equivalent to the the Quads of this Dataset which has theQuad.getGraphName()equal to the providedgraphName, or equal toOptional.empty()if the providedgraphNameisnull.It is unspecified if modifications to the returned Graph are reflected in this Dataset.
It is unspecified if requesting an unknown or empty graph will return
Optional.empty()or create a new emptyGraph.- Specified by:
getGraphin interfaceDataset- Parameters:
graphName- The name of the graph, ornullfor the default graph.- Returns:
- The named Graph, or
Optional.empty()if the dataset do not contain the named graph. - See Also:
-
getGraphNames
Description copied from interface:RDF4JDatasetGet the graph names in this Dataset.The set of returned graph names is equivalent to the set of unique
Quad.getGraphName()of all theDataset.stream()of this dataset (excluding the default graph).The returned
StreamSHOULD NOT contain duplicate graph names.The graph names can be used with
Dataset.getGraph(BlankNodeOrIRI)to retrieve the correspondingGraph, however callers should be aware of any concurrent modifications to the Dataset may cause such calls to returnOptional.empty().Note that a Dataset always contains a default graph which is not named, and thus is not represented in the returned Stream. The default graph is accessible via
Dataset.getGraph()or by usingOptional.empty()in the Quad access methods).Note that for datasets backed by a repository (
RDF4JGraphLike.asRepository()is present), the stream must be closed withBaseStream.close().This can generally achieved using a try-with-resources block, e.g.:
int graphs; try (Stream<BlankNodeOrIRI> s : graph.stream()) { graphs = s.count() }- Specified by:
getGraphNamesin interfaceDataset- Specified by:
getGraphNamesin interfaceRDF4JDataset- Returns:
- A
Streamof the graph names of this Dataset.
-