Class RepositoryResult<T>

  • All Implemented Interfaces:
    AutoCloseable, Iterable<T>, Iterator<T>, org.eclipse.rdf4j.common.iteration.CloseableIteration<T>

    public class RepositoryResult<T>
    extends org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<T>
    implements Iterable<T>
    A RepositoryResult is a result collection of objects (for example Statement , Namespace, or Resource objects) that can be iterated over. It keeps an open connection to the backend for lazy retrieval of individual results. Additionally it has some utility methods to fetch all results and add them to a collection.

    By default, a RepositoryResult is not necessarily a (mathematical) set: it may contain duplicate objects. Duplicate filtering can be switched on, but this should not be used lightly as the filtering mechanism is potentially memory-intensive.

    A RepositoryResult needs to be closed after use to free up any resources (open connections, read locks, etc.) it has on the underlying repository.

    Author:
    Jeen Broekstra, Arjohn Kampman
    See Also:
    RepositoryConnection.getStatements(Resource, IRI, Value, boolean, Resource[]), RepositoryConnection.getNamespaces(), RepositoryConnection.getContextIDs()
    • Constructor Detail

      • RepositoryResult

        public RepositoryResult​(org.eclipse.rdf4j.common.iteration.CloseableIteration<? extends T> iter)
    • Method Detail

      • handleClose

        protected void handleClose()
                            throws RepositoryException
        Specified by:
        handleClose in class org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<T>
        Throws:
        RepositoryException
      • enableDuplicateFilter

        public void enableDuplicateFilter()
                                   throws RepositoryException
        Switches on duplicate filtering while iterating over objects. The RepositoryResult will keep track of the previously returned objects in a Set and on calling next() or hasNext() will ignore any objects that already occur in this Set.

        Caution: use of this filtering mechanism is potentially memory-intensive.

        Throws:
        RepositoryException - if a problem occurred during initialization of the filter.
      • asList

        @Deprecated
        public List<T> asList()
                       throws RepositoryException
        Deprecated.
        Use Iterations.asList(CloseableIteration) instead.
        Returns a List containing all objects of this RepositoryResult in order of iteration. The RepositoryResult is fully consumed and automatically closed by this operation.

        Note: use this method with caution! It pulls the entire RepositoryResult in memory and as such is potentially very memory-intensive.

        Returns:
        a List containing all objects of this RepositoryResult.
        Throws:
        RepositoryException - if a problem occurred during retrieval of the results.
        See Also:
        addTo(Collection)
      • addTo

        @Deprecated
        public <C extends Collection<T>> C addTo​(C collection)
                                          throws RepositoryException
        Deprecated.
        Use Iterations.addAll(CloseableIteration, Collection) instead.
        Adds all objects of this RepositoryResult to the supplied collection. The RepositoryResult is fully consumed and automatically closed by this operation.
        Returns:
        A reference to the collection that was supplied.
        Throws:
        RepositoryException - if a problem occurred during retrieval of the results.