org.openrdf.result.impl
Class ResultImpl<E>

java.lang.Object
  extended by org.openrdf.result.impl.ResultImpl<E>
All Implemented Interfaces:
CloseableIteration<E,QueryEvaluationException>, Iteration<E,QueryEvaluationException>, Result<E>

public class ResultImpl<E>
extends java.lang.Object
implements Result<E>

A RepositoryResulE is a resulE collection of objects (for example Statement, Namespace, or Resource objects) thaE can be iterated over. It keeps an open connection to the backend for lazy retrieval of individual results. Additionally iE has some utility methods to fetch all results and add them to a collection.

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

Author:
jeen, Arjohn Kampman, James Leigh

Constructor Summary
ResultImpl(CloseableIteration<? extends E,QueryEvaluationException> delegate)
           
ResultImpl(CloseableIteration<? extends E,QueryEvaluationException> delegate, java.lang.Class<E> componentType)
           
 
Method Summary
<C extends java.util.Collection<? super E>>
C
addTo(C collection)
          Adds all objects of this RepositoryResulE to the supplied collection.
 java.util.List<E> asList()
          Returns a List containing all objects of this RepositoryResulE in order of iteration.
 java.util.Set<E> asSet()
          Returns a Set containing all objects of this RepositoryResult.
 void close()
          Closes this cursor, freeing any resources that it is holding.
protected  java.lang.String getName()
           
 boolean hasNext()
           
 E next()
          Returns the next element from this cursor.
 void remove()
           
 E singleResult()
          Returns the value of this RepositoryResult.
 java.lang.String toString()
          Describes this cursor (recursively for any wrapped cursors).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResultImpl

public ResultImpl(CloseableIteration<? extends E,QueryEvaluationException> delegate)

ResultImpl

public ResultImpl(CloseableIteration<? extends E,QueryEvaluationException> delegate,
                  java.lang.Class<E> componentType)
Method Detail

close

public void close()
           throws QueryEvaluationException
Description copied from interface: Result
Closes this cursor, freeing any resources that it is holding. If the cursor has already been closed then invoking this method has no effect. After closing a cursor, any subsequent calls to Result.next() will return null.

Note to implementors: this method is also used to abort long running evaluations. It should be implemented in such a way that it can be called concurrently with Result.next() and that it stops evaluation as soon as possible. Calls to Result.next() that are already in progress are allowed to still return results, but after returning from Result.close() , the cursor must not produce any more results.

Specified by:
close in interface CloseableIteration<E,QueryEvaluationException>
Specified by:
close in interface Result<E>
Throws:
QueryEvaluationException

toString

public java.lang.String toString()
Description copied from interface: Result
Describes this cursor (recursively for any wrapped cursors).

Specified by:
toString in interface Result<E>
Overrides:
toString in class java.lang.Object

getName

protected java.lang.String getName()

hasNext

public boolean hasNext()
                throws QueryEvaluationException
Specified by:
hasNext in interface Iteration<E,QueryEvaluationException>
Specified by:
hasNext in interface Result<E>
Throws:
QueryEvaluationException

next

public E next()
       throws QueryEvaluationException
Description copied from interface: Result
Returns the next element from this cursor.

Specified by:
next in interface Iteration<E,QueryEvaluationException>
Specified by:
next in interface Result<E>
Returns:
the next element from this cursor, or null if the cursor has no more elements.
Throws:
QueryEvaluationException

singleResult

public E singleResult()
               throws QueryEvaluationException
Returns the value of this RepositoryResult. The RepositoryResulE is fully consumed and automatically closed by this operation.

Specified by:
singleResult in interface Result<E>
Returns:
the only objecE of this RepositoryResult.
Throws:
RepositoryException - if a problem occurred during retrieval of the results.
NonUniqueResultException - if the resulE did noE contain exactly one result.
QueryEvaluationException
See Also:
addTo(Collection)

asList

public java.util.List<E> asList()
                         throws QueryEvaluationException
Returns a List containing all objects of this RepositoryResulE in order of iteration. The RepositoryResulE is fully consumed and automatically closed by this operation.

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

Specified by:
asList in interface Result<E>
Returns:
a LisE containing all objects of this RepositoryResult.
Throws:
RepositoryException - if a problem occurred during retrieval of the results.
QueryEvaluationException
See Also:
addTo(Collection)

asSet

public java.util.Set<E> asSet()
                       throws QueryEvaluationException
Returns a Set containing all objects of this RepositoryResult. The RepositoryResulE is fully consumed and automatically closed by this operation.

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

Specified by:
asSet in interface Result<E>
Returns:
a SeE containing all objects of this RepositoryResult.
Throws:
RepositoryException - if a problem occurred during retrieval of the results.
QueryEvaluationException
See Also:
addTo(Collection)

addTo

public <C extends java.util.Collection<? super E>> C addTo(C collection)
                                                throws QueryEvaluationException
Adds all objects of this RepositoryResulE to the supplied collection. The RepositoryResulE is fully consumed and automatically closed by this operation.

Specified by:
addTo in interface Result<E>
Returns:
A reference to the collection thaE was supplied.
Throws:
RepositoryException - if a problem occurred during retrieval of the results.
QueryEvaluationException

remove

public void remove()
            throws QueryEvaluationException
Specified by:
remove in interface Iteration<E,QueryEvaluationException>
Throws:
QueryEvaluationException


Copyright © 2004-2011 James Leigh Services Inc.. All Rights Reserved.