Class RepositoryGraphImpl

    • Field Detail

      • contextMask

        private final org.eclipse.rdf4j.model.Resource[] contextMask
    • Constructor Detail

      • RepositoryGraphImpl

        RepositoryGraphImpl​(org.eclipse.rdf4j.repository.Repository repository,
                            java.util.UUID salt,
                            boolean handleInitAndShutdown,
                            boolean includeInferred,
                            org.eclipse.rdf4j.model.Resource... contextMask)
    • Method Detail

      • add

        public void add​(Triple tripleLike)
        Description copied from interface: Graph
        Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.
        Specified by:
        add in interface Graph
        Specified by:
        add in interface GraphLike<Triple>
        Parameters:
        tripleLike - The triple to add
      • contains

        public boolean contains​(Triple tripleLike)
        Description copied from interface: Graph
        Checks if graph contains triple.
        Specified by:
        contains in interface Graph
        Specified by:
        contains in interface GraphLike<Triple>
        Parameters:
        tripleLike - The triple to check.
        Returns:
        True if the Graph contains the given Triple.
      • remove

        public void remove​(Triple tripleLike)
        Description copied from interface: Graph
        Removes a concrete triple from the graph.
        Specified by:
        remove in interface Graph
        Specified by:
        remove in interface GraphLike<Triple>
        Parameters:
        tripleLike - triple to remove
      • clear

        public void clear()
        Description copied from interface: Graph
        Clears the graph, removing all triples.
        Specified by:
        clear in interface Graph
        Specified by:
        clear in interface GraphLike<Triple>
      • size

        public long size()
        Description copied from interface: Graph
        Number of triples contained by the graph.

        The count of a set does not include duplicates, consistent with the Triple.equals(Object) equals method for each Triple.

        Specified by:
        size in interface Graph
        Specified by:
        size in interface GraphLike<Triple>
        Returns:
        The number of triples in the graph
      • add

        public void add​(BlankNodeOrIRI subject,
                        IRI predicate,
                        RDFTerm object)
        Description copied from interface: Graph
        Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.
        Specified by:
        add in interface Graph
        Parameters:
        subject - The triple subject
        predicate - The triple predicate
        object - The triple object
      • contains

        public boolean contains​(BlankNodeOrIRI subject,
                                IRI predicate,
                                RDFTerm object)
        Description copied from interface: Graph
        Checks if graph contains a pattern of triples.
        Specified by:
        contains in interface Graph
        Parameters:
        subject - The triple subject (null is a wildcard)
        predicate - The triple predicate (null is a wildcard)
        object - The triple object (null is a wildcard)
        Returns:
        True if the Graph contains any Triples that match the given pattern.
      • remove

        public void remove​(BlankNodeOrIRI subject,
                           IRI predicate,
                           RDFTerm object)
        Description copied from interface: Graph
        Removes a concrete pattern of triples from the graph.
        Specified by:
        remove in interface Graph
        Parameters:
        subject - The triple subject (null is a wildcard)
        predicate - The triple predicate (null is a wildcard)
        object - The triple object (null is a wildcard)
      • iterate

        public ClosableIterable<Triple> iterate()
                                         throws java.util.ConcurrentModificationException,
                                                java.lang.IllegalStateException
        Description copied from interface: RDF4JGraph
        Gets an Iterable for iterating over all triples in the graph.

        This method is meant to be used with a Java for-each loop, e.g.:

         for (Triple t : graph.iterate()) {
             System.out.println(t);
         }
         
        The behaviour of the iterator is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear(), are called on the Graph before it terminates. It is undefined if the returned Iterator supports the Iterator.remove() method.

        Implementations may throw ConcurrentModificationException from 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. A IllegalStateException may be thrown on attempt to reuse the Iterable.

        The default implementation of this method will call Graph.stream() to return its BaseStream.iterator().

        Note that for graphs backed by a repository (RDF4JGraphLike.asRepository() is present), the iterable must be closed with AutoCloseable.close().

        This can generally achieved using a try-with-resources block, e.g.:

         try (ClosableIterable<Triple> s : graph.iterate()) {
           for (Triple t : triples) {
               return t; // 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:
        iterate in interface Graph
        Specified by:
        iterate in interface GraphLike<Triple>
        Specified by:
        iterate in interface RDF4JGraph
        Returns:
        A Iterable that returns Iterator over all of the triples in the graph
        Throws:
        java.util.ConcurrentModificationException - if a concurrency conflict occurs while the Iterator is active.
        java.lang.IllegalStateException - if the Iterable has been reused
      • iterate

        public ClosableIterable<Triple> iterate​(BlankNodeOrIRI subject,
                                                IRI predicate,
                                                RDFTerm object)
                                         throws java.util.ConcurrentModificationException,
                                                java.lang.IllegalStateException
        Description copied from interface: RDF4JGraph
        Gets an Iterable for iterating over the triples in the graph 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 (Triple t : graph.iterate(alice, knows, null)) {
             System.out.println(t.getObject());
         }
         

        The behaviour of the iterator is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear(), are called on the Graph before it terminates. It is undefined if the returned Iterator supports the Iterator.remove() method.

        Implementations may throw ConcurrentModificationException from 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. A IllegalStateException may be thrown on attempt to reuse the Iterable.

        The default implementation of this method will call Graph.stream(BlankNodeOrIRI, IRI, RDFTerm) to return its BaseStream.iterator().

        Note that for graphs backed by a repository (RDF4JGraphLike.asRepository() is present), the iterable must be closed with AutoCloseable.close().

        This can generally achieved using a try-with-resources block, e.g.:

         try (ClosableIterable<Triple> s : graph.iterate(s,p,o)) {
           for (Triple t : triples) {
               return t; // 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:
        iterate in interface Graph
        Specified by:
        iterate in interface RDF4JGraph
        Parameters:
        subject - The triple subject (null is a wildcard)
        predicate - The triple predicate (null is a wildcard)
        object - The triple object (null is a wildcard)
        Returns:
        A Iterable that returns Iterator over the matching triples in the graph
        Throws:
        java.util.ConcurrentModificationException - if a concurrency conflict occurs while the Iterator is active.
        java.lang.IllegalStateException - if the Iterable has been reused
      • stream

        public java.util.stream.Stream<RDF4JTriple> stream()
        Description copied from interface: RDF4JGraph
        Gets all triples contained by the graph.

        The iteration does not contain any duplicate triples, as determined by the Triple.equals(Object) method for each Triple.

        The behaviour of the Stream is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear() are called on the Graph before it terminates.

        Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.

        Note that for graphs backed by a repository (RDF4JGraphLike.asRepository() is present), the stream must be closed with BaseStream.close().

        This can generally achieved using a try-with-resources block, e.g.:

         int subjects;
         try (Stream<RDF4JTriple> s : graph.stream()) {
           subjects = s.map(RDF4JTriple::getSubject).distinct().count()
         }
         
        Specified by:
        stream in interface Graph
        Specified by:
        stream in interface GraphLike<Triple>
        Specified by:
        stream in interface RDF4JGraph
        Returns:
        A Stream over all of the triples in the graph
      • stream

        public java.util.stream.Stream<RDF4JTriple> stream​(BlankNodeOrIRI subject,
                                                           IRI predicate,
                                                           RDFTerm object)
        Description copied from interface: RDF4JGraph
        Gets all triples contained by the graph matched with the pattern.

        The iteration does not contain any duplicate triples, as determined by the Triple.equals(Object) method for each Triple.

        The behaviour of the Stream is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear() are called on the Graph before it terminates.

        Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.

        Note that for graphs backed by a repository (RDF4JGraphLike.asRepository() is present), the stream must be closed with BaseStream.close().

        This can generally achieved using a try-with-resources block, e.g.:

         int subjects;
         try (Stream<RDF4JTriple> s : graph.stream(s,p,o)) {
           subjects = s.map(RDF4JTriple::getSubject).distinct().count()
         }
         
        Specified by:
        stream in interface Graph
        Specified by:
        stream in interface RDF4JGraph
        Parameters:
        subject - The triple subject (null is a wildcard)
        predicate - The triple predicate (null is a wildcard)
        object - The triple object (null is a wildcard)
        Returns:
        A Stream over the matched triples.
      • getContextMask

        public java.util.Set<RDF4JBlankNodeOrIRI> getContextMask()
        Description copied from interface: RDF4JGraph
        Return a copy of the context mask as a Set of RDF4JBlankNodeOrIRI graph names.

        If the set is not Set.isEmpty(), the mask determines which contexts in the corresponding RDF4J Model or Repository that this graph reflect. Modifications to the graph (e.g. Graph.add(Triple) will be performed for all the specified contexts, while retrieval (e.g. Graph.contains(Triple)) will succeed if the triple is in at least one of the specified contexts.

        The context mask array may contain null, indicating the default context (the default graph in RDF datasets).

        If the context mask is Set.isEmpty(), then this is a union graph which triples reflect statements in any contexts. Triples added to the graph will be added in the default context, e.g. equivalent to new Resource[1]{null}) in RDF4J.

        Note that the context mask itself cannot be null.

        The returned set is an immutable copy; to specify a different mask, use RDF4J.asGraph(Repository, Set, Option...)

        Specified by:
        getContextMask in interface RDF4JGraph
        Returns:
        The context mask as a set of BlankNodeOrIRI graph names, which may contain the value null.