jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Bocanegra <tri...@day.com>
Subject Re: svn commit: r776654 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Date Wed, 20 May 2009 12:28:37 GMT
On Wed, May 20, 2009 at 2:22 PM, Julian Reschke <julian.reschke@gmx.de> wrote:
> jukka@apache.org wrote:
>>
>> +    /**
>> +     * Returns the nodes in the given query result as an {@link Iterable}
>> +     * for use in a Java 5 for-each loop. The return value encapsulates
>> +     * the {@link QueryResult#getNodes()} method call. Potential
>> +     * {@link RepositoryException}s are converted to {@link
>> RuntimeException}s.
>> +     *
>> +     * @param result query result
>> +     * @return nodes in the query result
>> +     */
>> +    public static Iterable<Node> getNodes(final QueryResult result) {
>> +        return new Iterable<Node>() {
>> +            @SuppressWarnings("unchecked")
>> +            public Iterator<Node> iterator() {
>> +                try {
>> +                    return result.getNodes();
>> +                } catch (RepositoryException e) {
>> +                    throw new RuntimeException(
>> +                            "Unable to access nodes in " + result,
e);
>> +                }
>> +            }
>> +        };
>> +    }
>
> Jukka, is it really a good idea to catch the RepositoryException here,
> mapping it to an unchecked exception?

i don't like this either. how about:

public static Iterable<Node> getNodes(final QueryResult result) throws
RepositoryException {
     final Iterator iter = result.getNodes();
     return new Iterable<Node>() {
           @SuppressWarnings("unchecked")
           public Iterator<Node> iterator() {
               return iter;
           }
      };

i don't now about the exact semantics of the Iterable interface - i.e.
if a new iterator needs to be fetched for each call. but for the sake
of the "foreach" loop, this should work.

regards, toby

Mime
View raw message