[teiid-commits] teiid SVN: r2624 - in branches/7.1.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Oct 4 15:26:58 EDT 2010


Author: shawkins
Date: 2010-10-04 15:26:58 -0400 (Mon, 04 Oct 2010)
New Revision: 2624

Modified:
   branches/7.1.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
   branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
Log:
TEIID-1289 fixing hasnext handling with marking

Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java	2010-10-04 14:48:14 UTC (rev 2623)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java	2010-10-04 19:26:58 UTC (rev 2624)
@@ -29,6 +29,7 @@
 import org.teiid.common.buffer.TupleBatch;
 import org.teiid.common.buffer.TupleBuffer;
 import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
 import org.teiid.core.TeiidProcessingException;
 import org.teiid.query.processor.BatchCollector.BatchProducer;
 
@@ -79,7 +80,7 @@
 	protected List<?> getCurrentTuple() throws TeiidComponentException,
 			BlockedException, TeiidProcessingException {
 		List<?> tuple = super.getCurrentTuple();
-		if (mark && saveOnMark && this.getCurrentIndex() > this.buffer.getRowCount()) {
+		if (tuple != null && mark && saveOnMark && this.getCurrentIndex() > this.buffer.getRowCount()) {
         	this.buffer.setRowCount(this.getCurrentIndex() - 1);
         	this.buffer.addTuple(tuple);
         }
@@ -122,14 +123,20 @@
 			this.buffer.purge();
     	}
     	mark = true;
+    	if (saveOnMark) {
+        	try {
+    			getCurrentTuple();
+    		} catch (TeiidException e) {
+    		}
+    	}
     }
     
     @Override
     public void setPosition(int position) {
-    	super.setPosition(position);
     	if (this.buffer == null && position < getCurrentIndex() && position < (this.batch != null ? batch.getBeginRow() : Integer.MAX_VALUE)) {
 			throw new UnsupportedOperationException("Backwards positioning is not allowed"); //$NON-NLS-1$
     	}
+    	super.setPosition(position);
     }
     
 }

Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java	2010-10-04 14:48:14 UTC (rev 2623)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java	2010-10-04 19:26:58 UTC (rev 2624)
@@ -72,4 +72,23 @@
 		assertEquals(2, bi.nextTuple().get(0));
 	}
 	
+	@Test public void testReset2() throws Exception {
+		BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
+			Arrays.asList(1),
+			Arrays.asList(2),
+		}, 2));
+		BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
+		TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR);
+		bi.setBuffer(tb, true);  //$NON-NLS-1$
+		bi.hasNext();
+		bi.mark();
+		bi.nextTuple();
+		bi.nextTuple();
+		assertNull(bi.nextTuple());
+		bi.reset();
+		bi.hasNext();
+		assertEquals(1, bi.getCurrentIndex());
+		assertEquals(1, bi.nextTuple().get(0));
+	}
+	
 }



More information about the teiid-commits mailing list