jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r697453 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
Date Sun, 21 Sep 2008 08:03:19 GMT
Author: clombart
Date: Sun Sep 21 01:03:19 2008
New Revision: 697453

URL: http://svn.apache.org/viewvc?rev=697453&view=rev
Log:
Apply modified patch for JCR-1740 ( Make ObjectIterator implement RangeIterator interface
) provided by Sergey Nebolsin

Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java?rev=697453&r1=697452&r2=697453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/impl/ObjectIterator.java
Sun Sep 21 01:03:19 2008
@@ -33,10 +33,7 @@
 
 /**
  * ObjectIterator is a wrapper class for JCR NodeIterator, which returns
- * mapped objects. Note, though, that this iterator may not return the same
- * number of objects as the underlying node iterator as not all nodes may
- * successfully be mapped to objects. Any problems mapping nodes to objects are
- * logged at INFO level.
+ * mapped objects.
  * <p>
  * This Iterator implementation does not support removing elements, therefore
  * the {@link #remove()} method throws a <code>UnsupportOperationException</code>.
@@ -46,17 +43,12 @@
  */
 public class ObjectIterator implements RangeIterator
 {
-
-    private static final Log log = LogFactory.getLog(ObjectIterator.class);
-
 	private NodeIterator nodeIterator;
 
 	private Session session;
 
 	private ObjectConverter objectConverter;
 
-    private Object nextResult;
-	
 	/**
 	 * Constructor
 	 *
@@ -69,63 +61,56 @@
 		nodeIterator = iterator;
 		objectConverter = converter;
 		this.session = session;
-		
-		// get first result
-        seek();
 	}
 
-
+    /**
+     * @see java.util.Iterator#hasNext()
+     */
 	public boolean hasNext() {
-        return nextResult != null;
+        return nodeIterator.hasNext();
     }
 
 	
+    /**
+     * @see java.util.Iterator#next() 
+     */
     public Object next() {
-        if (nextResult == null) {
-            throw new NoSuchElementException();
+        try {
+            Node node = nodeIterator.nextNode();
+            return objectConverter.getObject(session, node.getPath());
+        } catch (RepositoryException re) {
+            throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Repository
access issue trying to map node to an object", re);
         }
-
-        Object result = nextResult;
-        seek();
-        return result;
     }
 
-
+    /**
+     * This Iterator implementation does not support removing elements, therefore
+     * this method always throws a <code>UnsupportOperationException</code>.
+     *
+     * @see java.util.Iterator#next()
+     */
     public void remove() {
         throw new UnsupportedOperationException();
     }
 
 
-    private void seek() {
-        while (nodeIterator.hasNext()) {
-            try {
-                Node node = nodeIterator.nextNode();
-                Object value = objectConverter.getObject(session, node.getPath());
-                if (value != null) {
-                    nextResult = value;
-                    return;
-                }
-            } catch (RepositoryException re) {
-                log.info("Repository access issue trying to map node to an object", re);
-            } catch (ObjectContentManagerException ocme) {
-                log.info("Mapping Failure", ocme);
-            } catch (Throwable t) {
-                log.info("Unexpected Problem while trying to map a node to an object", t);
-            }
-        }
-
-        // no more results
-        nextResult = null;
-    }
-
+    /**
+     * @see javax.jcr.RangeIterator#skip(long)
+     */
     public void skip(long l) {
         nodeIterator.skip(l);
     }
 
+    /**
+     * @see javax.jcr.RangeIterator#getSize()
+     */
     public long getSize() {
         return nodeIterator.getSize();
     }
 
+    /**
+     * @see javax.jcr.RangeIterator#getPosition()
+     */
     public long getPosition() {
         return nodeIterator.getPosition();
     }

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java?rev=697453&r1=697452&r2=697453&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/query/AnnotationIteratorQueryTest.java
Sun Sep 21 01:03:19 2008
@@ -34,6 +34,7 @@
 import org.apache.jackrabbit.ocm.exception.JcrMappingException;
 import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
 import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
+import org.apache.jackrabbit.ocm.manager.impl.ObjectIterator;
 import org.apache.jackrabbit.ocm.query.Filter;
 import org.apache.jackrabbit.ocm.query.Query;
 import org.apache.jackrabbit.ocm.query.QueryManager;
@@ -89,22 +90,32 @@
     		  // No scope    		
     	      QueryManager queryManager = this.getQueryManager();
     	      Filter filter = queryManager.createFilter(Page.class);        	
-    	      Query query = queryManager.createQuery(filter);    	
+    	      Query query = queryManager.createQuery(filter);
+              // we need this to be sure about objects order in the iterator test
+              query.addOrderByAscending("title");
     	      ObjectContentManager ocm = this.getObjectContentManager();
     	
     	      long  start = System.currentTimeMillis();
-    	      Iterator iterator = ocm.getObjectIterator(query);
-    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
-    	          	
+              ObjectIterator iterator = (ObjectIterator) ocm.getObjectIterator(query);
+              System.out.println("getObjectIterator takes : " + (System.currentTimeMillis()
- start));
+
     	      start = System.currentTimeMillis();
     	      Collection result = ocm.getObjects(query);
     	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
     	
-    	      start = System.currentTimeMillis();
-    	      iterator = ocm.getObjectIterator(query);
-    	      System.out.println("getObject takes : " + (System.currentTimeMillis() - start));
      	
 
-    	
+    	      start = System.currentTimeMillis();
+    	      iterator = (ObjectIterator) ocm.getObjectIterator(query);
+              System.out.println("getObjectIterator takes : " + (System.currentTimeMillis()
- start));
+              assertEquals("wrong results count", 4, iterator.getSize());
+              assertEquals("wrong initial position", 0, iterator.getPosition());
+              assertTrue("no objects returned", iterator.hasNext());
+              Page page = (Page) iterator.next();
+              assertEquals("wrong first result", "Page 1 Title", page.getTitle());
+              iterator.skip(1);
+              assertEquals("wrong position after skip", 2, iterator.getPosition());
+              page = (Page) iterator.next();
+              assertEquals("wrong third result", "Page 3 Title", page.getTitle());
         }
         catch (Exception e)
         {



Mime
View raw message