org.openrdf.repository
Class RepositoryResult<T>

java.lang.Object
  extended by info.aduna.iteration.CloseableIterationBase<E,X>
      extended by info.aduna.iteration.IterationWrapper<T,RepositoryException>
          extended by org.openrdf.repository.RepositoryResult<T>
All Implemented Interfaces:
CloseableIteration<T,RepositoryException>, Iteration<T,RepositoryException>

public class RepositoryResult<T>
extends IterationWrapper<T,RepositoryException>

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, Arjohn Kampman
See Also:
RepositoryConnection.getStatements(org.openrdf.model.Resource, org.openrdf.model.URI, org.openrdf.model.Value, boolean, org.openrdf.model.Resource[]), RepositoryConnection.getNamespaces(), RepositoryConnection.getContextIDs()

Field Summary
 
Fields inherited from class info.aduna.iteration.IterationWrapper
wrappedIter
 
Constructor Summary
RepositoryResult(CloseableIteration<? extends T,RepositoryException> iter)
           
 
Method Summary
<C extends Collection<T>>
C
addTo(C collection)
          Adds all objects of this RepositoryResult to the supplied collection.
 List<T> asList()
          Returns a List containing all objects of this RepositoryResult in order of iteration.
 void enableDuplicateFilter()
          Switches on duplicate filtering while iterating over objects.
 
Methods inherited from class info.aduna.iteration.IterationWrapper
handleClose, hasNext, next, remove
 
Methods inherited from class info.aduna.iteration.CloseableIterationBase
close, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepositoryResult

public RepositoryResult(CloseableIteration<? extends T,RepositoryException> iter)
Method Detail

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

public List<T> asList()
               throws RepositoryException
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

public <C extends Collection<T>> C addTo(C collection)
                              throws RepositoryException
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.


Copyright © 2001-2008 Aduna. All Rights Reserved.