jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r776654 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Date Wed, 20 May 2009 10:32:18 GMT
Author: jukka
Date: Wed May 20 10:32:17 2009
New Revision: 776654

URL: http://svn.apache.org/viewvc?rev=776654&view=rev
Log:
JCR-2120: java.lang.Iterable support for RangeIterators

Added methods for getting Iterables out of query results.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=776654&r1=776653&r2=776654&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Wed May 20 10:32:17 2009
@@ -21,6 +21,8 @@
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
 
 /**
  * Collection of static utility methods for use with the JCR API.
@@ -304,4 +306,50 @@
         };
     }
 
+    /**
+     * 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);
+                }
+            }
+        };
+    }
+
+    /**
+     * Returns the rows 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#getRows()} method call. Potential
+     * {@link RepositoryException}s are converted to {@link RuntimeException}s.
+     *
+     * @param result query result
+     * @return rows in the query result
+     */
+    public static Iterable<Row> getRows(final QueryResult result) {
+        return new Iterable<Row>() {
+            @SuppressWarnings("unchecked")
+            public Iterator<Row> iterator() {
+                try {
+                    return result.getRows();
+                } catch (RepositoryException e) {
+                    throw new RuntimeException(
+                            "Unable to access rows in " + result, e);
+                }
+            }
+        };
+    }
+
 }



Mime
View raw message